From 6ae64b1942a9e8fc903db6f90c98268060a11b26 Mon Sep 17 00:00:00 2001 From: Adityar Rayala Date: Tue, 10 Sep 2019 00:19:56 +0530 Subject: [PATCH 1/8] Added the Selection of cells till Top and Bottom --- .../notebook-extension/schema/tracker.json | 10 ++++++ packages/notebook-extension/src/index.ts | 32 +++++++++++++++++-- packages/notebook/src/actions.tsx | 24 +++++++++++--- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/packages/notebook-extension/schema/tracker.json b/packages/notebook-extension/schema/tracker.json index 0688b0e88ce5..237850049c3e 100644 --- a/packages/notebook-extension/schema/tracker.json +++ b/packages/notebook-extension/schema/tracker.json @@ -87,11 +87,21 @@ "keys": ["Shift K"], "selector": ".jp-Notebook:focus" }, + { + "command": "notebook:extend-marked-cells-top", + "keys": ["Shift PageUp"], + "selector": ".jp-Notebook:focus" + }, { "command": "notebook:extend-marked-cells-below", "keys": ["Shift ArrowDown"], "selector": ".jp-Notebook:focus" }, + { + "command": "notebook:extend-marked-cells-bottom", + "keys": ["Shift PageDown"], + "selector": ".jp-Notebook:focus" + }, { "command": "notebook:extend-marked-cells-below", "keys": ["Shift J"], diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index 2e769795de7c..a7033d080b3c 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -157,8 +157,12 @@ namespace CommandIDs { export const extendAbove = 'notebook:extend-marked-cells-above'; + export const extendTop = 'notebook:extend-marked-cells-top'; + export const extendBelow = 'notebook:extend-marked-cells-below'; + export const extendBottom = 'notebook:extend-marked-cells-bottom'; + export const selectAll = 'notebook:select-all'; export const deselectAll = 'notebook:deselect-all'; @@ -1459,7 +1463,18 @@ function addCommands( const current = getCurrent(args); if (current) { - return NotebookActions.extendSelectionAbove(current.content); + return NotebookActions.extendSelectionAbove(current.content, false); + } + }, + isEnabled + }); + commands.addCommand(CommandIDs.extendTop, { + label: 'Extend Selection to Top', + execute: args => { + const current = getCurrent(args); + + if (current) { + return NotebookActions.extendSelectionAbove(current.content, true); } }, isEnabled @@ -1470,7 +1485,18 @@ function addCommands( const current = getCurrent(args); if (current) { - return NotebookActions.extendSelectionBelow(current.content); + return NotebookActions.extendSelectionBelow(current.content, false); + } + }, + isEnabled + }); + commands.addCommand(CommandIDs.extendBottom, { + label: 'Extend Selection to Bottom', + execute: args => { + const current = getCurrent(args); + + if (current) { + return NotebookActions.extendSelectionBelow(current.content, true); } }, isEnabled @@ -1908,7 +1934,9 @@ function populatePalette( CommandIDs.selectAbove, CommandIDs.selectBelow, CommandIDs.extendAbove, + CommandIDs.extendTop, CommandIDs.extendBelow, + CommandIDs.extendBottom, CommandIDs.moveDown, CommandIDs.moveUp, CommandIDs.undoCellAction, diff --git a/packages/notebook/src/actions.tsx b/packages/notebook/src/actions.tsx index 3c1733ab633e..030ec2dfb646 100644 --- a/packages/notebook/src/actions.tsx +++ b/packages/notebook/src/actions.tsx @@ -724,7 +724,10 @@ export namespace NotebookActions { * This is a no-op if the first cell is the active cell. * The new cell will be activated. */ - export function extendSelectionAbove(notebook: Notebook): void { + export function extendSelectionAbove( + notebook: Notebook, + toTop: boolean + ): void { if (!notebook.model || !notebook.activeCell) { return; } @@ -736,7 +739,12 @@ export namespace NotebookActions { const state = Private.getState(notebook); notebook.mode = 'command'; - notebook.extendContiguousSelectionTo(notebook.activeCellIndex - 1); + //Check if toTop is true, if yes, selection is made till top. + if (toTop) { + notebook.extendContiguousSelectionTo(0); + } else { + notebook.extendContiguousSelectionTo(notebook.activeCellIndex - 1); + } Private.handleState(notebook, state, true); } @@ -749,7 +757,10 @@ export namespace NotebookActions { * This is a no-op if the last cell is the active cell. * The new cell will be activated. */ - export function extendSelectionBelow(notebook: Notebook): void { + export function extendSelectionBelow( + notebook: Notebook, + toBottom: boolean + ): void { if (!notebook.model || !notebook.activeCell) { return; } @@ -761,7 +772,12 @@ export namespace NotebookActions { const state = Private.getState(notebook); notebook.mode = 'command'; - notebook.extendContiguousSelectionTo(notebook.activeCellIndex + 1); + //Check if toBottom is true, if yes selection is made till bottom. + if (toBottom) { + notebook.extendContiguousSelectionTo(notebook.widgets.length - 1); + } else { + notebook.extendContiguousSelectionTo(notebook.activeCellIndex + 1); + } Private.handleState(notebook, state, true); } From a381e2153ee34296c2630add7a9b7b6c5509685d Mon Sep 17 00:00:00 2001 From: Adityar Rayala Date: Tue, 10 Sep 2019 01:20:51 +0530 Subject: [PATCH 2/8] Fixed Changes causing error --- examples/notebook/src/commands.ts | 14 ++++++-- packages/notebook/src/actions.tsx | 4 +-- tests/test-notebook/src/actions.spec.ts | 44 ++++++++++++------------- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/examples/notebook/src/commands.ts b/examples/notebook/src/commands.ts index 568c435e76e1..27b7ddc8118e 100644 --- a/examples/notebook/src/commands.ts +++ b/examples/notebook/src/commands.ts @@ -30,7 +30,9 @@ const cmdIds = { selectAbove: 'notebook-cells:select-above', selectBelow: 'notebook-cells:select-below', extendAbove: 'notebook-cells:extend-above', + extendTop: 'notebook-cells:extend-top', extendBelow: 'notebook-cells:extend-below', + extendBottom: 'notebook-cells:extend-bottom', editMode: 'notebook:edit-mode', merge: 'notebook-cells:merge', split: 'notebook-cells:split', @@ -164,11 +166,19 @@ export const SetupCommands = ( }); commands.addCommand(cmdIds.extendAbove, { label: 'Extend Above', - execute: () => NotebookActions.extendSelectionAbove(nbWidget.content) + execute: () => NotebookActions.extendSelectionAbove(nbWidget.content, false) + }); + commands.addCommand(cmdIds.extendTop, { + label: 'Extend Above', + execute: () => NotebookActions.extendSelectionAbove(nbWidget.content, true) }); commands.addCommand(cmdIds.extendBelow, { label: 'Extend Below', - execute: () => NotebookActions.extendSelectionBelow(nbWidget.content) + execute: () => NotebookActions.extendSelectionBelow(nbWidget.content, false) + }); + commands.addCommand(cmdIds.extendBottom, { + label: 'Extend Below', + execute: () => NotebookActions.extendSelectionBelow(nbWidget.content, true) }); commands.addCommand(cmdIds.merge, { label: 'Merge Cells', diff --git a/packages/notebook/src/actions.tsx b/packages/notebook/src/actions.tsx index 030ec2dfb646..9f83685f391f 100644 --- a/packages/notebook/src/actions.tsx +++ b/packages/notebook/src/actions.tsx @@ -739,7 +739,7 @@ export namespace NotebookActions { const state = Private.getState(notebook); notebook.mode = 'command'; - //Check if toTop is true, if yes, selection is made till top. + // Check if toTop is true, if yes, selection is made till top. if (toTop) { notebook.extendContiguousSelectionTo(0); } else { @@ -772,7 +772,7 @@ export namespace NotebookActions { const state = Private.getState(notebook); notebook.mode = 'command'; - //Check if toBottom is true, if yes selection is made till bottom. + // Check if toBottom is true, if yes selection is made till bottom. if (toBottom) { notebook.extendContiguousSelectionTo(notebook.widgets.length - 1); } else { diff --git a/tests/test-notebook/src/actions.spec.ts b/tests/test-notebook/src/actions.spec.ts index 547071b529a6..811420d49777 100644 --- a/tests/test-notebook/src/actions.spec.ts +++ b/tests/test-notebook/src/actions.spec.ts @@ -912,26 +912,26 @@ describe('@jupyterlab/notebook', () => { describe('#extendSelectionAbove()', () => { it('should extend the selection to the cell above', () => { widget.activeCellIndex = 1; - NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget, false); expect(widget.isSelected(widget.widgets[0])).to.equal(true); }); it('should be a no-op if there is no model', () => { widget.model = null; - NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget, false); expect(widget.activeCellIndex).to.equal(-1); }); it('should change to command mode if there is a selection', () => { widget.mode = 'edit'; widget.activeCellIndex = 1; - NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget, false); expect(widget.mode).to.equal('command'); }); it('should not wrap around to the bottom', () => { widget.mode = 'edit'; - NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget, false); expect(widget.activeCellIndex).to.equal(0); const last = widget.widgets[widget.widgets.length - 1]; expect(widget.isSelected(last)).to.equal(false); @@ -939,44 +939,44 @@ describe('@jupyterlab/notebook', () => { }); it('should deselect the current cell if the cell above is selected', () => { - NotebookActions.extendSelectionBelow(widget); - NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget, false); const cell = widget.activeCell; - NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget, false); expect(widget.isSelected(cell)).to.equal(false); }); it('should select only the first cell if we move from the second to first', () => { - NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget, false); const cell = widget.activeCell; - NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget, false); expect(widget.isSelected(cell)).to.equal(false); expect(widget.activeCellIndex).to.equal(0); }); it('should activate the cell', () => { widget.activeCellIndex = 1; - NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget, false); expect(widget.activeCellIndex).to.equal(0); }); }); describe('#extendSelectionBelow()', () => { it('should extend the selection to the cell below', () => { - NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget, false); expect(widget.isSelected(widget.widgets[0])).to.equal(true); expect(widget.isSelected(widget.widgets[1])).to.equal(true); }); it('should be a no-op if there is no model', () => { widget.model = null; - NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget, false); expect(widget.activeCellIndex).to.equal(-1); }); it('should change to command mode if there is a selection', () => { widget.mode = 'edit'; - NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget, false); expect(widget.mode).to.equal('command'); }); @@ -984,7 +984,7 @@ describe('@jupyterlab/notebook', () => { const last = widget.widgets.length - 1; widget.activeCellIndex = last; widget.mode = 'edit'; - NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget, false); expect(widget.activeCellIndex).to.equal(last); expect(widget.isSelected(widget.widgets[0])).to.equal(false); expect(widget.mode).to.equal('edit'); @@ -993,25 +993,25 @@ describe('@jupyterlab/notebook', () => { it('should deselect the current cell if the cell below is selected', () => { const last = widget.widgets.length - 1; widget.activeCellIndex = last; - NotebookActions.extendSelectionAbove(widget); - NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget, false); const current = widget.activeCell; - NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget, false); expect(widget.isSelected(current)).to.equal(false); }); it('should select only the last cell if we move from the second last to last', () => { const last = widget.widgets.length - 1; widget.activeCellIndex = last; - NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget, false); const current = widget.activeCell; - NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget, false); expect(widget.isSelected(current)).to.equal(false); expect(widget.activeCellIndex).to.equal(last); }); it('should activate the cell', () => { - NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget, false); expect(widget.activeCellIndex).to.equal(1); }); }); @@ -1019,7 +1019,7 @@ describe('@jupyterlab/notebook', () => { describe('#moveUp()', () => { it('should move the selected cells up', () => { widget.activeCellIndex = 2; - NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget, false); NotebookActions.moveUp(widget); expect(widget.isSelected(widget.widgets[0])).to.equal(true); expect(widget.isSelected(widget.widgets[1])).to.equal(true); @@ -1051,7 +1051,7 @@ describe('@jupyterlab/notebook', () => { describe('#moveDown()', () => { it('should move the selected cells down', () => { - NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget, false); NotebookActions.moveDown(widget); expect(widget.isSelected(widget.widgets[0])).to.equal(false); expect(widget.isSelected(widget.widgets[1])).to.equal(true); From c69747eb820717e346742b9f2af4d3232939307b Mon Sep 17 00:00:00 2001 From: Adityar Rayala Date: Tue, 10 Sep 2019 02:10:03 +0530 Subject: [PATCH 3/8] Added parameter documentation and updated labels --- examples/notebook/src/commands.ts | 4 ++-- packages/notebook/src/actions.tsx | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/notebook/src/commands.ts b/examples/notebook/src/commands.ts index 27b7ddc8118e..75083bf24eba 100644 --- a/examples/notebook/src/commands.ts +++ b/examples/notebook/src/commands.ts @@ -169,7 +169,7 @@ export const SetupCommands = ( execute: () => NotebookActions.extendSelectionAbove(nbWidget.content, false) }); commands.addCommand(cmdIds.extendTop, { - label: 'Extend Above', + label: 'Extend to Top', execute: () => NotebookActions.extendSelectionAbove(nbWidget.content, true) }); commands.addCommand(cmdIds.extendBelow, { @@ -177,7 +177,7 @@ export const SetupCommands = ( execute: () => NotebookActions.extendSelectionBelow(nbWidget.content, false) }); commands.addCommand(cmdIds.extendBottom, { - label: 'Extend Below', + label: 'Extend to Bottom', execute: () => NotebookActions.extendSelectionBelow(nbWidget.content, true) }); commands.addCommand(cmdIds.merge, { diff --git a/packages/notebook/src/actions.tsx b/packages/notebook/src/actions.tsx index 9f83685f391f..a77e39fc7cb3 100644 --- a/packages/notebook/src/actions.tsx +++ b/packages/notebook/src/actions.tsx @@ -719,14 +719,14 @@ export namespace NotebookActions { * Extend the selection to the cell above. * * @param notebook - The target notebook widget. - * + * @param toTop - If true, denotes selection to extend till the top. * #### Notes * This is a no-op if the first cell is the active cell. * The new cell will be activated. */ export function extendSelectionAbove( notebook: Notebook, - toTop: boolean + toTop: boolean = false ): void { if (!notebook.model || !notebook.activeCell) { return; @@ -752,14 +752,14 @@ export namespace NotebookActions { * Extend the selection to the cell below. * * @param notebook - The target notebook widget. - * + * @param toBottom - If true, denotes selection to extend till the bottom. * #### Notes * This is a no-op if the last cell is the active cell. * The new cell will be activated. */ export function extendSelectionBelow( notebook: Notebook, - toBottom: boolean + toBottom: boolean = false ): void { if (!notebook.model || !notebook.activeCell) { return; From 61885056846962fc8fcfdcfcf2f026ff66a38840 Mon Sep 17 00:00:00 2001 From: Adityar Rayala Date: Tue, 10 Sep 2019 09:12:31 +0530 Subject: [PATCH 4/8] Restored old definitions and changed comments --- packages/notebook-extension/src/index.ts | 4 ++-- packages/notebook/src/actions.tsx | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index a7033d080b3c..c6b9c56aac93 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -1463,7 +1463,7 @@ function addCommands( const current = getCurrent(args); if (current) { - return NotebookActions.extendSelectionAbove(current.content, false); + return NotebookActions.extendSelectionAbove(current.content); } }, isEnabled @@ -1485,7 +1485,7 @@ function addCommands( const current = getCurrent(args); if (current) { - return NotebookActions.extendSelectionBelow(current.content, false); + return NotebookActions.extendSelectionBelow(current.content); } }, isEnabled diff --git a/packages/notebook/src/actions.tsx b/packages/notebook/src/actions.tsx index a77e39fc7cb3..b7dd9a7a694f 100644 --- a/packages/notebook/src/actions.tsx +++ b/packages/notebook/src/actions.tsx @@ -719,7 +719,8 @@ export namespace NotebookActions { * Extend the selection to the cell above. * * @param notebook - The target notebook widget. - * @param toTop - If true, denotes selection to extend till the top. + * @param toTop - If true, denotes selection to extend to the top. + * * #### Notes * This is a no-op if the first cell is the active cell. * The new cell will be activated. @@ -739,7 +740,7 @@ export namespace NotebookActions { const state = Private.getState(notebook); notebook.mode = 'command'; - // Check if toTop is true, if yes, selection is made till top. + // Check if toTop is true, if yes, selection is made to the top. if (toTop) { notebook.extendContiguousSelectionTo(0); } else { @@ -752,7 +753,8 @@ export namespace NotebookActions { * Extend the selection to the cell below. * * @param notebook - The target notebook widget. - * @param toBottom - If true, denotes selection to extend till the bottom. + * @param toBottom - If true, denotes selection to extend to the bottom. + * * #### Notes * This is a no-op if the last cell is the active cell. * The new cell will be activated. @@ -772,7 +774,7 @@ export namespace NotebookActions { const state = Private.getState(notebook); notebook.mode = 'command'; - // Check if toBottom is true, if yes selection is made till bottom. + // Check if toBottom is true, if yes selection is made to the bottom. if (toBottom) { notebook.extendContiguousSelectionTo(notebook.widgets.length - 1); } else { From 2d293a3b87f38f282b2449ec317b174aaa8af26a Mon Sep 17 00:00:00 2001 From: Adityar Rayala Date: Tue, 10 Sep 2019 09:45:57 +0530 Subject: [PATCH 5/8] Updated changes in example notebook to default definitions --- examples/notebook/src/commands.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/notebook/src/commands.ts b/examples/notebook/src/commands.ts index 75083bf24eba..30ba8608b1c0 100644 --- a/examples/notebook/src/commands.ts +++ b/examples/notebook/src/commands.ts @@ -166,7 +166,7 @@ export const SetupCommands = ( }); commands.addCommand(cmdIds.extendAbove, { label: 'Extend Above', - execute: () => NotebookActions.extendSelectionAbove(nbWidget.content, false) + execute: () => NotebookActions.extendSelectionAbove(nbWidget.content) }); commands.addCommand(cmdIds.extendTop, { label: 'Extend to Top', @@ -174,7 +174,7 @@ export const SetupCommands = ( }); commands.addCommand(cmdIds.extendBelow, { label: 'Extend Below', - execute: () => NotebookActions.extendSelectionBelow(nbWidget.content, false) + execute: () => NotebookActions.extendSelectionBelow(nbWidget.content) }); commands.addCommand(cmdIds.extendBottom, { label: 'Extend to Bottom', From 80ae8a71d0b9f5e49ba99e04b0fc833e8c407c4b Mon Sep 17 00:00:00 2001 From: Adityar Rayala Date: Tue, 10 Sep 2019 23:57:35 +0530 Subject: [PATCH 6/8] Changed the test-notebook function and added the call with true parameter --- tests/test-notebook/src/actions.spec.ts | 55 +++++++++++++++---------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/tests/test-notebook/src/actions.spec.ts b/tests/test-notebook/src/actions.spec.ts index 811420d49777..2bdb20b1b35f 100644 --- a/tests/test-notebook/src/actions.spec.ts +++ b/tests/test-notebook/src/actions.spec.ts @@ -912,26 +912,32 @@ describe('@jupyterlab/notebook', () => { describe('#extendSelectionAbove()', () => { it('should extend the selection to the cell above', () => { widget.activeCellIndex = 1; - NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget); + expect(widget.isSelected(widget.widgets[0])).to.equal(true); + }); + + it('should extend the selection to the topmost cell', () => { + widget.activeCellIndex = 1; + NotebookActions.extendSelectionAbove(widget, true); expect(widget.isSelected(widget.widgets[0])).to.equal(true); }); it('should be a no-op if there is no model', () => { widget.model = null; - NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget); expect(widget.activeCellIndex).to.equal(-1); }); it('should change to command mode if there is a selection', () => { widget.mode = 'edit'; widget.activeCellIndex = 1; - NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget); expect(widget.mode).to.equal('command'); }); it('should not wrap around to the bottom', () => { widget.mode = 'edit'; - NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget); expect(widget.activeCellIndex).to.equal(0); const last = widget.widgets[widget.widgets.length - 1]; expect(widget.isSelected(last)).to.equal(false); @@ -939,44 +945,49 @@ describe('@jupyterlab/notebook', () => { }); it('should deselect the current cell if the cell above is selected', () => { - NotebookActions.extendSelectionBelow(widget, false); - NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget); + NotebookActions.extendSelectionBelow(widget); const cell = widget.activeCell; - NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget); expect(widget.isSelected(cell)).to.equal(false); }); it('should select only the first cell if we move from the second to first', () => { - NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget); const cell = widget.activeCell; - NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget); expect(widget.isSelected(cell)).to.equal(false); expect(widget.activeCellIndex).to.equal(0); }); it('should activate the cell', () => { widget.activeCellIndex = 1; - NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget); expect(widget.activeCellIndex).to.equal(0); }); }); describe('#extendSelectionBelow()', () => { it('should extend the selection to the cell below', () => { - NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget); expect(widget.isSelected(widget.widgets[0])).to.equal(true); expect(widget.isSelected(widget.widgets[1])).to.equal(true); }); + it('should extend the selection the bottomost cell', () => { + NotebookActions.extendSelectionBelow(widget, true); + expect(widget.isSelected(widget.widgets[0])).to.equal(true); + expect(widget.isSelected(widget.widgets[1])).to.equal(true); + }); it('should be a no-op if there is no model', () => { widget.model = null; - NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget); expect(widget.activeCellIndex).to.equal(-1); }); it('should change to command mode if there is a selection', () => { widget.mode = 'edit'; - NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget); expect(widget.mode).to.equal('command'); }); @@ -984,7 +995,7 @@ describe('@jupyterlab/notebook', () => { const last = widget.widgets.length - 1; widget.activeCellIndex = last; widget.mode = 'edit'; - NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget); expect(widget.activeCellIndex).to.equal(last); expect(widget.isSelected(widget.widgets[0])).to.equal(false); expect(widget.mode).to.equal('edit'); @@ -993,25 +1004,25 @@ describe('@jupyterlab/notebook', () => { it('should deselect the current cell if the cell below is selected', () => { const last = widget.widgets.length - 1; widget.activeCellIndex = last; - NotebookActions.extendSelectionAbove(widget, false); - NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget); + NotebookActions.extendSelectionAbove(widget); const current = widget.activeCell; - NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget); expect(widget.isSelected(current)).to.equal(false); }); it('should select only the last cell if we move from the second last to last', () => { const last = widget.widgets.length - 1; widget.activeCellIndex = last; - NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget); const current = widget.activeCell; - NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget); expect(widget.isSelected(current)).to.equal(false); expect(widget.activeCellIndex).to.equal(last); }); it('should activate the cell', () => { - NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget); expect(widget.activeCellIndex).to.equal(1); }); }); @@ -1019,7 +1030,7 @@ describe('@jupyterlab/notebook', () => { describe('#moveUp()', () => { it('should move the selected cells up', () => { widget.activeCellIndex = 2; - NotebookActions.extendSelectionAbove(widget, false); + NotebookActions.extendSelectionAbove(widget); NotebookActions.moveUp(widget); expect(widget.isSelected(widget.widgets[0])).to.equal(true); expect(widget.isSelected(widget.widgets[1])).to.equal(true); @@ -1051,7 +1062,7 @@ describe('@jupyterlab/notebook', () => { describe('#moveDown()', () => { it('should move the selected cells down', () => { - NotebookActions.extendSelectionBelow(widget, false); + NotebookActions.extendSelectionBelow(widget); NotebookActions.moveDown(widget); expect(widget.isSelected(widget.widgets[0])).to.equal(false); expect(widget.isSelected(widget.widgets[1])).to.equal(true); From 0ac8f2c111a8191d079296a986d7a0aa714a934b Mon Sep 17 00:00:00 2001 From: Adityar Rayala Date: Wed, 11 Sep 2019 18:23:36 +0530 Subject: [PATCH 7/8] Added checks in test-notebook --- tests/test-notebook/src/actions.spec.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test-notebook/src/actions.spec.ts b/tests/test-notebook/src/actions.spec.ts index 2bdb20b1b35f..ce8fcd5e1a90 100644 --- a/tests/test-notebook/src/actions.spec.ts +++ b/tests/test-notebook/src/actions.spec.ts @@ -919,7 +919,9 @@ describe('@jupyterlab/notebook', () => { it('should extend the selection to the topmost cell', () => { widget.activeCellIndex = 1; NotebookActions.extendSelectionAbove(widget, true); - expect(widget.isSelected(widget.widgets[0])).to.equal(true); + for (let i = widget.activeCellIndex; i >= 0; i--) { + expect(widget.isSelected(widget.widgets[i])).to.equal(true); + } }); it('should be a no-op if there is no model', () => { @@ -976,8 +978,9 @@ describe('@jupyterlab/notebook', () => { it('should extend the selection the bottomost cell', () => { NotebookActions.extendSelectionBelow(widget, true); - expect(widget.isSelected(widget.widgets[0])).to.equal(true); - expect(widget.isSelected(widget.widgets[1])).to.equal(true); + for (let i = widget.activeCellIndex; i < widget.widgets.length; i++) { + expect(widget.isSelected(widget.widgets[i])).to.equal(true); + } }); it('should be a no-op if there is no model', () => { widget.model = null; From 5e33ad4e9b3c4b56649ca79e90f766fa18ffa398 Mon Sep 17 00:00:00 2001 From: bw-space Date: Sat, 12 Oct 2019 10:25:16 +0530 Subject: [PATCH 8/8] Changed the Shortcut to select to Top and to Bottom --- packages/notebook-extension/schema/tracker.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/notebook-extension/schema/tracker.json b/packages/notebook-extension/schema/tracker.json index 237850049c3e..bc75cb91b87b 100644 --- a/packages/notebook-extension/schema/tracker.json +++ b/packages/notebook-extension/schema/tracker.json @@ -89,7 +89,7 @@ }, { "command": "notebook:extend-marked-cells-top", - "keys": ["Shift PageUp"], + "keys": ["Shift Home"], "selector": ".jp-Notebook:focus" }, { @@ -99,7 +99,7 @@ }, { "command": "notebook:extend-marked-cells-bottom", - "keys": ["Shift PageDown"], + "keys": ["Shift End"], "selector": ".jp-Notebook:focus" }, {