diff --git a/src/vs/base/common/extpath.ts b/src/vs/base/common/extpath.ts index 8fe9f9e1c2a73bd5866b70054652fe62392c7037..d6e7d6ef5d7e97046d3643d92f0b2a675e967b08 100644 --- a/src/vs/base/common/extpath.ts +++ b/src/vs/base/common/extpath.ts @@ -285,7 +285,7 @@ export function isRootOrDriveLetter(path: string): boolean { return pathNormalized === posix.sep; } -export function indexOfPath(path: string, candidate: string, ignoreCase: boolean): number { +export function indexOfPath(path: string, candidate: string, ignoreCase?: boolean): number { if (candidate.length > path.length) { return -1; } diff --git a/src/vs/workbench/browser/parts/editor/baseEditor.ts b/src/vs/workbench/browser/parts/editor/baseEditor.ts index acbb267de087ec43ced4d6d7d5a501956ba2b41e..fac5d32a8c9fda6469b2e4582a949510b5c81850 100644 --- a/src/vs/workbench/browser/parts/editor/baseEditor.ts +++ b/src/vs/workbench/browser/parts/editor/baseEditor.ts @@ -16,8 +16,7 @@ import { Event } from 'vs/base/common/event'; import { isEmptyObject } from 'vs/base/common/types'; import { DEFAULT_EDITOR_MIN_DIMENSIONS, DEFAULT_EDITOR_MAX_DIMENSIONS } from 'vs/workbench/browser/parts/editor/editor'; import { MementoObject } from 'vs/workbench/common/memento'; -import { isEqualOrParent, joinPath } from 'vs/base/common/resources'; -import { isLinux } from 'vs/base/common/platform'; +import { joinPath, IExtUri } from 'vs/base/common/resources'; import { indexOfPath } from 'vs/base/common/extpath'; import { IDisposable } from 'vs/base/common/lifecycle'; @@ -259,7 +258,7 @@ export class EditorMemento implements IEditorMemento { } } - moveEditorState(source: URI, target: URI): void { + moveEditorState(source: URI, target: URI, comparer: IExtUri): void { const cache = this.doLoad(); // We need a copy of the keys to not iterate over @@ -268,7 +267,7 @@ export class EditorMemento implements IEditorMemento { for (const cacheKey of cacheKeys) { const resource = URI.parse(cacheKey); - if (!isEqualOrParent(resource, source)) { + if (!comparer.isEqualOrParent(resource, source)) { continue; // not matching our resource } @@ -277,7 +276,7 @@ export class EditorMemento implements IEditorMemento { if (source.toString() === resource.toString()) { targetResource = target; // file got moved } else { - const index = indexOfPath(resource.path, source.path, !isLinux); + const index = indexOfPath(resource.path, source.path); targetResource = joinPath(target, resource.path.substr(index + source.path.length + 1)); // parent folder got moved } diff --git a/src/vs/workbench/browser/parts/editor/textEditor.ts b/src/vs/workbench/browser/parts/editor/textEditor.ts index a6650603cf4aed7bb1f72a2dc66a2c9e01770554..9536c9b971e18b63944abc8811b414a4139889aa 100644 --- a/src/vs/workbench/browser/parts/editor/textEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textEditor.ts @@ -24,6 +24,7 @@ import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/editor import { CancellationToken } from 'vs/base/common/cancellation'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { computeEditorAriaLabel } from 'vs/workbench/browser/parts/editor/editor'; +import { IExtUri } from 'vs/base/common/resources'; export interface IEditorConfiguration { editor: object; @@ -250,8 +251,8 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditorPa return this.group ? this.editorMemento.loadEditorState(this.group, resource) : undefined; } - protected moveTextEditorViewState(source: URI, target: URI): void { - return this.editorMemento.moveEditorState(source, target); + protected moveTextEditorViewState(source: URI, target: URI, comparer: IExtUri): void { + return this.editorMemento.moveEditorState(source, target, comparer); } protected clearTextEditorViewState(resources: URI[], group?: IEditorGroup): void { diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 8b04c9e67998fc1e70c0fabe602d094b16c7b405..c981734c60cf223da6d4bedb0880c1d4f2df7082 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -22,6 +22,7 @@ import { IPathData } from 'vs/platform/windows/common/windows'; import { coalesce, firstOrDefault } from 'vs/base/common/arrays'; import { IResourceEditorInputType } from 'vs/workbench/services/editor/common/editorService'; import { IRange } from 'vs/editor/common/core/range'; +import { IExtUri } from 'vs/base/common/resources'; export const DirtyWorkingCopiesContext = new RawContextKey('dirtyWorkingCopies', false); export const ActiveEditorContext = new RawContextKey('activeEditor', null); @@ -1269,7 +1270,7 @@ export interface IEditorMemento { clearEditorState(resource: URI, group?: IEditorGroup): void; clearEditorState(editor: EditorInput, group?: IEditorGroup): void; - moveEditorState(source: URI, target: URI): void; + moveEditorState(source: URI, target: URI, comparer: IExtUri): void; } class EditorInputFactoryRegistry implements IEditorInputFactoryRegistry { diff --git a/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts b/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts index 91a1fc23a1d0dffdfb654ac3e328120fe4253c26..308cf920a5a10ddac3d0c148ac4f6fbb6098e298 100644 --- a/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts +++ b/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts @@ -32,6 +32,7 @@ import { createErrorWithActions } from 'vs/base/common/errorsWithActions'; import { MutableDisposable } from 'vs/base/common/lifecycle'; import { EditorActivation, IEditorOptions } from 'vs/platform/editor/common/editor'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; /** * An implementation of editor for file system resources. @@ -56,7 +57,8 @@ export class TextFileEditor extends BaseTextEditor { @IEditorGroupsService editorGroupService: IEditorGroupsService, @ITextFileService private readonly textFileService: ITextFileService, @IExplorerService private readonly explorerService: IExplorerService, - @IConfigurationService private readonly configurationService: IConfigurationService + @IConfigurationService private readonly configurationService: IConfigurationService, + @IUriIdentityService private readonly uriIdentityService: IUriIdentityService ) { super(TextFileEditor.ID, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorService, editorGroupService); @@ -78,7 +80,7 @@ export class TextFileEditor extends BaseTextEditor { private onDidRunOperation(e: FileOperationEvent): void { if (e.operation === FileOperation.MOVE && e.target) { - this.moveTextEditorViewState(e.resource, e.target.resource); + this.moveTextEditorViewState(e.resource, e.target.resource, this.uriIdentityService.extUri); } } diff --git a/src/vs/workbench/contrib/files/electron-sandbox/textFileEditor.ts b/src/vs/workbench/contrib/files/electron-sandbox/textFileEditor.ts index b5e50bd3c547214889e498cf445b3cb5b56031b0..2a08e3b26d988fcb1948f42752a77e8f4e476c0a 100644 --- a/src/vs/workbench/contrib/files/electron-sandbox/textFileEditor.ts +++ b/src/vs/workbench/contrib/files/electron-sandbox/textFileEditor.ts @@ -24,6 +24,7 @@ import { IPreferencesService } from 'vs/workbench/services/preferences/common/pr import { IExplorerService } from 'vs/workbench/contrib/files/common/files'; import { IElectronService } from 'vs/platform/electron/electron-sandbox/electron'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; /** * An implementation of editor for file system resources. @@ -45,9 +46,10 @@ export class NativeTextFileEditor extends TextFileEditor { @IElectronService private readonly electronService: IElectronService, @IPreferencesService private readonly preferencesService: IPreferencesService, @IExplorerService explorerService: IExplorerService, - @IConfigurationService configurationService: IConfigurationService + @IConfigurationService configurationService: IConfigurationService, + @IUriIdentityService uriIdentityService: IUriIdentityService ) { - super(telemetryService, fileService, viewletService, instantiationService, contextService, storageService, textResourceConfigurationService, editorService, themeService, editorGroupService, textFileService, explorerService, configurationService); + super(telemetryService, fileService, viewletService, instantiationService, contextService, storageService, textResourceConfigurationService, editorService, themeService, editorGroupService, textFileService, explorerService, configurationService, uriIdentityService); } protected handleSetInputError(error: Error, input: FileEditorInput, options: EditorOptions | undefined): void { diff --git a/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts b/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts index 635c4c865fed78df9165838553fc9e22aec37137..b8a62fd8127eaacb74735d871fc5a3b6bd83c324 100644 --- a/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts +++ b/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts @@ -20,6 +20,7 @@ import { CancellationToken } from 'vs/base/common/cancellation'; import { IEditorModel } from 'vs/platform/editor/common/editor'; import { dispose } from 'vs/base/common/lifecycle'; import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices'; +import { extUri } from 'vs/base/common/resources'; const NullThemeService = new TestThemeService(); @@ -266,7 +267,7 @@ suite('Workbench base editor', () => { memento.saveEditorState(testGroup0, URI.file('/some/folder/file-2.txt'), { line: 2 }); memento.saveEditorState(testGroup0, URI.file('/some/other/file.txt'), { line: 3 }); - memento.moveEditorState(URI.file('/some/folder/file-1.txt'), URI.file('/some/folder/file-moved.txt')); + memento.moveEditorState(URI.file('/some/folder/file-1.txt'), URI.file('/some/folder/file-moved.txt'), extUri); let res = memento.loadEditorState(testGroup0, URI.file('/some/folder/file-1.txt')); assert.ok(!res); @@ -274,7 +275,7 @@ suite('Workbench base editor', () => { res = memento.loadEditorState(testGroup0, URI.file('/some/folder/file-moved.txt')); assert.equal(res?.line, 1); - memento.moveEditorState(URI.file('/some/folder'), URI.file('/some/folder-moved')); + memento.moveEditorState(URI.file('/some/folder'), URI.file('/some/folder-moved'), extUri); res = memento.loadEditorState(testGroup0, URI.file('/some/folder-moved/file-moved.txt')); assert.equal(res?.line, 1);