Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.8k
Open
Labels
Description
Problem
Currently, pressing the Escape key while editing a cell immediately switches JupyterLab into Command Mode.
In many common editors, however, Escape is first used to clear any active cursor selection.
This difference can feel unintuitive: if a user has a selection active, pressing Escape may be expected to simply clear the selection rather than exit Edit Mode altogether.
Proposed Solution
- When a selection is active, pressing Escape should clear the selection.
- Only when no selection is active should Escape switch from Edit Mode to Command Mode.
One possible modification could be:
(jupyterlab/packages/codemirror/src/commands.ts)
export function simplifySelectionAndMaybeSwitchToCommandMode(target: { dom: HTMLElement; state: EditorState; dispatch: (transaction: Transaction) => void; }): boolean { const arg = { state: target.state, dispatch: target.dispatch }; const preventDefault = simplifySelection(arg);- if (target.dom.closest(ACTIVE_CELL_IN_EDIT_MODE_SELECTOR)) {+ if (!preventDefault && target.dom.closest(ACTIVE_CELL_IN_EDIT_MODE_SELECTOR)) { // do not prevent default to allow switching to command mode return false; } else { return preventDefault; } }Note that the simplifySelection command returns false when the selection is already simple (i.e., no change was needed).