Skip to content

Commit ee6cb91

Browse files
committed
Fix #126
1 parent 120e4d3 commit ee6cb91

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"author": "Jay Ahn, Kiran Pinnipati",
1616
"files": [
1717
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
18-
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
18+
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
19+
"schema/*.json"
1920
],
2021
"main": "lib/index.js",
2122
"types": "lib/index.d.ts",
@@ -43,7 +44,6 @@
4344
"@jupyterlab/application": "^2.1.2",
4445
"@jupyterlab/apputils": "^2.2.4",
4546
"@jupyterlab/cells": "^2.2.4",
46-
"@jupyterlab/coreutils": "^4.1.0",
4747
"@jupyterlab/docmanager": "^2.1.2",
4848
"@jupyterlab/docregistry": "^2.1.2",
4949
"@jupyterlab/fileeditor": "^2.1.2",
@@ -77,7 +77,8 @@
7777
"style/*.css"
7878
],
7979
"jupyterlab": {
80-
"extension": true
80+
"extension": true,
81+
"schemaDir": "schema"
8182
},
8283
"husky": {
8384
"hooks": {

schema/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"jupyter.lab.shortcuts": [
3+
{
4+
"command": "codeSnippet:save-as-snippet",
5+
"keys": ["Accel Shift S"],
6+
"selector": ".jp-Cell"
7+
}
8+
],
9+
"type": "object"
10+
}

src/index.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
ILayoutRestorer
55
} from '@jupyterlab/application';
66
import { ICommandPalette, WidgetTracker } from '@jupyterlab/apputils';
7+
import { ISettingRegistry } from '@jupyterlab/settingregistry';
8+
79
import { IEditorServices } from '@jupyterlab/codeeditor';
810
import { LabIcon } from '@jupyterlab/ui-components';
911

@@ -23,6 +25,7 @@ import {
2325

2426
const CODE_SNIPPET_EXTENSION_ID = 'code-snippet-extension';
2527

28+
const CODE_SNIPPET_SETTING_ID = 'jupyterlab-code-snippets:settings';
2629
/**
2730
* Snippet Editor Icon
2831
*/
@@ -150,7 +153,7 @@ function activateCodeSnippet(
150153
});
151154

152155
//Add an application command
153-
const saveCommand = 'save as code snippet';
156+
const saveCommand = 'codeSnippet:save-as-snippet';
154157
const toggled = false;
155158
app.commands.addCommand(saveCommand, {
156159
label: 'Save As Code Snippet',
@@ -181,14 +184,6 @@ function activateCodeSnippet(
181184
selector: '.jp-FileEditor'
182185
});
183186

184-
// Add keybinding to save
185-
app.commands.addKeyBinding({
186-
command: saveCommand,
187-
args: {},
188-
keys: ['Accel Shift S'],
189-
selector: '.jp-Cell'
190-
});
191-
192187
// Track and restore the widget state
193188
const tracker = new WidgetTracker<CodeSnippetEditor>({
194189
namespace: 'codeSnippetEditor'
@@ -217,6 +212,18 @@ function activateCodeSnippet(
217212
});
218213
}
219214

215+
const codeSnippetExtensionSetting: JupyterFrontEndPlugin<void> = {
216+
id: CODE_SNIPPET_SETTING_ID,
217+
autoStart: true,
218+
requires: [ISettingRegistry],
219+
activate: (app: JupyterFrontEnd, settingRegistry: ISettingRegistry) => {
220+
void settingRegistry
221+
.load(CODE_SNIPPET_SETTING_ID)
222+
.then(_ => console.log('settingRegistry successfully loaded!'))
223+
.catch(e => console.log(e));
224+
}
225+
};
226+
220227
function getSelectedText(): string {
221228
let selectedText;
222229
// window.getSelection
@@ -230,4 +237,4 @@ function getSelectedText(): string {
230237
return selectedText.toString();
231238
}
232239

233-
export default code_snippet_extension;
240+
export default [code_snippet_extension, codeSnippetExtensionSetting];

0 commit comments

Comments
 (0)