Skip to content

Commit

Permalink
Backport PR #15938: Revert "Prevent command shortcuts from preventing…
Browse files Browse the repository at this point in the history
… user input" (#15940)

Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and krassowski committed Mar 7, 2024
1 parent a3cdd38 commit cc6cdea
Showing 1 changed file with 0 additions and 81 deletions.
81 changes: 0 additions & 81 deletions packages/application/src/lab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,72 +199,6 @@ export class JupyterLab extends JupyterFrontEnd<ILabShell> {
});
}

/**
* Override keydown handling to prevent command shortcuts from preventing user input.
*
* This introduces a slight delay to the command invocation, but no delay to user input.
*/
protected evtKeydown(event: KeyboardEvent): void {
// Process select keys which may call `preventDefault()` immediately
if (
['Tab', 'ArrowDown', 'ArrowUp', 'ArrowRight', 'ArrowLeft'].includes(
event.key
)
) {
return this.commands.processKeydownEvent(event);
}
// Process remaining events conditionally, depending on whether they would lead to text insertion
const causesInputPromise = Promise.race([
new Promise(resolve => {
if (!event.target) {
return resolve(false);
}
event.target.addEventListener(
'beforeinput',
(inputEvent: InputEvent) => {
switch (inputEvent.inputType) {
case 'historyUndo':
case 'historyRedo': {
if (
inputEvent.target instanceof Element &&
inputEvent.target.closest('[data-jp-undoer]')
) {
// Allow to use custom undo/redo bindings on `jpUndoer`s
inputEvent.preventDefault();
return resolve(false);
}
break;
}
case 'insertLineBreak': {
if (
inputEvent.target instanceof Element &&
inputEvent.target.closest('.jp-Cell')
) {
// Allow to override the default action of Shift + Enter on cells as this is used for cell execution
inputEvent.preventDefault();
return resolve(false);
}
break;
}
}
return resolve(true);
},
{ once: true }
);
}),
new Promise(resolve => {
setTimeout(() => resolve(false), Private.INPUT_GUARD_TIMEOUT);
})
]);
causesInputPromise
.then(willCauseInput => {
if (!willCauseInput) {
this.commands.processKeydownEvent(event);
}
})
.catch(console.warn);
}

private _info: JupyterLab.IInfo = JupyterLab.defaultInfo;
private _paths: JupyterFrontEnd.IPaths;
private _allPluginsActivated = new PromiseDelegate<void>();
Expand Down Expand Up @@ -439,18 +373,3 @@ export namespace JupyterLab {
| JupyterFrontEndPlugin<any, any, any>[];
}
}

/**
* A namespace for module-private functionality.
*/
namespace Private {
/**
* The delay for invoking a command introduced by user input guard.
* Decreasing this value may lead to commands incorrectly triggering
* on user input. Increasing this value will lead to longer delay for
* command invocation. Note that user input is never delayed.
*
* The value represents the number in milliseconds.
*/
export const INPUT_GUARD_TIMEOUT = 10;
}

0 comments on commit cc6cdea

Please sign in to comment.