Skip to content

Commit 9f7b100

Browse files
author
Benjamin Pasero
committed
Disambiguation tab folder hint is using wrong slash ".\" in WSL (fix microsoft#92030)
1 parent fe8729b commit 9f7b100

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

src/vs/base/common/labels.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { URI } from 'vs/base/common/uri';
7-
import { sep, posix, normalize, win32 } from 'vs/base/common/path';
7+
import { posix, normalize, win32, sep } from 'vs/base/common/path';
88
import { endsWith, startsWithIgnoreCase, rtrim, startsWith } from 'vs/base/common/strings';
99
import { Schemas } from 'vs/base/common/network';
1010
import { isLinux, isWindows, isMacintosh } from 'vs/base/common/platform';
@@ -160,7 +160,7 @@ export function untildify(path: string, userHome: string): string {
160160
const ellipsis = '\u2026';
161161
const unc = '\\\\';
162162
const home = '~';
163-
export function shorten(paths: string[]): string[] {
163+
export function shorten(paths: string[], pathSeparator: string = sep): string[] {
164164
const shortenedPaths: string[] = new Array(paths.length);
165165

166166
// for every path
@@ -169,7 +169,7 @@ export function shorten(paths: string[]): string[] {
169169
let path = paths[pathIndex];
170170

171171
if (path === '') {
172-
shortenedPaths[pathIndex] = `.${sep}`;
172+
shortenedPaths[pathIndex] = `.${pathSeparator}`;
173173
continue;
174174
}
175175

@@ -185,20 +185,20 @@ export function shorten(paths: string[]): string[] {
185185
if (path.indexOf(unc) === 0) {
186186
prefix = path.substr(0, path.indexOf(unc) + unc.length);
187187
path = path.substr(path.indexOf(unc) + unc.length);
188-
} else if (path.indexOf(sep) === 0) {
189-
prefix = path.substr(0, path.indexOf(sep) + sep.length);
190-
path = path.substr(path.indexOf(sep) + sep.length);
188+
} else if (path.indexOf(pathSeparator) === 0) {
189+
prefix = path.substr(0, path.indexOf(pathSeparator) + pathSeparator.length);
190+
path = path.substr(path.indexOf(pathSeparator) + pathSeparator.length);
191191
} else if (path.indexOf(home) === 0) {
192192
prefix = path.substr(0, path.indexOf(home) + home.length);
193193
path = path.substr(path.indexOf(home) + home.length);
194194
}
195195

196196
// pick the first shortest subpath found
197-
const segments: string[] = path.split(sep);
197+
const segments: string[] = path.split(pathSeparator);
198198
for (let subpathLength = 1; match && subpathLength <= segments.length; subpathLength++) {
199199
for (let start = segments.length - subpathLength; match && start >= 0; start--) {
200200
match = false;
201-
let subpath = segments.slice(start, start + subpathLength).join(sep);
201+
let subpath = segments.slice(start, start + subpathLength).join(pathSeparator);
202202

203203
// that is unique to any other path
204204
for (let otherPathIndex = 0; !match && otherPathIndex < paths.length; otherPathIndex++) {
@@ -209,7 +209,7 @@ export function shorten(paths: string[]): string[] {
209209

210210
// Adding separator as prefix for subpath, such that 'endsWith(src, trgt)' considers subpath as directory name instead of plain string.
211211
// prefix is not added when either subpath is root directory or path[otherPathIndex] does not have multiple directories.
212-
const subpathWithSep: string = (start > 0 && paths[otherPathIndex].indexOf(sep) > -1) ? sep + subpath : subpath;
212+
const subpathWithSep: string = (start > 0 && paths[otherPathIndex].indexOf(pathSeparator) > -1) ? pathSeparator + subpath : subpath;
213213
const isOtherPathEnding: boolean = endsWith(paths[otherPathIndex], subpathWithSep);
214214

215215
match = !isSubpathEnding || isOtherPathEnding;
@@ -226,26 +226,26 @@ export function shorten(paths: string[]): string[] {
226226
// extend subpath to include disk drive prefix
227227
start = 0;
228228
subpathLength++;
229-
subpath = segments[0] + sep + subpath;
229+
subpath = segments[0] + pathSeparator + subpath;
230230
}
231231

232232
if (start > 0) {
233-
result = segments[0] + sep;
233+
result = segments[0] + pathSeparator;
234234
}
235235

236236
result = prefix + result;
237237
}
238238

239239
// add ellipsis at the beginning if neeeded
240240
if (start > 0) {
241-
result = result + ellipsis + sep;
241+
result = result + ellipsis + pathSeparator;
242242
}
243243

244244
result = result + subpath;
245245

246246
// add ellipsis at the end if needed
247247
if (start + subpathLength < segments.length) {
248-
result = result + sep + ellipsis;
248+
result = result + pathSeparator + ellipsis;
249249
}
250250

251251
shortenedPaths[pathIndex] = result;

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import 'vs/css!./media/tabstitlecontrol';
7-
import { isMacintosh } from 'vs/base/common/platform';
7+
import { isMacintosh, isWindows } from 'vs/base/common/platform';
88
import { shorten } from 'vs/base/common/labels';
99
import { toResource, GroupIdentifier, IEditorInput, Verbosity, EditorCommandsContextActionRunner, IEditorPartOptions, SideBySideEditor } from 'vs/workbench/common/editor';
1010
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
@@ -43,6 +43,8 @@ import { withNullAsUndefined, assertAllDefined, assertIsDefined } from 'vs/base/
4343
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
4444
import { basenameOrAuthority } from 'vs/base/common/resources';
4545
import { RunOnceScheduler } from 'vs/base/common/async';
46+
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
47+
import { IPath, win32, posix } from 'vs/base/common/path';
4648

4749
interface IEditorInputLabel {
4850
name?: string;
@@ -69,6 +71,8 @@ export class TabsTitleControl extends TitleControl {
6971
private readonly layoutScheduled = this._register(new MutableDisposable());
7072
private blockRevealActiveTab: boolean | undefined;
7173

74+
private path: IPath = isWindows ? win32 : posix;
75+
7276
constructor(
7377
parent: HTMLElement,
7478
accessor: IEditorGroupsAccessor,
@@ -85,12 +89,18 @@ export class TabsTitleControl extends TitleControl {
8589
@IExtensionService extensionService: IExtensionService,
8690
@IConfigurationService configurationService: IConfigurationService,
8791
@IFileService fileService: IFileService,
88-
@IEditorService private readonly editorService: EditorServiceImpl
92+
@IEditorService private readonly editorService: EditorServiceImpl,
93+
@IRemotePathService private readonly remotePathService: IRemotePathService
8994
) {
9095
super(parent, accessor, group, contextMenuService, instantiationService, contextKeyService, keybindingService, telemetryService, notificationService, menuService, quickOpenService, themeService, extensionService, configurationService, fileService);
9196

9297
this.tabResourceLabels = this._register(this.instantiationService.createInstance(ResourceLabels, DEFAULT_LABELS_CONTAINER));
9398
this.closeOneEditorAction = this._register(this.instantiationService.createInstance(CloseOneEditorAction, CloseOneEditorAction.ID, CloseOneEditorAction.LABEL));
99+
100+
// Resolve the correct path library for the OS we are on
101+
// If we are connected to remote, this accounts for the
102+
// remote OS.
103+
(async () => this.path = await this.remotePathService.path)();
94104
}
95105

96106
protected create(parent: HTMLElement): void {
@@ -874,7 +884,7 @@ export class TabsTitleControl extends TitleControl {
874884
}
875885

876886
// Shorten descriptions
877-
const shortenedDescriptions = shorten(descriptions);
887+
const shortenedDescriptions = shorten(descriptions, this.path.sep);
878888
descriptions.forEach((description, i) => {
879889
for (const label of mapDescriptionToDuplicates.get(description) || []) {
880890
label.description = shortenedDescriptions[i];

0 commit comments

Comments
 (0)