Skip to content

Commit

Permalink
Merge pull request jupyterlab#6015 from ian-r-rose/shift-click-extend…
Browse files Browse the repository at this point in the history
…-selection

Don't prevent default if the user is selecting text in a notebook output.
  • Loading branch information
blink1073 authored Feb 26, 2019
2 parents 07c6df7 + 11e9d74 commit b50ea42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/notebook/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,10 @@ export class Notebook extends StaticNotebook {
if (targetArea === 'notebook') {
this.deselectAll();
} else if (targetArea === 'prompt' || targetArea === 'cell') {
if (button === 0 && shiftKey) {
// We don't want to prevent the default selection behavior
// if there is currently text selected in an output.
const hasSelection = window.getSelection().toString() !== '';
if (button === 0 && shiftKey && !hasSelection) {
// Prevent browser selecting text in prompt or output
event.preventDefault();

Expand Down
15 changes: 15 additions & 0 deletions tests/test-notebook/src/widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,21 @@ describe('@jupyter/notebook', () => {
expect(selected(widget)).to.deep.equal([2, 3]);
});

it('should not extend a selection if there is text selected in the output', () => {
widget.activeCellIndex = 2;

// Set a selection in the active cell outputs.
const selection = window.getSelection();
selection.selectAllChildren(
(widget.activeCell as CodeCell).outputArea.node
);

// Shift click below, which should not extend cells selection.
simulate(widget.widgets[4].node, 'mousedown', { shiftKey: true });
expect(widget.activeCellIndex).to.equal(2);
expect(selected(widget)).to.deep.equal([]);
});

it('should leave a markdown cell rendered', () => {
const code = widget.model.contentFactory.createCodeCell({});
const md = widget.model.contentFactory.createMarkdownCell({});
Expand Down

0 comments on commit b50ea42

Please sign in to comment.