diff --git a/src/notebook/plugin.ts b/src/notebook/plugin.ts index bf1d4b2..5f487a5 100644 --- a/src/notebook/plugin.ts +++ b/src/notebook/plugin.ts @@ -67,6 +67,8 @@ const cmdIds = { insertBelow: 'notebook-cells:insert-below', selectPrevious: 'notebook-cells:select-previous', selectNext: 'notebook-cells:select-next', + toggleLinenumbers: 'notebook-cells:toggle-linenumbers', + toggleAllLinenumbers: 'notebook:toggle-allLinenumbers', editMode: 'notebook-cells:editMode', commandMode: 'notebook-cells:commandMode' }; @@ -213,6 +215,36 @@ function activateNotebookHandler(app: Application, manager: DocumentManager, ser if (model) model.activeCellIndex += 1; } }, + { + id: cmdIds['toggleLinenumbers'], + handler: () => { + let model = handler.currentModel; + if (model) { + let cell = model.cells.get(model.activeCellIndex); + let lineNumbers = cell.input.textEditor.lineNumbers; + for (let i = 0; i < model.cells.length; i++) { + cell = model.cells.get(i); + if (model.isSelected(cell) || i === model.activeCellIndex) { + cell.input.textEditor.lineNumbers = !lineNumbers; + } + } + } + } + }, + { + id: cmdIds['toggleAllLinenumbers'], + handler: () => { + let model = handler.currentModel; + if (model) { + let cell = model.cells.get(model.activeCellIndex); + let lineNumbers = cell.input.textEditor.lineNumbers; + for (let i = 0; i < model.cells.length; i++) { + cell = model.cells.get(i); + cell.input.textEditor.lineNumbers = !lineNumbers; + } + } + } + }, { id: cmdIds['commandMode'], handler: () => { @@ -304,6 +336,16 @@ function activateNotebookHandler(app: Application, manager: DocumentManager, ser category: 'Notebook Cell Operations', text: 'Select next cell' }, + { + command: cmdIds['toggleLinenumbers'], + category: 'Notebook Cell Operations', + text: 'Toggle line numbers' + }, + { + command: cmdIds['toggleAllLinenumbers'], + category: 'Notebook Operations', + text: 'Toggle all line numbers' + }, { command: cmdIds['editMode'], category: 'Notebook Cell Operations', diff --git a/src/shortcuts/plugin.ts b/src/shortcuts/plugin.ts index 1703dbe..57ac50e 100644 --- a/src/shortcuts/plugin.ts +++ b/src/shortcuts/plugin.ts @@ -151,6 +151,11 @@ const SHORTCUTS = [ selector: '.jp-Notebook.jp-mod-commandMode', sequence: ['ArrowDown'] }, + { + command: 'notebook-cells:toggle-linenumbers', + selector: '.jp-Notebook.jp-mod-commandMode', + sequence: ['L'] + }, { command: 'notebook-cells:editMode', selector: '.jp-Notebook.jp-mod-commandMode',