Skip to content

Commit 04dd69f

Browse files
committed
Renders toggle state in action bar. Fixes #186403.
1 parent 1dcbd07 commit 04dd69f

File tree

8 files changed

+46
-49
lines changed

8 files changed

+46
-49
lines changed

build/lib/stylelint/vscode-known-variables.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"colors": [
3+
"--vscode-actionBar-toggledBackground",
34
"--vscode-activityBar-activeBackground",
45
"--vscode-activityBar-activeBorder",
56
"--vscode-activityBar-activeFocusBorder",

src/vs/base/browser/ui/actionbar/actionbar.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export interface IActionBarOptions {
5151
readonly preventLoopNavigation?: boolean;
5252
readonly focusOnlyEnabledItems?: boolean;
5353
readonly hoverDelegate?: IHoverDelegate;
54+
/**
55+
* If true, toggled primary items are highlighted with a background color.
56+
* Some action bars exclusively use icon states, we don't want to enable this for them.
57+
* Thus, this is opt-in.
58+
*/
59+
readonly highlightToggledItems?: boolean;
5460
}
5561

5662
export interface IActionOptions extends IActionViewItemOptions {
@@ -213,6 +219,9 @@ export class ActionBar extends Disposable implements IActionRunner {
213219

214220
this.actionsList = document.createElement('ul');
215221
this.actionsList.className = 'actions-container';
222+
if (this.options.highlightToggledItems) {
223+
this.actionsList.classList.add('highlight-toggled');
224+
}
216225
this.actionsList.setAttribute('role', this.options.ariaRole || 'toolbar');
217226

218227
if (this.options.ariaLabel) {

src/vs/base/browser/ui/toolbar/toolbar.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export interface IToolBarOptions {
3030
moreIcon?: ThemeIcon;
3131
allowContextMenu?: boolean;
3232
skipTelemetry?: boolean;
33+
34+
/**
35+
* If true, toggled primary items are highlighted with a background color.
36+
*/
37+
highlightToggledItems?: boolean;
3338
}
3439

3540
/**
@@ -66,6 +71,7 @@ export class ToolBar extends Disposable {
6671
ariaLabel: options.ariaLabel,
6772
actionRunner: options.actionRunner,
6873
allowContextMenu: options.allowContextMenu,
74+
highlightToggledItems: options.highlightToggledItems,
6975
actionViewItemProvider: (action, viewItemOptions) => {
7076
if (action.id === ToggleMenuAction.ID) {
7177
this.toggleMenuActionViewItem = new DropdownMenuActionViewItem(

src/vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2.contribution.ts

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

66
import { Codicon } from 'vs/base/common/codicons';
7-
import { ThemeIcon } from 'vs/base/common/themables';
87
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
98
import { EditorAction2, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
109
import { findFocusedDiffEditor } from 'vs/editor/browser/widget/diffEditor.contribution';
@@ -23,6 +22,13 @@ export class ToggleCollapseUnchangedRegions extends Action2 {
2322
title: { value: localize('toggleCollapseUnchangedRegions', "Toggle Collapse Unchanged Regions"), original: 'Toggle Collapse Unchanged Regions' },
2423
icon: Codicon.map,
2524
precondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),
25+
toggled: ContextKeyExpr.has('config.diffEditor.experimental.collapseUnchangedRegions'),
26+
menu: {
27+
id: MenuId.EditorTitle,
28+
order: 22,
29+
group: 'navigation',
30+
when: ContextKeyEqualsExpr.create('diffEditorVersion', 2),
31+
},
2632
});
2733
}
2834

@@ -35,34 +41,6 @@ export class ToggleCollapseUnchangedRegions extends Action2 {
3541

3642
registerAction2(ToggleCollapseUnchangedRegions);
3743

38-
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
39-
command: {
40-
id: new ToggleCollapseUnchangedRegions().desc.id,
41-
title: localize('collapseUnchangedRegions', "Show Unchanged Regions"),
42-
icon: Codicon.map
43-
},
44-
order: 22,
45-
group: 'navigation',
46-
when: ContextKeyExpr.and(
47-
ContextKeyExpr.has('config.diffEditor.experimental.collapseUnchangedRegions'),
48-
ContextKeyEqualsExpr.create('diffEditorVersion', 2)
49-
)
50-
});
51-
52-
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
53-
command: {
54-
id: new ToggleCollapseUnchangedRegions().desc.id,
55-
title: localize('showUnchangedRegions', "Collapse Unchanged Regions"),
56-
icon: ThemeIcon.modify(Codicon.map, 'disabled'),
57-
},
58-
order: 22,
59-
group: 'navigation',
60-
when: ContextKeyExpr.and(
61-
ContextKeyExpr.has('config.diffEditor.experimental.collapseUnchangedRegions').negate(),
62-
ContextKeyEqualsExpr.create('diffEditorVersion', 2)
63-
)
64-
});
65-
6644
export class ToggleShowMovedCodeBlocks extends Action2 {
6745
constructor() {
6846
super({

src/vs/platform/actionWidget/browser/actionWidget.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,8 @@
142142
.action-widget-action-bar .action-label:hover {
143143
background-color: transparent !important;
144144
}
145+
146+
.monaco-action-bar .actions-container.highlight-toggled .action-label.checked {
147+
/* The important gives this rule precedence over the hover rule. */
148+
background: var(--vscode-actionBar-toggledBackground) !important;
149+
}

src/vs/platform/actionWidget/browser/actionWidget.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
1717
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
1818
import { createDecorator, IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1919
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
20+
import { registerColor } from 'vs/platform/theme/common/colorRegistry';
2021

22+
registerColor(
23+
'actionBar.toggledBackground',
24+
{ dark: '#383a49', light: '#dddddd', hcDark: '#383a49', hcLight: '#dddddd', },
25+
localize('actionBar.toggledBackground', 'Background color for toggled action items in action bar.')
26+
);
2127

2228
const ActionWidgetContextKeys = {
2329
Visible: new RawContextKey<boolean>('codeActionMenuVisible', false, localize('codeActionMenuVisible', "Whether the action widget list is visible"))

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -554,27 +554,18 @@ appendEditorToolItem(
554554
11
555555
);
556556

557-
// Diff Editor Title Menu: Toggle Ignore Trim Whitespace (Enabled)
558-
appendEditorToolItem(
559-
{
560-
id: TOGGLE_DIFF_IGNORE_TRIM_WHITESPACE,
561-
title: localize('ignoreTrimWhitespace.label', "Ignore Leading/Trailing Whitespace Differences"),
562-
icon: toggleWhitespace
563-
},
564-
ContextKeyExpr.and(TextCompareEditorActiveContext, ContextKeyExpr.notEquals('config.diffEditor.ignoreTrimWhitespace', true)),
565-
20
566-
);
567-
568-
// Diff Editor Title Menu: Toggle Ignore Trim Whitespace (Disabled)
569-
appendEditorToolItem(
570-
{
557+
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
558+
command: {
571559
id: TOGGLE_DIFF_IGNORE_TRIM_WHITESPACE,
572-
title: localize('showTrimWhitespace.label', "Show Leading/Trailing Whitespace Differences"),
573-
icon: ThemeIcon.modify(toggleWhitespace, 'disabled')
560+
title: localize('ignoreTrimWhitespace.label', "Show Leading/Trailing Whitespace Differences"),
561+
icon: toggleWhitespace,
562+
precondition: TextCompareEditorActiveContext,
563+
toggled: ContextKeyExpr.equals('config.diffEditor.ignoreTrimWhitespace', false),
574564
},
575-
ContextKeyExpr.and(TextCompareEditorActiveContext, ContextKeyExpr.notEquals('config.diffEditor.ignoreTrimWhitespace', false)),
576-
20
577-
);
565+
group: 'navigation',
566+
when: TextCompareEditorActiveContext,
567+
order: 20,
568+
});
578569

579570
// Editor Commands for Command Palette
580571
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: KEEP_EDITOR_COMMAND_ID, title: { value: localize('keepEditor', "Keep Editor"), original: 'Keep Editor' }, category: Categories.View }, when: ContextKeyExpr.has('config.workbench.editor.enablePreview') });

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ export abstract class TitleControl extends Themable {
199199
renderDropdownAsChildElement: this.renderDropdownAsChildElement,
200200
telemetrySource: 'editorPart',
201201
resetMenu: MenuId.EditorTitle,
202-
maxNumberOfItems: 9
202+
maxNumberOfItems: 9,
203+
highlightToggledItems: true,
203204
}));
204205

205206
// Context

0 commit comments

Comments
 (0)