Skip to content

Commit

Permalink
reveal selection before attachment
Browse files Browse the repository at this point in the history
This commit ensures that if a selection is passed to the editor-manager
when an editor is created, the selection is revealed before the widget
is attached.

Signed-off-by: Colin Grant <[email protected]>
  • Loading branch information
colin-grant-work committed Mar 3, 2021
1 parent 308a6f7 commit 997074c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/editor/src/browser/editor-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ export class EditorManager extends NavigatableWidgetOpenHandler<EditorWidget> {
this.updateCurrentEditor();
}

async getByUri(uri: URI, options?: EditorOpenerOptions): Promise<EditorWidget | undefined> {
const widget = await super.getByUri(uri);
if (widget) {
// Reveal selection before attachment to manage nav stack. (https://github.com/eclipse-theia/theia/issues/8955)
this.revealSelection(widget, options, uri);
}
return widget;
}

async getOrCreateByUri(uri: URI, options?: EditorOpenerOptions): Promise<EditorWidget> {
const widget = await super.getOrCreateByUri(uri);
if (widget) {
// Reveal selection before attachment to manage nav stack. (https://github.com/eclipse-theia/theia/issues/8955)
this.revealSelection(widget, options, uri);
}
return widget;
}

protected readonly recentlyVisibleIds: string[] = [];
protected get recentlyVisible(): EditorWidget | undefined {
const id = this.recentlyVisibleIds[0];
Expand Down Expand Up @@ -137,8 +155,8 @@ export class EditorManager extends NavigatableWidgetOpenHandler<EditorWidget> {
}

async open(uri: URI, options?: EditorOpenerOptions): Promise<EditorWidget> {
const editor = await super.open(uri, options);
this.revealSelection(editor, options, uri);
const editor = await this.getOrCreateByUri(uri, options);
await super.open(uri, options);
return editor;
}

Expand Down

0 comments on commit 997074c

Please sign in to comment.