Skip to content

Commit

Permalink
cleanup editor delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Feb 21, 2021
1 parent f7b7f94 commit 8da2cec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/vs/workbench/contrib/files/browser/explorerViewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class ExplorerViewPaneContainer extends ViewPaneContainer {
// without causing the animation in the opened editors view to kick in and change scroll position.
// We try to be smart and only use the delay if we recognize that the user action is likely to cause
// a new entry in the opened editors view.
const delegatingEditorService = this.instantiationService.createInstance(DelegatingEditorService, async (delegate, group, editor, options): Promise<IEditorPane | null> => {
const delegatingEditorService = this.instantiationService.createInstance(DelegatingEditorService, async (group, delegate): Promise<IEditorPane | undefined> => {
let openEditorsView = this.getOpenEditorsView();
if (openEditorsView) {
let delay = 0;
Expand All @@ -221,9 +221,9 @@ export class ExplorerViewPaneContainer extends ViewPaneContainer {
}

try {
return await delegate(group, editor, options);
return await delegate();
} catch (error) {
return null; // ignore
return undefined; // ignore
} finally {
if (openEditorsView) {
openEditorsView.setStructuralRefreshDelay(0);
Expand Down
24 changes: 3 additions & 21 deletions src/vs/workbench/services/editor/browser/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1418,11 +1418,9 @@ export class EditorService extends Disposable implements EditorServiceImpl {

export interface IEditorOpenHandler {
(
delegate: (group: IEditorGroup, editor: IEditorInput, options?: IEditorOptions) => Promise<IEditorPane | null>,
group: IEditorGroup,
editor: IEditorInput,
options?: IEditorOptions | ITextEditorOptions
): Promise<IEditorPane | null>;
delegate: () => Promise<IEditorPane | undefined>,
): Promise<IEditorPane | undefined>;
}

/**
Expand All @@ -1447,23 +1445,7 @@ export class DelegatingEditorService implements IEditorService {
if (result) {
const [resolvedGroup, resolvedEditor, resolvedOptions] = result;

// If the override option is provided we want to open that specific editor or show a picker
if (resolvedOptions && (resolvedOptions.override === EditorOverride.PICK || typeof resolvedOptions.override === 'string')) {
return await this.editorService.openEditor(resolvedEditor, { ...resolvedOptions, override: withNullAsUndefined(resolvedOptions.override) }, resolvedGroup);
}
// Pass on to editor open handler
const editorPane = await this.editorOpenHandler(
(group: IEditorGroup, editor: IEditorInput, options?: IEditorOptions) => group.openEditor(editor, options),
resolvedGroup,
resolvedEditor,
resolvedOptions
);

if (editorPane) {
return editorPane; // the opening was handled, so return early
}

return withNullAsUndefined(await resolvedGroup.openEditor(resolvedEditor, resolvedOptions));
return this.editorOpenHandler(resolvedGroup, () => this.editorService.openEditor(resolvedEditor, resolvedOptions, resolvedGroup));
}

return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ suite('EditorService', () => {
const ed = instantiationService.createInstance(MyEditor, 'my.editor');

const inp = instantiationService.createInstance(ResourceEditorInput, URI.parse('my://resource-delegate'), 'name', 'description', undefined);
const delegate = instantiationService.createInstance(DelegatingEditorService, async (delegate, group, input) => {
assert.strictEqual(input, inp);
const delegate = instantiationService.createInstance(DelegatingEditorService, async (group, delegate) => {
assert.ok(group);

done();

Expand Down

0 comments on commit 8da2cec

Please sign in to comment.