Skip to content
Open
14 changes: 10 additions & 4 deletions src/vs/editor/contrib/hover/browser/contentHoverController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { IKeybindingService } from '../../../../platform/keybinding/common/keybi
import { ResultKind } from '../../../../platform/keybinding/common/keybindingResolver.js';
import { HoverVerbosityAction } from '../../../common/languages.js';
import { RunOnceScheduler } from '../../../../base/common/async.js';
import { isMousePositionWithinElement, shouldShowHover } from './hoverUtils.js';
import { isMousePositionWithinElement, shouldShowHover, isTriggerModifierPressed } from './hoverUtils.js';
import { ContentHoverWidgetWrapper } from './contentHoverWidgetWrapper.js';
import './hover.css';
import { Emitter } from '../../../../base/common/event.js';
Expand Down Expand Up @@ -266,12 +266,18 @@ export class ContentHoverController extends Disposable implements IEditorContrib
}

private _onKeyDown(e: IKeyboardEvent): void {
if (this._ignoreMouseEvents) {
if (this._ignoreMouseEvents || !this._contentWidget) {
return;
}
if (!this._contentWidget) {
return;

if (this._hoverSettings.enabled === 'onKeyboardModifier'
&& isTriggerModifierPressed(this._editor.getOption(EditorOption.multiCursorModifier), e)
&& this._mouseMoveEvent) {
if (!this._contentWidget.isVisible) {
this._contentWidget.showsOrWillShow(this._mouseMoveEvent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this return after? the rest of the logic in this function talks about hiding the content widget... so is there a scenario where this is shown and then hidden?

}
}

const isPotentialKeyboardShortcut = this._isPotentialKeyboardShortcut(e);
const isModifierKeyPressed = isModifierKey(e.keyCode);
if (isPotentialKeyboardShortcut || isModifierKeyPressed) {
Expand Down
11 changes: 10 additions & 1 deletion src/vs/editor/contrib/hover/browser/glyphHoverController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IEditorContribution, IScrollEvent } from '../../../common/editorCommon.
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { IHoverWidget } from './hoverTypes.js';
import { RunOnceScheduler } from '../../../../base/common/async.js';
import { isMousePositionWithinElement, shouldShowHover } from './hoverUtils.js';
import { isMousePositionWithinElement, isTriggerModifierPressed, shouldShowHover } from './hoverUtils.js';
import './hover.css';
import { GlyphHoverWidget } from './glyphHoverWidget.js';

Expand Down Expand Up @@ -206,6 +206,15 @@ export class GlyphHoverController extends Disposable implements IEditorContribut
if (!this._editor.hasModel()) {
return;
}

if (this._hoverSettings.enabled === 'onKeyboardModifier'
&& isTriggerModifierPressed(this._editor.getOption(EditorOption.multiCursorModifier), e)
&& this._mouseMoveEvent) {
if (this._tryShowHoverWidget(this._mouseMoveEvent)) {
return;
}
}

if (isModifierKey(e.keyCode)) {
// Do not hide hover when a modifier key is pressed
return;
Expand Down
16 changes: 13 additions & 3 deletions src/vs/editor/contrib/hover/browser/hoverUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ export function shouldShowHover(
if (hoverEnabled === 'off') {
return false;
}
return isTriggerModifierPressed(multiCursorModifier, mouseEvent.event);
}

/**
* Returns true if the trigger modifier (inverse of multi-cursor modifier) is pressed.
* This works with both mouse and keyboard events by relying only on the modifier flags.
*/
export function isTriggerModifierPressed(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some tests for this would be good.

multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey',
event: { ctrlKey: boolean; metaKey: boolean; altKey: boolean }
): boolean {
if (multiCursorModifier === 'altKey') {
return mouseEvent.event.ctrlKey || mouseEvent.event.metaKey;
} else {
return mouseEvent.event.altKey;
return event.ctrlKey || event.metaKey;
}
return event.altKey; // multiCursorModifier is ctrlKey or metaKey
}
Loading