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

Don't prevent default if the user is selecting text in a notebook output. #6015

Merged
merged 2 commits into from Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/notebook/src/widget.ts
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
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