Skip to content

Commit 0be89e9

Browse files
authored
Checked tree: Inconsistent hover styles (microsoft#184152)
Fixes microsoft#183918
1 parent 53dcdf3 commit 0be89e9

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/vs/workbench/browser/parts/views/checkbox.ts

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

66
import * as DOM from 'vs/base/browser/dom';
7+
import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate';
8+
import { ICustomHover, setupCustomHover } from 'vs/base/browser/ui/iconLabel/iconLabelHover';
79
import { Toggle } from 'vs/base/browser/ui/toggle/toggle';
810
import { Codicon } from 'vs/base/common/codicons';
911
import { Emitter, Event } from 'vs/base/common/event';
@@ -25,13 +27,14 @@ export class TreeItemCheckbox extends Disposable {
2527
public toggle: Toggle | undefined;
2628
private checkboxContainer: HTMLDivElement;
2729
public isDisposed = false;
30+
private hover: ICustomHover | undefined;
2831

2932
public static readonly checkboxClass = 'custom-view-tree-node-item-checkbox';
3033

3134
private readonly _onDidChangeState = new Emitter<boolean>();
3235
readonly onDidChangeState: Event<boolean> = this._onDidChangeState.event;
3336

34-
constructor(container: HTMLElement, private checkboxStateHandler: CheckboxStateHandler) {
37+
constructor(container: HTMLElement, private checkboxStateHandler: CheckboxStateHandler, private readonly hoverDelegate: IHoverDelegate) {
3538
super();
3639
this.checkboxContainer = <HTMLDivElement>container;
3740
}
@@ -52,10 +55,11 @@ export class TreeItemCheckbox extends Disposable {
5255
if (node.checkbox) {
5356
this.toggle = new Toggle({
5457
isChecked: node.checkbox.isChecked,
55-
title: this.createCheckboxTitle(node.checkbox),
58+
title: '',
5659
icon: node.checkbox.isChecked ? Codicon.check : undefined,
5760
...defaultToggleStyles
5861
});
62+
this.setHover(node.checkbox);
5963
this.setAccessibilityInformation(node.checkbox);
6064
this.toggle.domNode.classList.add(TreeItemCheckbox.checkboxClass);
6165
DOM.append(this.checkboxContainer, this.toggle.domNode);
@@ -73,17 +77,29 @@ export class TreeItemCheckbox extends Disposable {
7377
}
7478
}
7579

80+
private setHover(checkbox: ITreeItemCheckboxState) {
81+
if (this.toggle) {
82+
if (!this.hover) {
83+
this.hover = setupCustomHover(this.hoverDelegate, this.toggle.domNode, this.checkboxHoverContent(checkbox));
84+
this._register(this.hover);
85+
} else {
86+
this.hover.update(checkbox.tooltip);
87+
}
88+
}
89+
}
90+
7691
private setCheckbox(node: ITreeItem) {
7792
if (this.toggle && node.checkbox) {
7893
node.checkbox.isChecked = this.toggle.checked;
7994
this.toggle.setIcon(this.toggle.checked ? Codicon.check : undefined);
80-
this.toggle.setTitle(this.createCheckboxTitle(node.checkbox));
95+
this.setHover(node.checkbox);
96+
8197
this.setAccessibilityInformation(node.checkbox);
8298
this.checkboxStateHandler.setCheckboxState(node);
8399
}
84100
}
85101

86-
private createCheckboxTitle(checkbox: ITreeItemCheckboxState) {
102+
private checkboxHoverContent(checkbox: ITreeItemCheckboxState): string {
87103
return checkbox.tooltip ? checkbox.tooltip :
88104
checkbox.isChecked ? localize('checked', 'Checked') : localize('unchecked', 'Unchecked');
89105
}

src/vs/workbench/browser/parts/views/treeView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
13161316
this.rerender();
13171317
}
13181318
if (!templateData.checkbox) {
1319-
const checkbox = new TreeItemCheckbox(templateData.checkboxContainer, this.checkboxStateHandler);
1319+
const checkbox = new TreeItemCheckbox(templateData.checkboxContainer, this.checkboxStateHandler, this._hoverDelegate);
13201320
templateData.checkbox = checkbox;
13211321
}
13221322
templateData.checkbox.render(node);

0 commit comments

Comments
 (0)