Skip to content

Commit a1bcb27

Browse files
authored
Merge pull request microsoft#184079 from microsoft/aiday/issue#182697And#179575
Adding settings to control color decorator behavior
2 parents d823366 + 6263d2e commit a1bcb27

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

src/vs/editor/common/config/editorOptions.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ export interface IEditorOptions {
349349
* Enable inline color decorators and color picker rendering.
350350
*/
351351
colorDecorators?: boolean;
352+
/**
353+
* Controls what is the condition to spawn a color picker from a color dectorator
354+
*/
355+
colorDecoratorsActivatedOn?: 'clickAndHover' | 'click' | 'hover';
352356
/**
353357
* Controls the max number of color decorators that can be rendered in an editor at once.
354358
*/
@@ -5062,7 +5066,8 @@ export const enum EditorOption {
50625066
tabFocusMode,
50635067
layoutInfo,
50645068
wrappingInfo,
5065-
defaultColorDecorators
5069+
defaultColorDecorators,
5070+
colorDecoratorsActivatedOn
50665071
}
50675072

50685073
export const EditorOptions = {
@@ -5211,6 +5216,14 @@ export const EditorOptions = {
52115216
EditorOption.colorDecorators, 'colorDecorators', true,
52125217
{ description: nls.localize('colorDecorators', "Controls whether the editor should render the inline color decorators and color picker.") }
52135218
)),
5219+
colorDecoratorActivatedOn: register(new EditorStringEnumOption(EditorOption.colorDecoratorsActivatedOn, 'colorDecoratorsActivatedOn', 'clickAndHover' as 'clickAndHover' | 'hover' | 'click', ['clickAndHover', 'hover', 'click'] as const, {
5220+
enumDescriptions: [
5221+
nls.localize('editor.colorDecoratorActivatedOn.clickAndHover', "Make the color picker appear both on click and hover of the color decorator"),
5222+
nls.localize('editor.colorDecoratorActivatedOn.hover', "Make the color picker appear on hover of the color decorator"),
5223+
nls.localize('editor.colorDecoratorActivatedOn.click', "Make the color picker appear on click of the color decorator")
5224+
],
5225+
description: nls.localize('colorDecoratorActivatedOn', "Controls the condition to make a color picker appear from a color decorator")
5226+
})),
52145227
colorDecoratorsLimit: register(new EditorIntOption(
52155228
EditorOption.colorDecoratorsLimit, 'colorDecoratorsLimit', 500, 1, 1000000,
52165229
{

src/vs/editor/common/standalone/standaloneEnums.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ export enum EditorOption {
315315
tabFocusMode = 139,
316316
layoutInfo = 140,
317317
wrappingInfo = 141,
318-
defaultColorDecorators = 142
318+
defaultColorDecorators = 142,
319+
colorDecoratorsActivatedOn = 143
319320
}
320321

321322
/**

src/vs/editor/contrib/colorPicker/browser/colorContributions.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { Disposable } from 'vs/base/common/lifecycle';
77
import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser';
88
import { EditorContributionInstantiation, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
9+
import { EditorOption } from 'vs/editor/common/config/editorOptions';
910
import { Range } from 'vs/editor/common/core/range';
1011
import { IEditorContribution } from 'vs/editor/common/editorCommon';
1112
import { ColorDecorationInjectedTextMarker } from 'vs/editor/contrib/colorPicker/browser/colorDetector';
@@ -31,6 +32,12 @@ export class ColorContribution extends Disposable implements IEditorContribution
3132
}
3233

3334
private onMouseDown(mouseEvent: IEditorMouseEvent) {
35+
36+
const colorDecoratorsActivatedOn = this._editor.getOption(EditorOption.colorDecoratorsActivatedOn);
37+
if (colorDecoratorsActivatedOn !== 'click' && colorDecoratorsActivatedOn !== 'clickAndHover') {
38+
return;
39+
}
40+
3441
const target = mouseEvent.target;
3542

3643
if (target.type !== MouseTargetType.CONTENT_TEXT) {
@@ -55,7 +62,7 @@ export class ColorContribution extends Disposable implements IEditorContribution
5562
}
5663
if (!hoverController.isColorPickerVisible()) {
5764
const range = new Range(target.range.startLineNumber, target.range.startColumn + 1, target.range.endLineNumber, target.range.endColumn + 1);
58-
hoverController.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Mouse, false);
65+
hoverController.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Mouse, false, true);
5966
}
6067
}
6168
}

src/vs/editor/contrib/hover/browser/hover.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class ModesHoverController implements IEditorContribution {
4646
private _hoverClicked: boolean;
4747
private _isHoverEnabled!: boolean;
4848
private _isHoverSticky!: boolean;
49+
private _hoverActivatedByColorDecoratorClick: boolean = false;
4950

5051
static get(editor: ICodeEditor): ModesHoverController | null {
5152
return editor.getContribution<ModesHoverController>(ModesHoverController.ID);
@@ -175,7 +176,15 @@ export class ModesHoverController implements IEditorContribution {
175176
return;
176177
}
177178

178-
if (!this._isHoverEnabled) {
179+
const mouseOnDecorator = target.element?.classList.contains('colorpicker-color-decoration');
180+
const decoratorActivatedOn = this._editor.getOption(EditorOption.colorDecoratorsActivatedOn);
181+
182+
if ((mouseOnDecorator && (
183+
(decoratorActivatedOn === 'click' && !this._hoverActivatedByColorDecoratorClick) ||
184+
(decoratorActivatedOn === 'hover' && !this._isHoverEnabled) ||
185+
(decoratorActivatedOn === 'clickAndHover' && !this._isHoverEnabled && !this._hoverActivatedByColorDecoratorClick)))
186+
|| !mouseOnDecorator && !this._isHoverEnabled && !this._hoverActivatedByColorDecoratorClick
187+
) {
179188
this._hideWidgets();
180189
return;
181190
}
@@ -219,7 +228,7 @@ export class ModesHoverController implements IEditorContribution {
219228
if ((this._isMouseDown && this._hoverClicked && this._contentWidget?.isColorPickerVisible()) || InlineSuggestionHintsContentWidget.dropDownVisible) {
220229
return;
221230
}
222-
231+
this._hoverActivatedByColorDecoratorClick = false;
223232
this._hoverClicked = false;
224233
this._glyphWidget?.hide();
225234
this._contentWidget?.hide();
@@ -236,7 +245,8 @@ export class ModesHoverController implements IEditorContribution {
236245
return this._contentWidget?.isColorPickerVisible() || false;
237246
}
238247

239-
public showContentHover(range: Range, mode: HoverStartMode, source: HoverStartSource, focus: boolean): void {
248+
public showContentHover(range: Range, mode: HoverStartMode, source: HoverStartSource, focus: boolean, activatedByColorDecoratorClick: boolean = false): void {
249+
this._hoverActivatedByColorDecoratorClick = activatedByColorDecoratorClick;
240250
this._getOrCreateContentWidget().startShowingAtRange(range, mode, source, focus);
241251
}
242252

src/vs/monaco.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3456,6 +3456,10 @@ declare namespace monaco.editor {
34563456
* Enable inline color decorators and color picker rendering.
34573457
*/
34583458
colorDecorators?: boolean;
3459+
/**
3460+
* Controls what is the condition to spawn a color picker from a color dectorator
3461+
*/
3462+
colorDecoratorsActivatedOn?: 'clickAndHover' | 'click' | 'hover';
34593463
/**
34603464
* Controls the max number of color decorators that can be rendered in an editor at once.
34613465
*/
@@ -4927,7 +4931,8 @@ declare namespace monaco.editor {
49274931
tabFocusMode = 139,
49284932
layoutInfo = 140,
49294933
wrappingInfo = 141,
4930-
defaultColorDecorators = 142
4934+
defaultColorDecorators = 142,
4935+
colorDecoratorsActivatedOn = 143
49314936
}
49324937

49334938
export const EditorOptions: {
@@ -4951,6 +4956,7 @@ declare namespace monaco.editor {
49514956
codeLensFontFamily: IEditorOption<EditorOption.codeLensFontFamily, string>;
49524957
codeLensFontSize: IEditorOption<EditorOption.codeLensFontSize, number>;
49534958
colorDecorators: IEditorOption<EditorOption.colorDecorators, boolean>;
4959+
colorDecoratorActivatedOn: IEditorOption<EditorOption.colorDecoratorsActivatedOn, 'clickAndHover' | 'click' | 'hover'>;
49544960
colorDecoratorsLimit: IEditorOption<EditorOption.colorDecoratorsLimit, number>;
49554961
columnSelection: IEditorOption<EditorOption.columnSelection, boolean>;
49564962
comments: IEditorOption<EditorOption.comments, Readonly<Required<IEditorCommentsOptions>>>;

0 commit comments

Comments
 (0)