Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Do not block shift-click mouse up handler on active cell #16647

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

Merged
merged 8 commits into from
Aug 9, 2024

Conversation

EdsterG
Copy link
Contributor

@EdsterG EdsterG commented Aug 6, 2024

References

Fixes #16633

Code changes

Don't prevent default behavior when the current cell is the active cell.

User-facing changes

shift+click in the same cell no longer swallows the mouseup event.

Backwards-incompatible changes

N/A

Copy link

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

@krassowski krassowski added the bug label Aug 7, 2024
@krassowski krassowski added this to the 4.2.x milestone Aug 7, 2024
@krassowski
Copy link
Member

Thank you, this looks good. I think we would also want to add a test case, somewhere here:

it('should extend selection if invoked with shift', () => {
widget.activeCellIndex = 3;
// shift click below
simulate(widget.widgets[4].node, 'mousedown', { shiftKey: true });
expect(widget.activeCellIndex).toBe(4);
expect(selected(widget)).toEqual([3, 4]);
// shift click above
simulate(widget.widgets[1].node, 'mousedown', { shiftKey: true });
expect(widget.activeCellIndex).toBe(1);
expect(selected(widget)).toEqual([1, 2, 3]);
// shift click expand
simulate(widget.widgets[0].node, 'mousedown', { shiftKey: true });
expect(widget.activeCellIndex).toBe(0);
expect(selected(widget)).toEqual([0, 1, 2, 3]);
// shift click contract
simulate(widget.widgets[2].node, 'mousedown', { shiftKey: true });
expect(widget.activeCellIndex).toBe(2);
expect(selected(widget)).toEqual([2, 3]);
});
it('should not extend a selection if there is text selected in the output', () => {
const codeCellIndex = 3;
widget.activeCellIndex = codeCellIndex;
// 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[codeCellIndex + 2].node, 'mousedown', {
shiftKey: true
});
expect(widget.activeCellIndex).toBe(codeCellIndex);
expect(selected(widget)).toEqual([]);
});

@krassowski krassowski changed the title check if current cell is the active cell Do not block shift-click mouse up handler on active cell Aug 7, 2024
@EdsterG
Copy link
Contributor Author

EdsterG commented Aug 7, 2024

Thank you for the support.

@EdsterG
Copy link
Contributor Author

EdsterG commented Aug 7, 2024

I'm not sure why the tests are failing. After looking at this some more I think the test I added doesn't actually cover the new behavior. For the test case added in this PR, selected will be empty even without this PR.

What really needs to be tested is whether the widget is a registered mouse up event listener or whether the the mouse mode is null: expect(widget._mouseMode.toBe(null)). Also, the new test case needs to be moved to the top because shift clicking the first cell after expanding the selection is valid, and will still be listening to mouseup events.

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the parens are off

packages/notebook/test/widget.spec.ts Outdated Show resolved Hide resolved
packages/notebook/test/widget.spec.ts Outdated Show resolved Hide resolved
@EdsterG
Copy link
Contributor Author

EdsterG commented Aug 8, 2024

It looks like the parens are off

Oops, thanks! I'm currently not setup for JS dev, so no linters :(

@EdsterG
Copy link
Contributor Author

EdsterG commented Aug 8, 2024

Looks like the test linter doesn't like _mouseMode because it's private. What's the suggested work around here? Or an alternative to test the same thing.

packages/notebook/test/widget.spec.ts Outdated Show resolved Hide resolved
packages/notebook/test/widget.spec.ts Outdated Show resolved Hide resolved
Comment on lines 2675 to 2682
// We don't want to block the shift-click mouse up handler
// when the current cell is the active cell.
const isActiveCell = index == this.activeCellIndex;
if (
button === 0 &&
shiftKey &&
!hasSelection &&
!isActiveCell &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving it a bit more thought I think this has to be more subtle. The idea is that user can press Shift, press mouse down and start dragging cursor to select cells. Instead of short-circuiting here I think we should store the activeCellIndex if starts shift + mousedown on active cell and skip preventing default on _evtDocumentMouseup() if the cell index has not changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will push a commit

packages/notebook/test/widget.spec.ts Fixed Show fixed Hide fixed
packages/notebook/test/widget.spec.ts Fixed Show fixed Hide fixed
Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @EdsterG! Please let me know once you had a chance to look at the changes I've made and whether you have any comments.

packages/notebook/test/widget.spec.ts Outdated Show resolved Hide resolved
@EdsterG
Copy link
Contributor Author

EdsterG commented Aug 9, 2024

Yay, thanks for pushing the changes. LGTM.

@krassowski krassowski merged commit 165d589 into jupyterlab:main Aug 9, 2024
83 checks passed
@EdsterG EdsterG deleted the fix_shift_click branch August 9, 2024 17:24
@krassowski
Copy link
Member

@meeseeksdev please backport to 4.2.x

krassowski pushed a commit that referenced this pull request Aug 9, 2024
…ve cell (#16663)

Co-authored-by: Eddie Groshev <eddie_g_89@hotmail.com>
ImpSy pushed a commit to spotinst/jupyterlab that referenced this pull request Jan 7, 2025
…16647)

* check if current cell is the active cell

* add unit test

* update unit test

* fix typo in unit tests

* Do not use private variables in tests, use events

* Do not prevent default on mouse + shift up if in the same cell

* Fix the test

* Adjust comment

---------

Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JupyterLab suppresses left mouse up while holding shift.
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.