mirror of
https://github.com/Microsoft/vscode
synced 2024-08-26 20:39:37 +00:00
fix #142239.
This commit is contained in:
parent
f5b418e3e9
commit
f71d4b6a02
|
@ -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;
|
||||
|
|
|
@ -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<webviewMessages.IOutputFocusMessage>('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, <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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue