Skip to content

Commit c780d0d

Browse files
authored
Merge pull request microsoft#186719 from microsoft/aiday/contentShowOnFocus
Keep content open hover when focused until unfocused and mouse moved
2 parents 8e1ae0d + 8df24c5 commit c780d0d

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class ColorContribution extends Disposable implements IEditorContribution
6060
if (!hoverController) {
6161
return;
6262
}
63-
if (!hoverController.isColorPickerVisible()) {
63+
if (!hoverController.isColorPickerVisible) {
6464
const range = new Range(target.range.startLineNumber, target.range.startColumn + 1, target.range.endLineNumber, target.range.endColumn + 1);
6565
hoverController.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Mouse, false, true);
6666
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,26 @@ export class ContentHoverController extends Disposable {
215215
this._setCurrentResult(null);
216216
}
217217

218-
public isColorPickerVisible(): boolean {
218+
public get isColorPickerVisible(): boolean {
219219
return this._widget.isColorPickerVisible;
220220
}
221221

222-
public isVisibleFromKeyboard(): boolean {
222+
public get isVisibleFromKeyboard(): boolean {
223223
return this._widget.isVisibleFromKeyboard;
224224
}
225225

226-
public isVisible(): boolean {
226+
public get isVisible(): boolean {
227227
return this._widget.isVisible;
228228
}
229229

230+
public get isFocused(): boolean {
231+
return this._widget.isFocused;
232+
}
233+
234+
public get isResizing(): boolean {
235+
return this._widget.isResizing;
236+
}
237+
230238
public containsNode(node: Node | null | undefined): boolean {
231239
return (node ? this._widget.getDomNode().contains(node) : false);
232240
}
@@ -476,6 +484,10 @@ export class ContentHoverWidget extends ResizableContentWidget {
476484
return this._hoverVisibleKey.get() ?? false;
477485
}
478486

487+
public get isFocused(): boolean {
488+
return this._hoverFocusedKey.get() ?? false;
489+
}
490+
479491
constructor(
480492
editor: ICodeEditor,
481493
@IContextKeyService contextKeyService: IContextKeyService

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export class ModesHoverController implements IEditorContribution {
155155
private _onEditorMouseMove(mouseEvent: IEditorMouseEvent): void {
156156
const target = mouseEvent.target;
157157

158+
if (this._contentWidget?.isFocused || this._contentWidget?.isResizing) {
159+
return;
160+
}
161+
158162
if (this._isMouseDown && this._hoverClicked) {
159163
return;
160164
}
@@ -171,7 +175,7 @@ export class ModesHoverController implements IEditorContribution {
171175

172176
if (
173177
!this._isHoverSticky && target.type === MouseTargetType.CONTENT_WIDGET && target.detail === ContentHoverWidget.ID
174-
&& this._contentWidget?.isColorPickerVisible()
178+
&& this._contentWidget?.isColorPickerVisible
175179
) {
176180
// though the hover is not sticky, the color picker needs to.
177181
return;
@@ -182,7 +186,7 @@ export class ModesHoverController implements IEditorContribution {
182186
return;
183187
}
184188

185-
if (this._isHoverSticky && this._contentWidget?.isVisibleFromKeyboard()) {
189+
if (this._isHoverSticky && this._contentWidget?.isVisibleFromKeyboard) {
186190
// Sticky mode is on and the hover has been shown via keyboard
187191
// so moving the mouse has no effect
188192
return;
@@ -216,9 +220,10 @@ export class ModesHoverController implements IEditorContribution {
216220
this._glyphWidget.startShowingAt(target.position.lineNumber);
217221
return;
218222
}
219-
if (!this._contentWidget?.widget.isResizing && !_sticky) {
220-
this._hideWidgets();
223+
if (_sticky) {
224+
return;
221225
}
226+
this._hideWidgets();
222227
}
223228

224229
private _onKeyDown(e: IKeyboardEvent): void {
@@ -228,7 +233,7 @@ export class ModesHoverController implements IEditorContribution {
228233

229234
const resolvedKeyboardEvent = this._keybindingService.softDispatch(e, this._editor.getDomNode());
230235
// If the beginning of a multi-chord keybinding is pressed, or the command aims to focus the hover, set the variable to true, otherwise false
231-
const mightTriggerFocus = (resolvedKeyboardEvent.kind === ResultKind.MoreChordsNeeded || (resolvedKeyboardEvent.kind === ResultKind.KbFound && resolvedKeyboardEvent.commandId === 'editor.action.showHover' && this._contentWidget?.isVisible()));
236+
const mightTriggerFocus = (resolvedKeyboardEvent.kind === ResultKind.MoreChordsNeeded || (resolvedKeyboardEvent.kind === ResultKind.KbFound && resolvedKeyboardEvent.commandId === 'editor.action.showHover' && this._contentWidget?.isVisible));
232237

233238
if (e.keyCode !== KeyCode.Ctrl && e.keyCode !== KeyCode.Alt && e.keyCode !== KeyCode.Meta && e.keyCode !== KeyCode.Shift
234239
&& !mightTriggerFocus) {
@@ -241,7 +246,7 @@ export class ModesHoverController implements IEditorContribution {
241246
if (_sticky) {
242247
return;
243248
}
244-
if ((this._isMouseDown && this._hoverClicked && this._contentWidget?.isColorPickerVisible()) || InlineSuggestionHintsContentWidget.dropDownVisible) {
249+
if ((this._isMouseDown && this._hoverClicked && this._contentWidget?.isColorPickerVisible) || InlineSuggestionHintsContentWidget.dropDownVisible) {
245250
return;
246251
}
247252
this._hoverActivatedByColorDecoratorClick = false;
@@ -257,10 +262,6 @@ export class ModesHoverController implements IEditorContribution {
257262
return this._contentWidget;
258263
}
259264

260-
public isColorPickerVisible(): boolean {
261-
return this._contentWidget?.isColorPickerVisible() || false;
262-
}
263-
264265
public showContentHover(range: Range, mode: HoverStartMode, source: HoverStartSource, focus: boolean, activatedByColorDecoratorClick: boolean = false): void {
265266
this._hoverActivatedByColorDecoratorClick = activatedByColorDecoratorClick;
266267
this._getOrCreateContentWidget().startShowingAtRange(range, mode, source, focus);
@@ -302,8 +303,12 @@ export class ModesHoverController implements IEditorContribution {
302303
this._contentWidget?.goToBottom();
303304
}
304305

305-
public isHoverVisible(): boolean | undefined {
306-
return this._contentWidget?.isVisible();
306+
public get isColorPickerVisible(): boolean | undefined {
307+
return this._contentWidget?.isColorPickerVisible;
308+
}
309+
310+
public get isHoverVisible(): boolean | undefined {
311+
return this._contentWidget?.isVisible;
307312
}
308313

309314
public dispose(): void {
@@ -367,7 +372,7 @@ class ShowOrFocusHoverAction extends EditorAction {
367372
const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column);
368373
const focus = editor.getOption(EditorOption.accessibilitySupport) === AccessibilitySupport.Enabled || !!args?.focus;
369374

370-
if (controller.isHoverVisible()) {
375+
if (controller.isHoverVisible) {
371376
controller.focus();
372377
} else {
373378
controller.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Keyboard, focus);

0 commit comments

Comments
 (0)