You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently lumino shortcuts can prevent user from typing characters on certain keyboards (because it always calls preventDefault() and stopPropagation() on matched keyboard events)
However, some shortcuts need to be executed immediately to prevent default browser action
Currently there is no way to distinguish the situation in which the current keyboard event would invoke a shortcut which needs such immediately handling
Add new public method on commands to check if the default action on the event should be prevented, say:
willPreventDefault(event){// Bail immediately if playing back keystrokes.if(this._replaying||CommandRegistry.isModifierKeyPressed(event)){return;}// Get the normalized keystroke for the event.letkeystroke=CommandRegistry.keystrokeForKeydownEvent(event);// If the keystroke is not valid for the keyboard layout, replay// any suppressed events and clear the pending state.if(!keystroke){this._replayKeydownEvents();this._clearPendingState();return;}// Add the keystroke to the current key sequence.constkeystrokes=[*this._keystrokes,keystroke];// Find the exact and partial matches for the key sequence.let{ exact }=Private.matchKeyBinding(this._keyBindings,keystrokes,event);if(exact.preventDefault||partial.preventDefault){returntrue;}returnfalse;}
Change processKeydownEvent to only preventDefault when needed, this is change:
In JupyterLab:
a) mark all keybindings as preventDefault=false by default, and flick the few ones which should prevent default manually to true
b) rework the evtKeydown handler to call willPreventDefault(event) and depending on the result decide whether to process the event immediately or not
In a future major lumino version, consider changing preventDefault default to false, and adopting the refined evtKeydown implementation from JupyterLab
willPreventDefault is a bit single-use case method which needs to be called in a very specific way (after previous processKeydownEvent but before next processKeydownEvent). I don't like it from the API design perspective.
the script on the lab side is wrong with respect to chord because it just skips call to processKeydownEvent if it find that user input arises from a new key event; this can still result in a command being dispatched if it was a partial match; we need a better solution on lumino level
Problem
preventDefault()
andstopPropagation()
on matched keyboard events)Proposed Solution
Add new attribute
preventDefault: bool = true
toIKeyBindingOptions
Add new public method on commands to check if the default action on the event should be prevented, say:
Change
processKeydownEvent
to onlypreventDefault
when needed, this is change:lumino/packages/commands/src/index.ts
Lines 553 to 557 in f101429
to:
In JupyterLab:
a) mark all keybindings as preventDefault=false by default, and flick the few ones which should prevent default manually to true
b) rework the
evtKeydown
handler to callwillPreventDefault(event)
and depending on the result decide whether to process the event immediately or notIn a future major lumino version, consider changing
preventDefault
default tofalse
, and adopting the refinedevtKeydown
implementation from JupyterLabAdditional context
Ctrl + S
triggle browser's "save page", not save notebook in4.1.3
jupyterlab#15912The text was updated successfully, but these errors were encountered: