提交 4493125a 编写于 作者: M Matt Bierner

Working on handling custom editor move

Delegate to custom editor input on move. Eventually this will be hooked up to go back to extensions
上级 cd620d7e
......@@ -10,7 +10,6 @@ import { basename } from 'vs/base/common/path';
import { isEqual } from 'vs/base/common/resources';
import { assertIsDefined } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { generateUuid } from 'vs/base/common/uuid';
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -139,7 +138,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
return undefined;
}
return this.handleMove(groupId, target) || this.editorService.createEditorInput({ resource: target, forceFile: true });
return this.tryMoveWebview(groupId, target) || this.editorService.createEditorInput({ resource: target, forceFile: true });
}
public async revert(group: GroupIdentifier, options?: IRevertOptions): Promise<void> {
......@@ -161,14 +160,22 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
return null;
}
public handleMove(groupId: GroupIdentifier, uri: URI, options?: ITextEditorOptions): IEditorInput | undefined {
move(group: GroupIdentifier, newResource: URI): { editor: IEditorInput } | undefined {
const newEditor = this.tryMoveWebview(group, newResource);
if (!newEditor) {
return;
}
return { editor: newEditor };
}
private tryMoveWebview(groupId: GroupIdentifier, uri: URI, options?: ITextEditorOptions): IEditorInput | undefined {
const editorInfo = this.customEditorService.getCustomEditor(this.viewType);
if (editorInfo?.matches(uri)) {
const webview = assertIsDefined(this.takeOwnershipOfWebview());
const newInput = this.instantiationService.createInstance(CustomEditorInput,
uri,
this.viewType,
generateUuid(),
this.id,
new Lazy(() => webview));
newInput.updateGroup(groupId);
return newInput;
......@@ -176,6 +183,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
return undefined;
}
public undo(): void {
assertIsDefined(this._modelRef);
this.undoRedoService.undo(this.resource);
......
......@@ -317,12 +317,18 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
continue;
}
if (!isEqual(editor.resource, oldResource)) {
continue;
}
const editorInfo = this._editorInfoStore.get(editor.viewType);
if (!editorInfo?.matches(newResource)) {
continue;
}
const replacement = this.createInput(newResource, editor.viewType, group);
const moveResult = editor.move(group.id, newResource);
const replacement = moveResult ? moveResult.editor : this.createInput(newResource, editor.viewType, group);
this.editorService.replaceEditors([{
editor: editor,
replacement: replacement,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册