From e97e5071eb61dacf69c17bbc0887b6f2fa8d9641 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 7 Apr 2016 08:08:57 -0500 Subject: [PATCH 1/2] Add the ability to toggle line numbers on cell and whole document --- src/notebook/plugin.ts | 37 +++++++++++++++++++++++++++++++++++++ src/shortcuts/plugin.ts | 5 +++++ 2 files changed, 42 insertions(+) diff --git a/src/notebook/plugin.ts b/src/notebook/plugin.ts index bf1d4b2..d594467 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,31 @@ 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; + 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 +331,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', From 7f105e059284f161e1a3256c7273b0291f3c5098 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 7 Apr 2016 08:10:53 -0500 Subject: [PATCH 2/2] Toggle line numbers on all selected cells --- src/notebook/plugin.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/notebook/plugin.ts b/src/notebook/plugin.ts index d594467..5f487a5 100644 --- a/src/notebook/plugin.ts +++ b/src/notebook/plugin.ts @@ -222,7 +222,12 @@ function activateNotebookHandler(app: Application, manager: DocumentManager, ser if (model) { let cell = model.cells.get(model.activeCellIndex); let lineNumbers = cell.input.textEditor.lineNumbers; - cell.input.textEditor.lineNumbers = !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; + } + } } } },