Revert "fix #142239."

This reverts commit f71d4b6a02.
This commit is contained in:
Rob Lourens 2022-02-17 20:21:04 -08:00
parent 1d618b2df1
commit 821cd165e9
2 changed files with 64 additions and 11 deletions

View file

@ -605,7 +605,6 @@ var requirejs = (function() {
const latestCell = this.notebookEditor.getCellByInfo(resolvedResult.cellInfo);
if (latestCell) {
latestCell.outputIsFocused = true;
this.notebookEditor.focusNotebookCell(latestCell, 'container', { skipReveal: true });
}
}
break;

View file

@ -88,16 +88,6 @@ async function webviewPreloads(ctx: PreloadContext) {
return;
}
for (const node of event.composedPath()) {
if (node instanceof HTMLElement && node.classList.contains('output')) {
// output
postNotebookMessage<webviewMessages.IOutputFocusMessage>('outputFocus', {
id: node.id,
});
break;
}
}
for (const node of event.composedPath()) {
if (node instanceof HTMLAnchorElement && node.href) {
if (node.href.startsWith('blob:')) {
@ -634,6 +624,64 @@ 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, <HTMLElement>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<webviewMessages.IOutputFocusMessage>('outputFocus', {
id: this._outputId,
});
}
}
private _onBlur() {
if (this._hasFocus) {
this._loosingFocus = true;
window.setTimeout(() => {
if (this._loosingFocus) {
this._loosingFocus = false;
this._hasFocus = false;
postNotebookMessage<webviewMessages.IOutputBlurMessage>('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<string, OutputFocusTracker>();
function addOutputFocusTracker(element: HTMLElement, outputId: string): void {
if (outputFocusTrackers.has(outputId)) {
outputFocusTrackers.get(outputId)?.dispose();
}
outputFocusTrackers.set(outputId, new OutputFocusTracker(element, outputId));
}
function createEmitter<T>(listenerChange: (listeners: Set<Listener<T>>) => void = () => undefined): EmitterLike<T> {
const listeners = new Set<Listener<T>>();
return {
@ -1062,6 +1110,11 @@ async function webviewPreloads(ctx: PreloadContext) {
renderers.clearAll();
viewModel.clearAll();
document.getElementById('container')!.innerText = '';
outputFocusTrackers.forEach(ft => {
ft.dispose();
});
outputFocusTrackers.clear();
break;
case 'clearOutput': {
@ -1951,6 +2004,7 @@ async function webviewPreloads(ctx: PreloadContext) {
this.element.style.padding = '0px';
addMouseoverListeners(this.element, outputId);
addOutputFocusTracker(this.element, outputId);
}