Skip to content

Make the key binding listener phase (capture vs. bubbling) a per-key-binding option in IKeyBinding #761

@firai

Description

@firai

Problem

@krassowski (jupyterlab/jupyterlab#15897 (comment)):

As summarised in jupyterlab/jupyterlab#14115 (comment), with changes from listening to keydown events in capture phase to listening to them in bubbling phase (JupyterLab 4.1) we lost ability to preventDefault() the default CodeMirror shortcuts behaviour. The current solution is to override respective CM commands manually (as in jupyterlab/jupyterlab#15898) and check if it should possibly be prevented (e.g. based on the class of a closest DOM node), but it does not work if user disables such a command or changes the shortcut.

Proposed Solution

@krassowski (jupyterlab/jupyterlab#15897 (comment)):

  1. Make it a property of lumino's IKeybinding so some shortcuts can be invoked already in capture phase and others only in bubbling phase

Based on initial review, in order to implement option 2, it seems like another addEventListener() needs to be added around

document.addEventListener('keydown', this, !this._bubblingKeydown);

so that one event listener has useCapture (the last argument) as true and the other has false, so that both capture and bubbling phases trigger the callback.

And then something like #689 needs to be added so that key bindings are processed based on whether a new IKeyBinding capture phase flag is true for a particular key binding.

Help with implementing this or suggestions for how to implement this are welcome.

Additional context

jupyterlab/jupyterlab#15897
jupyterlab-contrib/jupyterlab-vim#138

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions