From 090e4bc8b9badb7db91472e42ac916a8d23d853a Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Thu, 21 Feb 2019 09:10:10 -0800 Subject: [PATCH 1/2] Don't prevent default if the user is selecting text in a notebook output. --- packages/notebook/src/widget.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/notebook/src/widget.ts b/packages/notebook/src/widget.ts index cce6c4b279dd..e17bc8145aca 100644 --- a/packages/notebook/src/widget.ts +++ b/packages/notebook/src/widget.ts @@ -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(); From 11e9d743ccbdfd4ce30fd6d969cfeaa3e0c0f761 Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Thu, 21 Feb 2019 09:30:55 -0800 Subject: [PATCH 2/2] Add test. --- tests/test-notebook/src/widget.spec.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test-notebook/src/widget.spec.ts b/tests/test-notebook/src/widget.spec.ts index 74f4f003dd67..d7f310544bd8 100644 --- a/tests/test-notebook/src/widget.spec.ts +++ b/tests/test-notebook/src/widget.spec.ts @@ -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({});