Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the Selection of cells till Top and Bottom #7177

Merged
merged 8 commits into from Oct 12, 2019
14 changes: 12 additions & 2 deletions examples/notebook/src/commands.ts
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
});
commands.addCommand(cmdIds.extendTop, {
label: 'Extend Above',
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
execute: () => NotebookActions.extendSelectionAbove(nbWidget.content, true)
});
commands.addCommand(cmdIds.extendBelow, {
label: 'Extend Below',
execute: () => NotebookActions.extendSelectionBelow(nbWidget.content)
execute: () => NotebookActions.extendSelectionBelow(nbWidget.content, false)
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
});
commands.addCommand(cmdIds.extendBottom, {
label: 'Extend Below',
execute: () => NotebookActions.extendSelectionBelow(nbWidget.content, true)
});
commands.addCommand(cmdIds.merge, {
label: 'Merge Cells',
Expand Down
4 changes: 2 additions & 2 deletions packages/notebook/src/actions.tsx
Expand Up @@ -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.
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
if (toTop) {
notebook.extendContiguousSelectionTo(0);
} else {
Expand Down Expand Up @@ -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.
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
if (toBottom) {
notebook.extendContiguousSelectionTo(notebook.widgets.length - 1);
} else {
Expand Down
44 changes: 22 additions & 22 deletions tests/test-notebook/src/actions.spec.ts
Expand Up @@ -912,79 +912,79 @@ describe('@jupyterlab/notebook', () => {
describe('#extendSelectionAbove()', () => {
it('should extend the selection to the cell above', () => {
widget.activeCellIndex = 1;
NotebookActions.extendSelectionAbove(widget);
NotebookActions.extendSelectionAbove(widget, false);
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
expect(widget.isSelected(widget.widgets[0])).to.equal(true);
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
});

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);
expect(widget.mode).to.equal('edit');
});

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);
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
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');
});

it('should not wrap around to the top', () => {
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');
Expand All @@ -993,33 +993,33 @@ 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);
});
});

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);
Expand Down Expand Up @@ -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);
Expand Down