From 1c8dd62a248c46c930175d8a3af6655d31827da5 Mon Sep 17 00:00:00 2001 From: Aaron Munger Date: Fri, 19 Apr 2024 13:28:09 -0700 Subject: [PATCH] redirect text editor commands to null when focused in webview text editor --- .../contrib/cellCommands/nullCommand.ts | 46 +++++++++++++++++++ .../notebook/browser/notebook.contribution.ts | 1 + .../notebook/browser/notebookEditorWidget.ts | 4 +- .../browser/view/renderers/webviewPreloads.ts | 2 +- .../notebook/common/notebookContextKeys.ts | 2 +- 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/nullCommand.ts diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/nullCommand.ts b/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/nullCommand.ts new file mode 100644 index 00000000000000..8d01ad1059a00c --- /dev/null +++ b/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/nullCommand.ts @@ -0,0 +1,46 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { KeyCode } from 'vs/base/common/keyCodes'; +import { registerAction2, Action2 } from 'vs/platform/actions/common/actions'; +import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; +import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_OUTPUT_INPUT_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys'; + +registerAction2(class NullAction extends Action2 { + constructor() { + super({ + id: 'notebook.nullCommand', + title: 'Null Command', + f1: false, + keybinding: [ + { + when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_OUTPUT_INPUT_FOCUSED), + primary: KeyCode.DownArrow, + weight: KeybindingWeight.WorkbenchContrib + 1 + }, + { + when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_OUTPUT_INPUT_FOCUSED), + primary: KeyCode.UpArrow, + weight: KeybindingWeight.WorkbenchContrib + 1 + }, + { + when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_OUTPUT_INPUT_FOCUSED), + primary: KeyCode.Delete, + weight: KeybindingWeight.WorkbenchContrib + 1 + }, + { + when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_OUTPUT_INPUT_FOCUSED), + primary: KeyCode.Enter, + weight: KeybindingWeight.WorkbenchContrib + 1 + } + ] + }); + } + + run() { + //noop + } +}); diff --git a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts index e27f6630ef8e53..1a093a39872fd6 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -89,6 +89,7 @@ import 'vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionSta import 'vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar'; import 'vs/workbench/contrib/notebook/browser/contrib/undoRedo/notebookUndoRedo'; import 'vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands'; +import 'vs/workbench/contrib/notebook/browser/contrib/cellCommands/nullCommand'; import 'vs/workbench/contrib/notebook/browser/contrib/viewportWarmup/viewportWarmup'; import 'vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout'; import 'vs/workbench/contrib/notebook/browser/contrib/debug/notebookBreakpoints'; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index ab543edd1ea2c2..3a65e207a9367b 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -75,7 +75,7 @@ import { NotebookOverviewRuler } from 'vs/workbench/contrib/notebook/browser/vie import { ListTopCellToolbar } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookTopCellToolbar'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { CellEditType, CellKind, INotebookSearchOptions, RENDERER_NOT_AVAILABLE, SelectionStateType } from 'vs/workbench/contrib/notebook/common/notebookCommon'; -import { NOTEBOOK_CURSOR_NAVIGATION_MODE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_OUTPUT_FOCUSED, NOTEBOOK_OUPTUT_INPUT_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys'; +import { NOTEBOOK_CURSOR_NAVIGATION_MODE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_OUTPUT_FOCUSED, NOTEBOOK_OUTPUT_INPUT_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys'; import { INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService'; import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService'; @@ -415,7 +415,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD this._isVisible = true; this._editorFocus = NOTEBOOK_EDITOR_FOCUSED.bindTo(this.scopedContextKeyService); this._outputFocus = NOTEBOOK_OUTPUT_FOCUSED.bindTo(this.scopedContextKeyService); - this._outputInputFocus = NOTEBOOK_OUPTUT_INPUT_FOCUSED.bindTo(this.scopedContextKeyService); + this._outputInputFocus = NOTEBOOK_OUTPUT_INPUT_FOCUSED.bindTo(this.scopedContextKeyService); this._editorEditable = NOTEBOOK_EDITOR_EDITABLE.bindTo(this.scopedContextKeyService); this._cursorNavMode = NOTEBOOK_CURSOR_NAVIGATION_MODE.bindTo(this.scopedContextKeyService); // Never display the native cut/copy context menu items in notebooks diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts index c350ab72ff48a2..c7aa6196b5c0e2 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts @@ -196,7 +196,7 @@ async function webviewPreloads(ctx: PreloadContext) { } const id = lastFocusedOutput?.id; - if (id && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA')) { + if (id && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA' || activeElement.tagName === 'SELECT')) { postNotebookMessage('outputInputFocus', { inputFocused: true, id }); activeElement.addEventListener('blur', () => { diff --git a/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts b/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts index a487c2c0fda71c..4aad255f787616 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts @@ -21,7 +21,7 @@ export const INTERACTIVE_WINDOW_IS_ACTIVE_EDITOR = ContextKeyExpr.equals('active export const NOTEBOOK_EDITOR_FOCUSED = new RawContextKey('notebookEditorFocused', false); export const NOTEBOOK_CELL_LIST_FOCUSED = new RawContextKey('notebookCellListFocused', false); export const NOTEBOOK_OUTPUT_FOCUSED = new RawContextKey('notebookOutputFocused', false); -export const NOTEBOOK_OUPTUT_INPUT_FOCUSED = new RawContextKey('notebookOutputInputFocused', false); +export const NOTEBOOK_OUTPUT_INPUT_FOCUSED = new RawContextKey('notebookOutputInputFocused', false); export const NOTEBOOK_EDITOR_EDITABLE = new RawContextKey('notebookEditable', true); export const NOTEBOOK_HAS_RUNNING_CELL = new RawContextKey('notebookHasRunningCell', false); export const NOTEBOOK_HAS_SOMETHING_RUNNING = new RawContextKey('notebookHasSomethingRunning', false);