Skip to content

Commit 5f0b0b9

Browse files
author
Benjamin Pasero
committed
uris - do not rely on isLinux check for comparing mementos
1 parent 5ae8f93 commit 5f0b0b9

7 files changed

Lines changed: 21 additions & 15 deletions

File tree

src/vs/base/common/extpath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export function isRootOrDriveLetter(path: string): boolean {
285285
return pathNormalized === posix.sep;
286286
}
287287

288-
export function indexOfPath(path: string, candidate: string, ignoreCase: boolean): number {
288+
export function indexOfPath(path: string, candidate: string, ignoreCase?: boolean): number {
289289
if (candidate.length > path.length) {
290290
return -1;
291291
}

src/vs/workbench/browser/parts/editor/baseEditor.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import { Event } from 'vs/base/common/event';
1616
import { isEmptyObject } from 'vs/base/common/types';
1717
import { DEFAULT_EDITOR_MIN_DIMENSIONS, DEFAULT_EDITOR_MAX_DIMENSIONS } from 'vs/workbench/browser/parts/editor/editor';
1818
import { MementoObject } from 'vs/workbench/common/memento';
19-
import { isEqualOrParent, joinPath } from 'vs/base/common/resources';
20-
import { isLinux } from 'vs/base/common/platform';
19+
import { joinPath, IExtUri } from 'vs/base/common/resources';
2120
import { indexOfPath } from 'vs/base/common/extpath';
2221
import { IDisposable } from 'vs/base/common/lifecycle';
2322

@@ -259,7 +258,7 @@ export class EditorMemento<T> implements IEditorMemento<T> {
259258
}
260259
}
261260

262-
moveEditorState(source: URI, target: URI): void {
261+
moveEditorState(source: URI, target: URI, comparer: IExtUri): void {
263262
const cache = this.doLoad();
264263

265264
// We need a copy of the keys to not iterate over
@@ -268,7 +267,7 @@ export class EditorMemento<T> implements IEditorMemento<T> {
268267
for (const cacheKey of cacheKeys) {
269268
const resource = URI.parse(cacheKey);
270269

271-
if (!isEqualOrParent(resource, source)) {
270+
if (!comparer.isEqualOrParent(resource, source)) {
272271
continue; // not matching our resource
273272
}
274273

@@ -277,7 +276,7 @@ export class EditorMemento<T> implements IEditorMemento<T> {
277276
if (source.toString() === resource.toString()) {
278277
targetResource = target; // file got moved
279278
} else {
280-
const index = indexOfPath(resource.path, source.path, !isLinux);
279+
const index = indexOfPath(resource.path, source.path);
281280
targetResource = joinPath(target, resource.path.substr(index + source.path.length + 1)); // parent folder got moved
282281
}
283282

src/vs/workbench/browser/parts/editor/textEditor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/editor
2424
import { CancellationToken } from 'vs/base/common/cancellation';
2525
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2626
import { computeEditorAriaLabel } from 'vs/workbench/browser/parts/editor/editor';
27+
import { IExtUri } from 'vs/base/common/resources';
2728

2829
export interface IEditorConfiguration {
2930
editor: object;
@@ -250,8 +251,8 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditorPa
250251
return this.group ? this.editorMemento.loadEditorState(this.group, resource) : undefined;
251252
}
252253

253-
protected moveTextEditorViewState(source: URI, target: URI): void {
254-
return this.editorMemento.moveEditorState(source, target);
254+
protected moveTextEditorViewState(source: URI, target: URI, comparer: IExtUri): void {
255+
return this.editorMemento.moveEditorState(source, target, comparer);
255256
}
256257

257258
protected clearTextEditorViewState(resources: URI[], group?: IEditorGroup): void {

src/vs/workbench/common/editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { IPathData } from 'vs/platform/windows/common/windows';
2222
import { coalesce, firstOrDefault } from 'vs/base/common/arrays';
2323
import { IResourceEditorInputType } from 'vs/workbench/services/editor/common/editorService';
2424
import { IRange } from 'vs/editor/common/core/range';
25+
import { IExtUri } from 'vs/base/common/resources';
2526

2627
export const DirtyWorkingCopiesContext = new RawContextKey<boolean>('dirtyWorkingCopies', false);
2728
export const ActiveEditorContext = new RawContextKey<string | null>('activeEditor', null);
@@ -1269,7 +1270,7 @@ export interface IEditorMemento<T> {
12691270
clearEditorState(resource: URI, group?: IEditorGroup): void;
12701271
clearEditorState(editor: EditorInput, group?: IEditorGroup): void;
12711272

1272-
moveEditorState(source: URI, target: URI): void;
1273+
moveEditorState(source: URI, target: URI, comparer: IExtUri): void;
12731274
}
12741275

12751276
class EditorInputFactoryRegistry implements IEditorInputFactoryRegistry {

src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { createErrorWithActions } from 'vs/base/common/errorsWithActions';
3232
import { MutableDisposable } from 'vs/base/common/lifecycle';
3333
import { EditorActivation, IEditorOptions } from 'vs/platform/editor/common/editor';
3434
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
35+
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
3536

3637
/**
3738
* An implementation of editor for file system resources.
@@ -56,7 +57,8 @@ export class TextFileEditor extends BaseTextEditor {
5657
@IEditorGroupsService editorGroupService: IEditorGroupsService,
5758
@ITextFileService private readonly textFileService: ITextFileService,
5859
@IExplorerService private readonly explorerService: IExplorerService,
59-
@IConfigurationService private readonly configurationService: IConfigurationService
60+
@IConfigurationService private readonly configurationService: IConfigurationService,
61+
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService
6062
) {
6163
super(TextFileEditor.ID, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorService, editorGroupService);
6264

@@ -78,7 +80,7 @@ export class TextFileEditor extends BaseTextEditor {
7880

7981
private onDidRunOperation(e: FileOperationEvent): void {
8082
if (e.operation === FileOperation.MOVE && e.target) {
81-
this.moveTextEditorViewState(e.resource, e.target.resource);
83+
this.moveTextEditorViewState(e.resource, e.target.resource, this.uriIdentityService.extUri);
8284
}
8385
}
8486

src/vs/workbench/contrib/files/electron-sandbox/textFileEditor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { IPreferencesService } from 'vs/workbench/services/preferences/common/pr
2424
import { IExplorerService } from 'vs/workbench/contrib/files/common/files';
2525
import { IElectronService } from 'vs/platform/electron/electron-sandbox/electron';
2626
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
27+
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
2728

2829
/**
2930
* An implementation of editor for file system resources.
@@ -45,9 +46,10 @@ export class NativeTextFileEditor extends TextFileEditor {
4546
@IElectronService private readonly electronService: IElectronService,
4647
@IPreferencesService private readonly preferencesService: IPreferencesService,
4748
@IExplorerService explorerService: IExplorerService,
48-
@IConfigurationService configurationService: IConfigurationService
49+
@IConfigurationService configurationService: IConfigurationService,
50+
@IUriIdentityService uriIdentityService: IUriIdentityService
4951
) {
50-
super(telemetryService, fileService, viewletService, instantiationService, contextService, storageService, textResourceConfigurationService, editorService, themeService, editorGroupService, textFileService, explorerService, configurationService);
52+
super(telemetryService, fileService, viewletService, instantiationService, contextService, storageService, textResourceConfigurationService, editorService, themeService, editorGroupService, textFileService, explorerService, configurationService, uriIdentityService);
5153
}
5254

5355
protected handleSetInputError(error: Error, input: FileEditorInput, options: EditorOptions | undefined): void {

src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
2020
import { IEditorModel } from 'vs/platform/editor/common/editor';
2121
import { dispose } from 'vs/base/common/lifecycle';
2222
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
23+
import { extUri } from 'vs/base/common/resources';
2324

2425
const NullThemeService = new TestThemeService();
2526

@@ -266,15 +267,15 @@ suite('Workbench base editor', () => {
266267
memento.saveEditorState(testGroup0, URI.file('/some/folder/file-2.txt'), { line: 2 });
267268
memento.saveEditorState(testGroup0, URI.file('/some/other/file.txt'), { line: 3 });
268269

269-
memento.moveEditorState(URI.file('/some/folder/file-1.txt'), URI.file('/some/folder/file-moved.txt'));
270+
memento.moveEditorState(URI.file('/some/folder/file-1.txt'), URI.file('/some/folder/file-moved.txt'), extUri);
270271

271272
let res = memento.loadEditorState(testGroup0, URI.file('/some/folder/file-1.txt'));
272273
assert.ok(!res);
273274

274275
res = memento.loadEditorState(testGroup0, URI.file('/some/folder/file-moved.txt'));
275276
assert.equal(res?.line, 1);
276277

277-
memento.moveEditorState(URI.file('/some/folder'), URI.file('/some/folder-moved'));
278+
memento.moveEditorState(URI.file('/some/folder'), URI.file('/some/folder-moved'), extUri);
278279

279280
res = memento.loadEditorState(testGroup0, URI.file('/some/folder-moved/file-moved.txt'));
280281
assert.equal(res?.line, 1);

0 commit comments

Comments
 (0)