提交 fcff9f97 编写于 作者: B Benjamin Pasero

files.indexOf() 💄

上级 12e07d54
......@@ -362,7 +362,7 @@ export function isEqualOrParent(path: string, candidate: string, ignoreCase?: bo
return path.indexOf(candidate) === 0;
}
export function indexOf(path: string, candidate: string): number {
export function indexOf(path: string, candidate: string, ignoreCase?: boolean): number {
if (candidate.length > path.length) {
return -1;
}
......@@ -371,7 +371,7 @@ export function indexOf(path: string, candidate: string): number {
return 0;
}
if (!isLinux) {
if (ignoreCase) {
path = path.toLowerCase();
candidate = candidate.toLowerCase();
}
......
......@@ -188,19 +188,15 @@ suite('Files', () => {
}
});
test('indexOf', function () {
assert.equal(indexOf('/some/path', '/some/path'), 0);
assert.equal(indexOf('/some/path/more', '/some/path'), 0);
test('indexOf (ignorecase)', function () {
assert.equal(indexOf('/some/path', '/some/path', true), 0);
assert.equal(indexOf('/some/path/more', '/some/path', true), 0);
assert.equal(indexOf('c:\\some\\path', 'c:\\some\\path'), 0);
assert.equal(indexOf('c:\\some\\path\\more', 'c:\\some\\path'), 0);
assert.equal(indexOf('c:\\some\\path', 'c:\\some\\path', true), 0);
assert.equal(indexOf('c:\\some\\path\\more', 'c:\\some\\path', true), 0);
assert.equal(indexOf('/some/path', '/some/other/path'), -1);
assert.equal(indexOf('/some/path', '/some/other/path', true), -1);
if (isLinux) {
assert.equal(indexOf('/some/path', '/some/PATH'), -1);
} else {
assert.equal(indexOf('/some/path', '/some/PATH'), 0);
}
assert.equal(indexOf('/some/path', '/some/PATH', true), 0);
});
});
\ No newline at end of file
......@@ -200,7 +200,7 @@ export class FileEditorTracker implements IWorkbenchContribution {
if (oldResource.toString() === resource.toString()) {
reopenFileResource = newResource; // file got moved
} else {
const index = indexOf(resource.fsPath, oldResource.fsPath);
const index = indexOf(resource.fsPath, oldResource.fsPath, !isLinux /* ignorecase */);
reopenFileResource = URI.file(paths.join(newResource.fsPath, resource.fsPath.substr(index + oldResource.fsPath.length + 1))); // parent folder got moved
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册