diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts index bb3370a4fe9..340ea034325 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts @@ -596,6 +596,7 @@ var requirejs = (function() { const latestCell = this.notebookEditor.getCellByInfo(resolvedResult.cellInfo); if (latestCell) { latestCell.outputIsFocused = true; + this.notebookEditor.focusNotebookCell(latestCell, 'container', { skipReveal: true }); } } break; 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 c2b11f3160a..604e807356d 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts @@ -82,6 +82,16 @@ async function webviewPreloads(ctx: PreloadContext) { return; } + for (const node of event.composedPath()) { + if (node instanceof HTMLElement && node.classList.contains('output')) { + // output + postNotebookMessage('outputFocus', { + id: node.id, + }); + break; + } + } + for (const node of event.composedPath()) { if (node instanceof HTMLAnchorElement && node.href) { if (node.href.startsWith('blob:')) { @@ -628,64 +638,6 @@ async function webviewPreloads(ctx: PreloadContext) { } } - class OutputFocusTracker { - private _outputId: string; - private _hasFocus: boolean = false; - private _loosingFocus: boolean = false; - private _element: HTMLElement | Window; - constructor(element: HTMLElement | Window, outputId: string) { - this._element = element; - this._outputId = outputId; - this._hasFocus = isAncestor(document.activeElement, element); - this._loosingFocus = false; - - element.addEventListener('focus', this._onFocus.bind(this), true); - element.addEventListener('blur', this._onBlur.bind(this), true); - } - - private _onFocus() { - this._loosingFocus = false; - if (!this._hasFocus) { - this._hasFocus = true; - postNotebookMessage('outputFocus', { - id: this._outputId, - }); - } - } - - private _onBlur() { - if (this._hasFocus) { - this._loosingFocus = true; - window.setTimeout(() => { - if (this._loosingFocus) { - this._loosingFocus = false; - this._hasFocus = false; - postNotebookMessage('outputBlur', { - id: this._outputId, - }); - } - }, 0); - } - } - - dispose() { - if (this._element) { - this._element.removeEventListener('focus', this._onFocus, true); - this._element.removeEventListener('blur', this._onBlur, true); - } - } - } - - const outputFocusTrackers = new Map(); - - function addOutputFocusTracker(element: HTMLElement, outputId: string): void { - if (outputFocusTrackers.has(outputId)) { - outputFocusTrackers.get(outputId)?.dispose(); - } - - outputFocusTrackers.set(outputId, new OutputFocusTracker(element, outputId)); - } - function createEmitter(listenerChange: (listeners: Set>) => void = () => undefined): EmitterLike { const listeners = new Set>(); return { @@ -1123,11 +1075,6 @@ async function webviewPreloads(ctx: PreloadContext) { renderers.clearAll(); viewModel.clearAll(); document.getElementById('container')!.innerText = ''; - - outputFocusTrackers.forEach(ft => { - ft.dispose(); - }); - outputFocusTrackers.clear(); break; case 'clearOutput': { @@ -1993,7 +1940,6 @@ async function webviewPreloads(ctx: PreloadContext) { this.element.style.padding = '0px'; addMouseoverListeners(this.element, outputId); - addOutputFocusTracker(this.element, outputId); }