mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-09 09:24:12 -05:00
files.indexOf() 💄
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user