提交 5f0b0b9c 编写于 作者: B Benjamin Pasero

uris - do not rely on isLinux check for comparing mementos

上级 5ae8f932
......@@ -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;
}
......
......@@ -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<T> implements IEditorMemento<T> {
}
}
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<T> implements IEditorMemento<T> {
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<T> implements IEditorMemento<T> {
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
}
......
......@@ -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 {
......
......@@ -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<boolean>('dirtyWorkingCopies', false);
export const ActiveEditorContext = new RawContextKey<string | null>('activeEditor', null);
......@@ -1269,7 +1270,7 @@ export interface IEditorMemento<T> {
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 {
......
......@@ -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);
}
}
......
......@@ -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 {
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册