提交 8010415c 编写于 作者: I isidor

paths: fix dirname for paths that end in slash. Explorer model fix find for...

paths: fix dirname for paths that end in slash. Explorer model fix find for paths ending with extra slashes

fixes microsoft/vscode-cascade#57
上级 2ed98bf4
......@@ -27,6 +27,8 @@ export function dirname(path: string): string {
return '.';
} else if (~idx === 0) {
return path[0];
} else if (~idx === path.length - 1) {
return dirname(path.substring(0, path.length - 1));
} else {
let res = path.substring(0, ~idx);
if (isWindows && res[res.length - 1] === ':') {
......@@ -395,4 +397,4 @@ export function isAbsolute_win32(path: string): boolean {
export function isAbsolute_posix(path: string): boolean {
return path && path.charCodeAt(0) === CharCode.Slash;
}
\ No newline at end of file
}
......@@ -20,6 +20,7 @@ suite('Paths', () => {
assert.equal(paths.dirname('/'), '/');
assert.equal(paths.dirname('\\'), '\\');
assert.equal(paths.dirname('foo'), '.');
assert.equal(paths.dirname('/folder/'), '/');
if (platform.isWindows) {
assert.equal(paths.dirname('c:\\some\\file.txt'), 'c:\\some');
assert.equal(paths.dirname('c:\\some'), 'c:\\');
......@@ -226,4 +227,4 @@ suite('Paths', () => {
assert.ok(!paths.isAbsolute_posix(nonAbsolutePath), nonAbsolutePath);
});
});
});
\ No newline at end of file
});
......@@ -17,7 +17,7 @@ import { IEditorGroup, toResource, IEditorIdentifier } from 'vs/workbench/common
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { getPathLabel } from 'vs/base/common/labels';
import { Schemas } from 'vs/base/common/network';
import { startsWith, startsWithIgnoreCase, equalsIgnoreCase } from 'vs/base/common/strings';
import { startsWith, startsWithIgnoreCase, equalsIgnoreCase, rtrim } from 'vs/base/common/strings';
export class Model {
......@@ -345,10 +345,7 @@ export class ExplorerItem {
}
private findByPath(path: string, index: number): ExplorerItem {
if (this.resource.path === path) {
return this;
}
if (!isLinux && equalsIgnoreCase(this.resource.path, path)) {
if (paths.isEqual(rtrim(this.resource.path, paths.sep), rtrim(path, paths.sep), !isLinux)) {
return this;
}
......
......@@ -156,6 +156,7 @@ suite('Files - View Model', () => {
assert.strictEqual(s1.find(toResource('foobar')), null);
assert.strictEqual(s1.find(toResource('/')), s1);
assert.strictEqual(s1.find(toResource('')), s1);
});
test('Find with mixed case', function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册