Skip to content

Commit b53fb02

Browse files
authored
Recent devcontainer display string corrupted on Get Started page (microsoft#183740)
1 parent 26ee556 commit b53fb02

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

src/vs/base/common/labels.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,21 @@ export function unmnemonicLabel(label: string): string {
436436
}
437437

438438
/**
439-
* Splits a path in name and parent path, supporting both '/' and '\'
439+
* Splits a recent label in name and parent path, supporting both '/' and '\' and workspace suffixes
440440
*/
441-
export function splitName(fullPath: string): { name: string; parentPath: string } {
441+
export function splitRecentLabel(recentLabel: string) {
442+
if (recentLabel.endsWith(']')) {
443+
// label with workspace suffix
444+
const lastIndexOfSquareBracket = recentLabel.lastIndexOf(' [', recentLabel.length - 2);
445+
if (lastIndexOfSquareBracket !== -1) {
446+
const split = splitName(recentLabel.substring(0, lastIndexOfSquareBracket));
447+
return { name: split.name, parentPath: split.parentPath + recentLabel.substring(lastIndexOfSquareBracket) };
448+
}
449+
}
450+
return splitName(recentLabel);
451+
}
452+
453+
function splitName(fullPath: string): { name: string; parentPath: string } {
442454
const p = fullPath.indexOf('/') !== -1 ? posix : win32;
443455
const name = p.basename(fullPath);
444456
const parentPath = p.dirname(fullPath);

src/vs/platform/workspaces/electron-main/workspacesHistoryMainService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { app, JumpListCategory, JumpListItem } from 'electron';
77
import { coalesce } from 'vs/base/common/arrays';
88
import { ThrottledDelayer } from 'vs/base/common/async';
99
import { Emitter, Event as CommonEvent } from 'vs/base/common/event';
10-
import { normalizeDriveLetter, splitName } from 'vs/base/common/labels';
10+
import { normalizeDriveLetter, splitRecentLabel } from 'vs/base/common/labels';
1111
import { Disposable } from 'vs/base/common/lifecycle';
1212
import { Schemas } from 'vs/base/common/network';
1313
import { isMacintosh, isWindows } from 'vs/base/common/platform';
@@ -390,7 +390,7 @@ export class WorkspacesHistoryMainService extends Disposable implements IWorkspa
390390

391391
// Prefer recent label
392392
if (recentLabel) {
393-
return { title: splitName(recentLabel).name, description: recentLabel };
393+
return { title: splitRecentLabel(recentLabel).name, description: recentLabel };
394394
}
395395

396396
// Single Folder

src/vs/workbench/browser/actions/windowActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { IRecent, isRecentFolder, isRecentWorkspace, IWorkspacesService } from '
2222
import { URI } from 'vs/base/common/uri';
2323
import { getIconClasses } from 'vs/editor/common/services/getIconClasses';
2424
import { FileKind } from 'vs/platform/files/common/files';
25-
import { splitName } from 'vs/base/common/labels';
25+
import { splitRecentLabel } from 'vs/base/common/labels';
2626
import { isMacintosh, isWeb, isWindows } from 'vs/base/common/platform';
2727
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
2828
import { inQuickPickContext, getQuickNavigateHandler } from 'vs/workbench/browser/quickaccess';
@@ -214,7 +214,7 @@ abstract class BaseOpenRecentAction extends Action2 {
214214
fullLabel = recent.label || labelService.getUriLabel(resource);
215215
}
216216

217-
const { name, parentPath } = splitName(fullLabel);
217+
const { name, parentPath } = splitRecentLabel(fullLabel);
218218

219219
return {
220220
iconClasses,

src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { IRecentFolder, IRecentlyOpened, IRecentWorkspace, isRecentFolder, isRec
3131
import { IWorkspaceContextService, UNKNOWN_EMPTY_WINDOW_WORKSPACE } from 'vs/platform/workspace/common/workspace';
3232
import { ILabelService, Verbosity } from 'vs/platform/label/common/label';
3333
import { IWindowOpenable } from 'vs/platform/window/common/window';
34-
import { splitName } from 'vs/base/common/labels';
34+
import { splitRecentLabel } from 'vs/base/common/labels';
3535
import { IHostService } from 'vs/workbench/services/host/browser/host';
3636
import { isMacintosh } from 'vs/base/common/platform';
3737
import { Delayer, Throttler } from 'vs/base/common/async';
@@ -883,7 +883,7 @@ export class GettingStartedPage extends EditorPane {
883883
windowOpenable = { workspaceUri: recent.workspace.configPath };
884884
}
885885

886-
const { name, parentPath } = splitName(fullPath);
886+
const { name, parentPath } = splitRecentLabel(fullPath);
887887

888888
const li = $('li');
889889
const link = $('button.button-link');

src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
3434
import { IMarkdownString, MarkdownString } from 'vs/base/common/htmlContent';
3535
import { STATUS_BAR_PROMINENT_ITEM_BACKGROUND, STATUS_BAR_PROMINENT_ITEM_FOREGROUND } from 'vs/workbench/common/theme';
3636
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
37-
import { splitName } from 'vs/base/common/labels';
3837
import { IHostService } from 'vs/workbench/services/host/browser/host';
3938
import { IBannerItem, IBannerService } from 'vs/workbench/services/banner/browser/bannerService';
4039
import { isVirtualWorkspace } from 'vs/platform/workspace/common/virtualWorkspace';
@@ -48,6 +47,7 @@ import { MANAGE_TRUST_COMMAND_ID, WorkspaceTrustContext } from 'vs/workbench/con
4847
import { isWeb } from 'vs/base/common/platform';
4948
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
5049
import { securityConfigurationNodeBase } from 'vs/workbench/common/configuration';
50+
import { basename, dirname as uriDirname } from 'vs/base/common/resources';
5151

5252
const BANNER_RESTRICTED_MODE = 'workbench.banner.restrictedMode';
5353
const STARTUP_PROMPT_SHOWN_KEY = 'workspace.trust.startupPrompt.shown';
@@ -314,7 +314,7 @@ export class WorkspaceTrustUXHandler extends Disposable implements IWorkbenchCon
314314
const isSingleFolderWorkspace = isSingleFolderWorkspaceIdentifier(workspaceIdentifier);
315315
const isEmptyWindow = isEmptyWorkspaceIdentifier(workspaceIdentifier);
316316
if (this.workspaceTrustManagementService.canSetParentFolderTrust()) {
317-
const { name } = splitName(splitName((workspaceIdentifier as ISingleFolderWorkspaceIdentifier).uri.fsPath).parentPath);
317+
const name = basename(uriDirname((workspaceIdentifier as ISingleFolderWorkspaceIdentifier).uri));
318318
checkboxText = localize('checkboxString', "Trust the authors of all files in the parent folder '{0}'", name);
319319
}
320320

src/vs/workbench/contrib/workspace/browser/workspaceTrustEditor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Codicon } from 'vs/base/common/codicons';
1515
import { debounce } from 'vs/base/common/decorators';
1616
import { Emitter, Event } from 'vs/base/common/event';
1717
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
18-
import { normalizeDriveLetter, splitName } from 'vs/base/common/labels';
18+
import { normalizeDriveLetter } from 'vs/base/common/labels';
1919
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
2020
import { parseLinkedText } from 'vs/base/common/linkedText';
2121
import { Schemas } from 'vs/base/common/network';
@@ -58,6 +58,7 @@ import { defaultButtonStyles, defaultInputBoxStyles } from 'vs/platform/theme/br
5858
import { isMacintosh } from 'vs/base/common/platform';
5959
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
6060
import { ResolvedKeybinding } from 'vs/base/common/keybindings';
61+
import { basename, dirname } from 'vs/base/common/resources';
6162

6263
export const shieldIcon = registerIcon('workspace-trust-banner', Codicon.shield, localize('shieldIcon', 'Icon for workspace trust ion the banner.'));
6364

@@ -1041,7 +1042,7 @@ export class WorkspaceTrustEditor extends EditorPane {
10411042

10421043
if (this.workspaceTrustManagementService.canSetParentFolderTrust()) {
10431044
const workspaceIdentifier = toWorkspaceIdentifier(this.workspaceService.getWorkspace()) as ISingleFolderWorkspaceIdentifier;
1044-
const { name } = splitName(splitName(workspaceIdentifier.uri.fsPath).parentPath);
1045+
const name = basename(dirname(workspaceIdentifier.uri));
10451046

10461047
const trustMessageElement = append(parent, $('.trust-message-box'));
10471048
trustMessageElement.innerText = localize('trustMessage', "Trust the authors of all files in the current folder or its parent '{0}'.", name);

0 commit comments

Comments
 (0)