Skip to content

Commit d3678a6

Browse files
committed
simplification of the condition to hide the widget
1 parent cab30c4 commit d3678a6

File tree

1 file changed

+12
-40
lines changed
  • src/vs/editor/contrib/hover/browser

1 file changed

+12
-40
lines changed

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

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

5151
static get(editor: ICodeEditor): ModesHoverController | null {
5252
return editor.getContribution<ModesHoverController>(ModesHoverController.ID);
@@ -176,45 +176,17 @@ export class ModesHoverController implements IEditorContribution {
176176
return;
177177
}
178178

179-
const onDecorator = target.element?.classList.contains('colorpicker-color-decoration');
179+
const mouseOnDecorator = target.element?.classList.contains('colorpicker-color-decoration');
180180
const decoratorActivatedOn = this._editor.getOption(EditorOption.colorDecoratorsActivatedOn);
181181

182-
console.log('onDecorator : ', onDecorator);
183-
console.log('decoratorActivatedOn : ', decoratorActivatedOn);
184-
185-
// TODO: finish the following code whith the option 'click and hover''
186-
// TODO: find out why the color hover seems to disappear when clicking on th box
187-
if (onDecorator) {
188-
if (decoratorActivatedOn === 'click') {
189-
if (!this._activatedByColorDecoratorClick) {
190-
this._hideWidgets();
191-
return;
192-
}
193-
} else if (decoratorActivatedOn === 'hover') {
194-
if (this._activatedByColorDecoratorClick) {
195-
throw new Error('Invalid state');
196-
} else {
197-
if (!this._isHoverEnabled) {
198-
this._hideWidgets();
199-
return;
200-
}
201-
}
202-
} else if (decoratorActivatedOn === 'click and hover') {
203-
console.log('entered into the third case');
204-
if (!this._activatedByColorDecoratorClick) {
205-
if (!this._isHoverEnabled) {
206-
this._hideWidgets();
207-
return;
208-
}
209-
}
210-
} else {
211-
throw new Error('Invalid value for EditorOption.colorDecoratorsActivatedOn');
212-
}
213-
} else {
214-
if (!this._isHoverEnabled && !this._activatedByColorDecoratorClick) {
215-
this._hideWidgets();
216-
return;
217-
}
182+
if ((mouseOnDecorator && (
183+
(decoratorActivatedOn === 'click' && !this._hoverActivatedByColorDecoratorClick) ||
184+
(decoratorActivatedOn === 'hover' && !this._isHoverEnabled) ||
185+
(decoratorActivatedOn === 'click and hover' && !this._isHoverEnabled && !this._hoverActivatedByColorDecoratorClick)))
186+
|| !mouseOnDecorator && !this._isHoverEnabled && !this._hoverActivatedByColorDecoratorClick
187+
) {
188+
this._hideWidgets();
189+
return;
218190
}
219191

220192
const contentWidget = this._getOrCreateContentWidget();
@@ -256,7 +228,7 @@ export class ModesHoverController implements IEditorContribution {
256228
if ((this._isMouseDown && this._hoverClicked && this._contentWidget?.isColorPickerVisible()) || InlineSuggestionHintsContentWidget.dropDownVisible) {
257229
return;
258230
}
259-
this._activatedByColorDecoratorClick = false;
231+
this._hoverActivatedByColorDecoratorClick = false;
260232
this._hoverClicked = false;
261233
this._glyphWidget?.hide();
262234
this._contentWidget?.hide();
@@ -274,7 +246,7 @@ export class ModesHoverController implements IEditorContribution {
274246
}
275247

276248
public showContentHover(range: Range, mode: HoverStartMode, source: HoverStartSource, focus: boolean, activatedByColorDecoratorClick: boolean = false): void {
277-
this._activatedByColorDecoratorClick = activatedByColorDecoratorClick;
249+
this._hoverActivatedByColorDecoratorClick = activatedByColorDecoratorClick;
278250
this._getOrCreateContentWidget().startShowingAtRange(range, mode, source, focus);
279251
}
280252

0 commit comments

Comments
 (0)