Skip to content

Commit 1e97f34

Browse files
authored
react to diff changing and relayout inner diff (microsoft#183299)
1 parent 193c2f5 commit 1e97f34

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorLivePreviewWidget.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Dimension, h } from 'vs/base/browser/dom';
7-
import { MutableDisposable } from 'vs/base/common/lifecycle';
7+
import { DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
88
import { assertType } from 'vs/base/common/types';
99
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
1010
import { EmbeddedCodeEditorWidget, EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
@@ -38,6 +38,7 @@ export class InteractiveEditorLivePreviewWidget extends ZoneWidget {
3838

3939
private readonly _elements = h('div.interactive-editor-diff-widget@domNode');
4040

41+
private readonly _sessionStore = this._disposables.add(new DisposableStore());
4142
private readonly _diffEditor: IDiffEditor;
4243
private readonly _inlineDiffDecorations: IEditorDecorationsCollection;
4344
private _dim: Dimension | undefined;
@@ -129,6 +130,20 @@ export class InteractiveEditorLivePreviewWidget extends ZoneWidget {
129130

130131
override show(): void {
131132
assertType(this.editor.hasModel());
133+
this._sessionStore.clear();
134+
135+
this._sessionStore.add(this._diffEditor.onDidUpdateDiff(() => {
136+
const result = this._diffEditor.getDiffComputationResult();
137+
const hasFocus = this._diffEditor.hasTextFocus();
138+
this._updateFromChanges(this._session.wholeRange, result?.changes2 ?? []);
139+
// TODO@jrieken find a better fix for this. this is the challenge:
140+
// the _doShowForChanges method invokes show of the zone widget which removes and adds the
141+
// zone and overlay parts. this dettaches and reattaches the dom nodes which means they lose
142+
// focus
143+
if (hasFocus) {
144+
this._diffEditor.focus();
145+
}
146+
}));
132147
this._updateFromChanges(this._session.wholeRange, this._session.lastTextModelChanges);
133148
this._isVisible = true;
134149
}

0 commit comments

Comments
 (0)