Merge pull request #186719 from microsoft/aiday/contentShowOnFocus

Keep content open hover when focused until unfocused and mouse moved
This commit is contained in:
Aiday Marlen Kyzy 2023-07-14 15:42:06 +02:00 committed by GitHub
commit c780d0dfef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 17 deletions

View file

@ -60,7 +60,7 @@ export class ColorContribution extends Disposable implements IEditorContribution
if (!hoverController) {
return;
}
if (!hoverController.isColorPickerVisible()) {
if (!hoverController.isColorPickerVisible) {
const range = new Range(target.range.startLineNumber, target.range.startColumn + 1, target.range.endLineNumber, target.range.endColumn + 1);
hoverController.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Mouse, false, true);
}

View file

@ -215,18 +215,26 @@ export class ContentHoverController extends Disposable {
this._setCurrentResult(null);
}
public isColorPickerVisible(): boolean {
public get isColorPickerVisible(): boolean {
return this._widget.isColorPickerVisible;
}
public isVisibleFromKeyboard(): boolean {
public get isVisibleFromKeyboard(): boolean {
return this._widget.isVisibleFromKeyboard;
}
public isVisible(): boolean {
public get isVisible(): boolean {
return this._widget.isVisible;
}
public get isFocused(): boolean {
return this._widget.isFocused;
}
public get isResizing(): boolean {
return this._widget.isResizing;
}
public containsNode(node: Node | null | undefined): boolean {
return (node ? this._widget.getDomNode().contains(node) : false);
}
@ -476,6 +484,10 @@ export class ContentHoverWidget extends ResizableContentWidget {
return this._hoverVisibleKey.get() ?? false;
}
public get isFocused(): boolean {
return this._hoverFocusedKey.get() ?? false;
}
constructor(
editor: ICodeEditor,
@IContextKeyService contextKeyService: IContextKeyService

View file

@ -155,6 +155,10 @@ export class ModesHoverController implements IEditorContribution {
private _onEditorMouseMove(mouseEvent: IEditorMouseEvent): void {
const target = mouseEvent.target;
if (this._contentWidget?.isFocused || this._contentWidget?.isResizing) {
return;
}
if (this._isMouseDown && this._hoverClicked) {
return;
}
@ -171,7 +175,7 @@ export class ModesHoverController implements IEditorContribution {
if (
!this._isHoverSticky && target.type === MouseTargetType.CONTENT_WIDGET && target.detail === ContentHoverWidget.ID
&& this._contentWidget?.isColorPickerVisible()
&& this._contentWidget?.isColorPickerVisible
) {
// though the hover is not sticky, the color picker needs to.
return;
@ -182,7 +186,7 @@ export class ModesHoverController implements IEditorContribution {
return;
}
if (this._isHoverSticky && this._contentWidget?.isVisibleFromKeyboard()) {
if (this._isHoverSticky && this._contentWidget?.isVisibleFromKeyboard) {
// Sticky mode is on and the hover has been shown via keyboard
// so moving the mouse has no effect
return;
@ -216,9 +220,10 @@ export class ModesHoverController implements IEditorContribution {
this._glyphWidget.startShowingAt(target.position.lineNumber);
return;
}
if (!this._contentWidget?.widget.isResizing && !_sticky) {
this._hideWidgets();
if (_sticky) {
return;
}
this._hideWidgets();
}
private _onKeyDown(e: IKeyboardEvent): void {
@ -228,7 +233,7 @@ export class ModesHoverController implements IEditorContribution {
const resolvedKeyboardEvent = this._keybindingService.softDispatch(e, this._editor.getDomNode());
// 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
const mightTriggerFocus = (resolvedKeyboardEvent.kind === ResultKind.MoreChordsNeeded || (resolvedKeyboardEvent.kind === ResultKind.KbFound && resolvedKeyboardEvent.commandId === 'editor.action.showHover' && this._contentWidget?.isVisible()));
const mightTriggerFocus = (resolvedKeyboardEvent.kind === ResultKind.MoreChordsNeeded || (resolvedKeyboardEvent.kind === ResultKind.KbFound && resolvedKeyboardEvent.commandId === 'editor.action.showHover' && this._contentWidget?.isVisible));
if (e.keyCode !== KeyCode.Ctrl && e.keyCode !== KeyCode.Alt && e.keyCode !== KeyCode.Meta && e.keyCode !== KeyCode.Shift
&& !mightTriggerFocus) {
@ -241,7 +246,7 @@ export class ModesHoverController implements IEditorContribution {
if (_sticky) {
return;
}
if ((this._isMouseDown && this._hoverClicked && this._contentWidget?.isColorPickerVisible()) || InlineSuggestionHintsContentWidget.dropDownVisible) {
if ((this._isMouseDown && this._hoverClicked && this._contentWidget?.isColorPickerVisible) || InlineSuggestionHintsContentWidget.dropDownVisible) {
return;
}
this._hoverActivatedByColorDecoratorClick = false;
@ -257,10 +262,6 @@ export class ModesHoverController implements IEditorContribution {
return this._contentWidget;
}
public isColorPickerVisible(): boolean {
return this._contentWidget?.isColorPickerVisible() || false;
}
public showContentHover(range: Range, mode: HoverStartMode, source: HoverStartSource, focus: boolean, activatedByColorDecoratorClick: boolean = false): void {
this._hoverActivatedByColorDecoratorClick = activatedByColorDecoratorClick;
this._getOrCreateContentWidget().startShowingAtRange(range, mode, source, focus);
@ -302,8 +303,12 @@ export class ModesHoverController implements IEditorContribution {
this._contentWidget?.goToBottom();
}
public isHoverVisible(): boolean | undefined {
return this._contentWidget?.isVisible();
public get isColorPickerVisible(): boolean | undefined {
return this._contentWidget?.isColorPickerVisible;
}
public get isHoverVisible(): boolean | undefined {
return this._contentWidget?.isVisible;
}
public dispose(): void {
@ -367,7 +372,7 @@ class ShowOrFocusHoverAction extends EditorAction {
const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column);
const focus = editor.getOption(EditorOption.accessibilitySupport) === AccessibilitySupport.Enabled || !!args?.focus;
if (controller.isHoverVisible()) {
if (controller.isHoverVisible) {
controller.focus();
} else {
controller.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Keyboard, focus);