Revert "Revert "On file rename, use default custom editor if possible instead of always prompting""

This reverts commit c817576cd0.
This commit is contained in:
Matt Bierner 2020-03-30 16:28:19 -07:00
parent 17e140249f
commit fc77b27e46
2 changed files with 39 additions and 34 deletions

View file

@ -177,31 +177,30 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
}
move(group: GroupIdentifier, newResource: URI): { editor: IEditorInput } | undefined {
// See if we can keep using the same custom editor provider
const editorInfo = this.customEditorService.getCustomEditor(this.viewType);
if (editorInfo?.matches(newResource)) {
// We can keep using the same custom editor provider
if (!this._moveHandler) {
return {
editor: this.customEditorService.createInput(newResource, this.viewType, group),
};
}
this._moveHandler(newResource);
const newEditor = this.instantiationService.createInstance(CustomEditorInput,
newResource,
this.viewType,
this.id,
new Lazy(() => undefined!), // this webview is replaced in the transfer call
this._fromBackup,
);
this.transfer(newEditor);
newEditor.updateGroup(group);
return { editor: newEditor };
} else {
// const possible = this.customEditorService.getContributedCustomEditors(newResource);
return { editor: this.editorService.createEditorInput({ resource: newResource, forceFile: true }) };
return { editor: this.doMove(group, newResource) };
}
return { editor: this.editorService.createEditorInput({ resource: newResource, forceFile: true }) };
}
private doMove(group: GroupIdentifier, newResource: URI): IEditorInput {
if (!this._moveHandler) {
return this.customEditorService.createInput(newResource, this.viewType, group);
}
this._moveHandler(newResource);
const newEditor = this.instantiationService.createInstance(CustomEditorInput,
newResource,
this.viewType,
this.id,
new Lazy(() => undefined!),
this._fromBackup); // this webview is replaced in the transfer call
this.transfer(newEditor);
newEditor.updateGroup(group);
return newEditor;
}
public undo(): void {

View file

@ -330,10 +330,10 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
return;
}
// See if the new resource can be opened in a custom editor
if (!this.getAllCustomEditors(newResource).allEditors
.some(editor => editor.priority !== CustomEditorPriority.option)
) {
const possibleEditors = this.getAllCustomEditors(newResource);
// See if we have any non-optional custom editor for this resource
if (!possibleEditors.allEditors.some(editor => editor.priority !== CustomEditorPriority.option)) {
return;
}
@ -359,19 +359,25 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
return;
}
// If there is, show a single prompt for all editors to see if the user wants to re-open them
//
// TODO: instead of prompting eagerly, it'd likly be better to replace all the editors with
// ones that would prompt when they first become visible
await new Promise(resolve => setTimeout(resolve, 50));
const pickedViewType = await this.showOpenWithPrompt(newResource);
if (!pickedViewType) {
let viewType: string | undefined;
if (possibleEditors.defaultEditor) {
viewType = possibleEditors.defaultEditor.id;
} else {
// If there is, show a single prompt for all editors to see if the user wants to re-open them
//
// TODO: instead of prompting eagerly, it'd likly be better to replace all the editors with
// ones that would prompt when they first become visible
await new Promise(resolve => setTimeout(resolve, 50));
viewType = await this.showOpenWithPrompt(newResource);
}
if (!viewType) {
return;
}
for (const [group, entries] of editorsToReplace) {
this.editorService.replaceEditors(entries.map(editor => {
const replacement = this.createInput(newResource, pickedViewType, group);
const replacement = this.createInput(newResource, viewType!, group);
return {
editor,
replacement,