Skip to content

Commit 8e2905a

Browse files
committed
Outline cannot follow correct side in split editor case (fix microsoft#134008)
1 parent cb48ce5 commit 8e2905a

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

src/vs/workbench/contrib/outline/browser/outlinePane.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export class OutlinePane extends ViewPane {
6666

6767
private readonly _disposables = new DisposableStore();
6868

69-
private readonly _editorDisposables = new DisposableStore();
69+
private readonly _editorControlDisposables = new DisposableStore();
70+
private readonly _editorPaneDisposables = new DisposableStore();
7071
private readonly _outlineViewState = new OutlineViewState();
7172

7273
private readonly _editorListener = new MutableDisposable();
@@ -120,7 +121,8 @@ export class OutlinePane extends ViewPane {
120121

121122
override dispose(): void {
122123
this._disposables.dispose();
123-
this._editorDisposables.dispose();
124+
this._editorPaneDisposables.dispose();
125+
this._editorControlDisposables.dispose();
124126
this._editorListener.dispose();
125127
super.dispose();
126128
}
@@ -148,7 +150,8 @@ export class OutlinePane extends ViewPane {
148150
if (!visible) {
149151
// stop everything when not visible
150152
this._editorListener.clear();
151-
this._editorDisposables.clear();
153+
this._editorPaneDisposables.clear();
154+
this._editorControlDisposables.clear();
152155

153156
} else if (!this._editorListener.value) {
154157
const event = Event.any(this._editorService.onDidActiveEditorChange, this._outlineService.onDidChange);
@@ -189,13 +192,26 @@ export class OutlinePane extends ViewPane {
189192
return false;
190193
}
191194

192-
private async _handleEditorChanged(pane: IEditorPane | undefined): Promise<void> {
195+
private _handleEditorChanged(pane: IEditorPane | undefined): void {
196+
this._editorPaneDisposables.clear();
197+
198+
if (pane) {
199+
// react to control changes from within pane (https://github.com/microsoft/vscode/issues/134008)
200+
this._editorPaneDisposables.add(pane.onDidChangeControl(() => {
201+
this._handleEditorControlChanged(pane);
202+
}));
203+
}
204+
205+
this._handleEditorControlChanged(pane);
206+
}
207+
208+
private async _handleEditorControlChanged(pane: IEditorPane | undefined): Promise<void> {
193209

194210
// persist state
195211
const resource = EditorResourceAccessor.getOriginalUri(pane?.input);
196212
const didCapture = this._captureViewState(resource);
197213

198-
this._editorDisposables.clear();
214+
this._editorControlDisposables.clear();
199215

200216
if (!pane || !this._outlineService.canCreateOutline(pane) || !resource) {
201217
return this._showMessage(localize('no-editor', "The active editor cannot provide outline information."));
@@ -211,7 +227,7 @@ export class OutlinePane extends ViewPane {
211227
this._progressBar.infinite().show(500);
212228

213229
const cts = new CancellationTokenSource();
214-
this._editorDisposables.add(toDisposable(() => cts.dispose(true)));
230+
this._editorControlDisposables.add(toDisposable(() => cts.dispose(true)));
215231

216232
const newOutline = await this._outlineService.createOutline(pane, OutlineTarget.OutlinePane, cts.token);
217233
loadingMessage?.dispose();
@@ -225,7 +241,7 @@ export class OutlinePane extends ViewPane {
225241
return;
226242
}
227243

228-
this._editorDisposables.add(newOutline);
244+
this._editorControlDisposables.add(newOutline);
229245
this._progressBar.stop().hide();
230246

231247
const sorter = new OutlineTreeSorter(newOutline.config.comparator, this._outlineViewState.sortBy);
@@ -270,21 +286,21 @@ export class OutlinePane extends ViewPane {
270286
}
271287
};
272288
updateTree();
273-
this._editorDisposables.add(newOutline.onDidChange(updateTree));
289+
this._editorControlDisposables.add(newOutline.onDidChange(updateTree));
274290

275291
// feature: apply panel background to tree
276-
this._editorDisposables.add(this.viewDescriptorService.onDidChangeLocation(({ views }) => {
292+
this._editorControlDisposables.add(this.viewDescriptorService.onDidChangeLocation(({ views }) => {
277293
if (views.some(v => v.id === this.id)) {
278294
tree.updateOptions({ overrideStyles: { listBackground: this.getBackgroundColor() } });
279295
}
280296
}));
281297

282298
// feature: filter on type - keep tree and menu in sync
283-
this._editorDisposables.add(tree.onDidUpdateOptions(e => this._outlineViewState.filterOnType = Boolean(e.filterOnType)));
299+
this._editorControlDisposables.add(tree.onDidUpdateOptions(e => this._outlineViewState.filterOnType = Boolean(e.filterOnType)));
284300

285301
// feature: reveal outline selection in editor
286302
// on change -> reveal/select defining range
287-
this._editorDisposables.add(tree.onDidOpen(e => newOutline.reveal(e.element, e.editorOptions, e.sideBySide)));
303+
this._editorControlDisposables.add(tree.onDidOpen(e => newOutline.reveal(e.element, e.editorOptions, e.sideBySide)));
288304
// feature: reveal editor selection in outline
289305
const revealActiveElement = () => {
290306
if (!this._outlineViewState.followCursor || !newOutline.activeElement) {
@@ -307,10 +323,10 @@ export class OutlinePane extends ViewPane {
307323
}
308324
};
309325
revealActiveElement();
310-
this._editorDisposables.add(newOutline.onDidChange(revealActiveElement));
326+
this._editorControlDisposables.add(newOutline.onDidChange(revealActiveElement));
311327

312328
// feature: update view when user state changes
313-
this._editorDisposables.add(this._outlineViewState.onDidChange((e: { followCursor?: boolean, sortBy?: boolean, filterOnType?: boolean }) => {
329+
this._editorControlDisposables.add(this._outlineViewState.onDidChange((e: { followCursor?: boolean, sortBy?: boolean, filterOnType?: boolean }) => {
314330
this._outlineViewState.persist(this._storageService);
315331
if (e.filterOnType) {
316332
tree.updateOptions({ filterOnType: this._outlineViewState.filterOnType });
@@ -326,7 +342,7 @@ export class OutlinePane extends ViewPane {
326342

327343
// feature: expand all nodes when filtering (not when finding)
328344
let viewState: IDataTreeViewState | undefined;
329-
this._editorDisposables.add(tree.onDidChangeTypeFilterPattern(pattern => {
345+
this._editorControlDisposables.add(tree.onDidChangeTypeFilterPattern(pattern => {
330346
if (!tree.options.filterOnType) {
331347
return;
332348
}
@@ -342,7 +358,7 @@ export class OutlinePane extends ViewPane {
342358
// last: set tree property
343359
tree.layout(this._treeDimensions?.height, this._treeDimensions?.width);
344360
this._tree = tree;
345-
this._editorDisposables.add(toDisposable(() => {
361+
this._editorControlDisposables.add(toDisposable(() => {
346362
tree.dispose();
347363
this._tree = undefined;
348364
}));

0 commit comments

Comments
 (0)