Skip to content

Commit 55799e3

Browse files
committed
use focusin event
1 parent 8c4fde3 commit 55799e3

File tree

2 files changed

+5
-64
lines changed

2 files changed

+5
-64
lines changed

src/vs/workbench/contrib/notebook/browser/controller/editActions.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -126,61 +126,6 @@ registerAction2(class QuitEditCellAction extends NotebookCellAction {
126126
}
127127
});
128128

129-
registerAction2(class UnfocusCellOutput extends NotebookCellAction {
130-
constructor() {
131-
super(
132-
{
133-
id: 'notebook.cell.unfocusOutput',
134-
title: localize('notebookActions.unfocusOutput', "Stop Editing Cell"),
135-
menu: {
136-
id: MenuId.NotebookCellTitle,
137-
when: ContextKeyExpr.and(
138-
NOTEBOOK_CELL_TYPE.isEqualTo('markup'),
139-
NOTEBOOK_CELL_MARKDOWN_EDIT_MODE,
140-
NOTEBOOK_CELL_EDITABLE),
141-
order: CellToolbarOrder.SaveCell,
142-
group: CELL_TITLE_CELL_GROUP_ID
143-
},
144-
icon: icons.stopEditIcon,
145-
keybinding: [
146-
{
147-
when: ContextKeyExpr.and(quitEditCondition,
148-
EditorContextKeys.hoverVisible.toNegated(),
149-
EditorContextKeys.hasNonEmptySelection.toNegated(),
150-
EditorContextKeys.hasMultipleSelections.toNegated()),
151-
primary: KeyCode.Escape,
152-
weight: NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT - 5
153-
},
154-
{
155-
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED,
156-
NOTEBOOK_OUTPUT_FOCUSED,
157-
NOTEBOOK_OUPTUT_INPUT_FOCUSED.toNegated()),
158-
primary: KeyCode.Escape,
159-
weight: KeybindingWeight.WorkbenchContrib + 1
160-
},
161-
{
162-
when: ContextKeyExpr.and(
163-
quitEditCondition,
164-
NOTEBOOK_CELL_TYPE.isEqualTo('markup')),
165-
primary: KeyMod.WinCtrl | KeyCode.Enter,
166-
win: {
167-
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Enter
168-
},
169-
weight: NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT - 5
170-
},
171-
]
172-
});
173-
}
174-
175-
async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext) {
176-
if (context.cell.cellKind === CellKind.Markup) {
177-
context.cell.updateEditState(CellEditState.Preview, QUIT_EDIT_CELL_COMMAND_ID);
178-
}
179-
180-
await context.notebookEditor.focusNotebookCell(context.cell, 'container', { skipReveal: true });
181-
}
182-
});
183-
184129
registerAction2(class DeleteCellAction extends NotebookCellAction {
185130
constructor() {
186131
super(

src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ async function webviewPreloads(ctx: PreloadContext) {
9494
let currentRenderOptions = ctx.renderOptions;
9595
const settingChange: EmitterLike<RenderOptions> = createEmitter<RenderOptions>();
9696

97-
let isInputElementFocused: boolean | undefined = undefined;
98-
9997
const acquireVsCodeApi = globalThis.acquireVsCodeApi;
10098
const vscode = acquireVsCodeApi();
10199
delete (globalThis as any).acquireVsCodeApi;
@@ -140,19 +138,16 @@ async function webviewPreloads(ctx: PreloadContext) {
140138
};
141139

142140
// check if an input element is focused within the output element
143-
const checkOutputInputFocus = () => {
144-
141+
const handleOutputFocus = () => {
145142
const activeElement = document.activeElement;
146143
if (!activeElement) {
147144
return;
148145
}
149146

150-
isInputElementFocused = !!activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA');
151-
152-
if (isInputElementFocused) {
147+
if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') {
153148
postNotebookMessage<webviewMessages.IOutputInputFocusMessage>('outputInputFocus', { hasFocus: true });
154149

155-
activeElement.addEventListener('onblur', () => {
150+
activeElement.addEventListener('blur', () => {
156151
postNotebookMessage<webviewMessages.IOutputInputFocusMessage>('outputInputFocus', { hasFocus: false });
157152
}, { once: true });
158153
}
@@ -163,7 +158,7 @@ async function webviewPreloads(ctx: PreloadContext) {
163158
return;
164159
}
165160

166-
checkOutputInputFocus();
161+
handleOutputFocus();
167162

168163
for (const node of event.composedPath()) {
169164
if (node instanceof HTMLElement && node.classList.contains('output')) {
@@ -245,6 +240,7 @@ async function webviewPreloads(ctx: PreloadContext) {
245240
};
246241

247242
document.body.addEventListener('click', handleInnerClick);
243+
document.body.addEventListener('focusin', handleOutputFocus);
248244

249245
interface RendererContext extends rendererApi.RendererContext<unknown> {
250246
readonly onDidChangeSettings: Event<RenderOptions>;

0 commit comments

Comments
 (0)