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

Improve the keybinding input guard using proposed lumino features #15927

Merged
merged 18 commits into from
Apr 17, 2024

Conversation

krassowski
Copy link
Member

@krassowski krassowski commented Mar 6, 2024

References

This PR requires a new lumino release and may need to wait for 4.2.0; a short-term solution (hotfix) for JupyterLab 4.1.4 is available in #15913.

The CI on this PR is expected to fail until jupyterlab/lumino#689 is merged, released and we bump versions here.

Fixes #15744

Also relates to #4301

Code changes

Use new holdKeyBindingExecution() to improve the logic from #15790 and mark the problematic shortcuts with preventDefault: false.

User-facing changes

  • when a keybinding marked with "preventDefault": false conflicts with default browser action such as typing a character, it will not be executed, and it the default browser action will be executed.
  • all other keybindings will prevent the default browser action as they used to in JupyterLab <=4.1.2

Backwards-incompatible changes

None

@krassowski krassowski added the bug label Mar 6, 2024
Copy link

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

@krassowski krassowski added this to the 4.2.0 milestone Mar 6, 2024
@krassowski krassowski changed the title Improve the keybinding input guard using new lumino property and method Improve the keybinding input guard using proposed lumino features Mar 6, 2024
@krassowski
Copy link
Member Author

This still requires jupyterlab/lumino#689 but I am marking this as ready for review as it can be tested by linking local installation of lumino with jupyterlab/lumino#689 applied.

@krassowski
Copy link
Member Author

How to test it:

  1. Without the patch add the following shortcut in JSON Setting Editor → Keyboard Shortcuts:
    {
        "shortcuts": [
            {
                "command": "runmenu:run",
                "selector": "[data-jp-code-runner]",
                "keys": [
                    "Shift ["
                ]
            }
        ]
    }
  2. In notebook press Shift + [
  3. See that cell gets run (and { does not get typed)
  4. Apply the patch by checking out the Optional prevent default and asynchronous hold for keybinding execution lumino#689 lumino branch
  5. Build lumino with yarn run build
  6. In JupyterLab repo with this branch run jlpm link path/to/lumino/packages/commands
  7. Build JupyterLab with jlpm run build
  8. Change the setting to (remember to press save icon):
    {
        "shortcuts": [
            {
                "command": "runmenu:run",
                "selector": "[data-jp-code-runner]",
                "keys": [
                    "Shift ["
                ],
                "preventDefault": false
            }
        ]
    }
  9. In notebook press Shift + [ again
  10. See that { gets typed
  11. Change preventDefault to true (and save)
  12. In notebook press Shift + [ again
  13. See that cell gets run.

@krassowski
Copy link
Member Author

demo

@krassowski
Copy link
Member Author

The failing UI Tests / Visual Regression Tests appear potentially relvant.

@krassowski
Copy link
Member Author

The CI will be fixed once we merge #16078.

Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

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

Thanks @krassowski it looks good to me.

I guess we want to merge first #16078 to ensure the tests are passing for this one too.

@krassowski
Copy link
Member Author

The failures of:

    [jupyterlab] › test/jupyterlab/notebook-search.test.ts:276:7 › Notebook Search › Search in multiple selected cells 

are persistent across three re-runs - I will investigate.

@krassowski krassowski marked this pull request as draft April 8, 2024 16:08
@krassowski
Copy link
Member Author

No that test does not appear relevant:

Actual Expected
image image

There is 1 frame when the toolbar is not yet there, and one frame when it is half-populated.

However, I wonder if this introduces some more flakiness to the test runs because when we assumed that a command would be executed instantaneously after pressing keys, now it can take a few milliseconds more.

We can improve the logic by attaching keyup which should short-circuit; this may save a few milliseconds in the case if onbeforeinput would not be called.

@krassowski krassowski marked this pull request as ready for review April 9, 2024 17:15
Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

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

Thanks @krassowski

@fcollonval fcollonval merged commit 2ceabd8 into jupyterlab:main Apr 17, 2024
81 checks passed
gderocher pushed a commit to gderocher/jupyterlab that referenced this pull request Apr 26, 2024
…pyterlab#15927)

* Fix saving shortcut not preventing default

* Run `Command + Shift + c` immediately too

* Command + S for saving on Mac

* Use lumino's `holdKeyBindingExecution` and disable `preventDefault`

on inline completer shortcuts

* Fix compilation by adding type argument

* Upgrade lumino packages to v2024.3.25

* Short-circuit on `keyup` too, disconnect handlers when done

* Wait for command mode confirmation in search test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment