Pressing alt/opt makes the hover temporarily sticky (#236356)
* add alt key to make hover temporarily sticky * adding codepull/236360/head
parent
206033fd3f
commit
317d55da7b
|
@ -4,8 +4,8 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { DECREASE_HOVER_VERBOSITY_ACTION_ID, INCREASE_HOVER_VERBOSITY_ACTION_ID, SHOW_OR_FOCUS_HOVER_ACTION_ID } from './hoverActionIds.js';
|
||||
import { IKeyboardEvent } from '../../../../base/browser/keyboardEvent.js';
|
||||
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
|
||||
import { IKeyboardEvent, StandardKeyboardEvent } from '../../../../base/browser/keyboardEvent.js';
|
||||
import { Disposable, DisposableStore, toDisposable } from '../../../../base/common/lifecycle.js';
|
||||
import { ICodeEditor, IEditorMouseEvent, IPartialEditorMouseEvent } from '../../../browser/editorBrowser.js';
|
||||
import { ConfigurationChangedEvent, EditorOption } from '../../../common/config/editorOptions.js';
|
||||
import { Range } from '../../../common/core/range.js';
|
||||
|
@ -22,6 +22,9 @@ import { ContentHoverWidgetWrapper } from './contentHoverWidgetWrapper.js';
|
|||
import './hover.css';
|
||||
import { Emitter } from '../../../../base/common/event.js';
|
||||
import { isOnColorDecorator } from '../../colorPicker/browser/hoverColorPicker/hoverColorPicker.js';
|
||||
import { KeyCode } from '../../../../base/common/keyCodes.js';
|
||||
import { EventType } from '../../../../base/browser/dom.js';
|
||||
import { mainWindow } from '../../../../base/browser/window.js';
|
||||
|
||||
// sticky hover widget which doesn't disappear on focus out and such
|
||||
const _sticky = false
|
||||
|
@ -92,11 +95,18 @@ export class ContentHoverController extends Disposable implements IEditorContrib
|
|||
this._listenersStore.add(this._editor.onMouseDown((e: IEditorMouseEvent) => this._onEditorMouseDown(e)));
|
||||
this._listenersStore.add(this._editor.onMouseUp(() => this._onEditorMouseUp()));
|
||||
this._listenersStore.add(this._editor.onMouseMove((e: IEditorMouseEvent) => this._onEditorMouseMove(e)));
|
||||
this._listenersStore.add(this._editor.onKeyDown((e: IKeyboardEvent) => this._onKeyDown(e)));
|
||||
this._listenersStore.add(this._editor.onMouseLeave((e) => this._onEditorMouseLeave(e)));
|
||||
this._listenersStore.add(this._editor.onDidChangeModel(() => this._cancelSchedulerAndHide()));
|
||||
this._listenersStore.add(this._editor.onDidChangeModelContent(() => this._cancelScheduler()));
|
||||
this._listenersStore.add(this._editor.onDidScrollChange((e: IScrollEvent) => this._onEditorScrollChanged(e)));
|
||||
const keyDownListener = (e: KeyboardEvent) => this._onKeyDown(e);
|
||||
const keyUpListener = (e: KeyboardEvent) => this._onKeyUp(e);
|
||||
mainWindow.addEventListener(EventType.KEY_DOWN, keyDownListener);
|
||||
mainWindow.addEventListener(EventType.KEY_UP, keyUpListener);
|
||||
this._listenersStore.add(toDisposable(() => {
|
||||
mainWindow.removeEventListener(EventType.KEY_DOWN, keyDownListener);
|
||||
mainWindow.removeEventListener(EventType.KEY_UP, keyUpListener);
|
||||
}));
|
||||
}
|
||||
|
||||
private _unhookListeners(): void {
|
||||
|
@ -155,6 +165,9 @@ export class ContentHoverController extends Disposable implements IEditorContrib
|
|||
if (_sticky) {
|
||||
return;
|
||||
}
|
||||
if (this._contentWidget) {
|
||||
this._contentWidget.temporarilySticky = false;
|
||||
}
|
||||
this.hideContentHover();
|
||||
}
|
||||
|
||||
|
@ -234,17 +247,31 @@ export class ContentHoverController extends Disposable implements IEditorContrib
|
|||
this.hideContentHover();
|
||||
}
|
||||
|
||||
private _onKeyDown(e: IKeyboardEvent): void {
|
||||
if (!this._editor.hasModel()) {
|
||||
private _onKeyDown(e: KeyboardEvent): void {
|
||||
if (!this._contentWidget) {
|
||||
return;
|
||||
}
|
||||
const isPotentialKeyboardShortcut = this._isPotentialKeyboardShortcut(e);
|
||||
const event = new StandardKeyboardEvent(e);
|
||||
if (event.keyCode === KeyCode.Alt) {
|
||||
this._contentWidget.temporarilySticky = true;
|
||||
}
|
||||
const isPotentialKeyboardShortcut = this._isPotentialKeyboardShortcut(event);
|
||||
if (isPotentialKeyboardShortcut) {
|
||||
return;
|
||||
}
|
||||
this.hideContentHover();
|
||||
}
|
||||
|
||||
private _onKeyUp(e: KeyboardEvent): void {
|
||||
if (!this._contentWidget) {
|
||||
return;
|
||||
}
|
||||
const event = new StandardKeyboardEvent(e);
|
||||
if (event.keyCode === KeyCode.Alt) {
|
||||
this._contentWidget.temporarilySticky = false;
|
||||
}
|
||||
}
|
||||
|
||||
private _isPotentialKeyboardShortcut(e: IKeyboardEvent): boolean {
|
||||
if (!this._editor.hasModel() || !this._contentWidget) {
|
||||
return false;
|
||||
|
|
|
@ -27,6 +27,7 @@ export class ContentHoverWidgetWrapper extends Disposable implements IHoverWidge
|
|||
|
||||
private _currentResult: ContentHoverResult | null = null;
|
||||
private _renderedContentHover: RenderedContentHover | undefined;
|
||||
private _temporarilySticky: boolean = false;
|
||||
|
||||
private readonly _contentHoverWidget: ContentHoverWidget;
|
||||
private readonly _participants: IEditorHoverParticipant[];
|
||||
|
@ -162,11 +163,25 @@ export class ContentHoverWidgetWrapper extends Disposable implements IHoverWidge
|
|||
if (currentHoverResultIsEmpty) {
|
||||
currentHoverResult = null;
|
||||
}
|
||||
const hoverVisible = this._contentHoverWidget.isVisible;
|
||||
if (!hoverVisible) {
|
||||
this._renderResult(currentHoverResult);
|
||||
} else {
|
||||
if (this._temporarilySticky) {
|
||||
return;
|
||||
} else {
|
||||
this._renderResult(currentHoverResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _renderResult(currentHoverResult: ContentHoverResult | null): void {
|
||||
this._currentResult = currentHoverResult;
|
||||
if (this._currentResult) {
|
||||
this._showHover(this._currentResult);
|
||||
} else {
|
||||
this._hideHover();
|
||||
this._contentHoverWidget.hide();
|
||||
this._participants.forEach(participant => participant.handleHide?.());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,11 +230,6 @@ export class ContentHoverWidgetWrapper extends Disposable implements IHoverWidge
|
|||
}
|
||||
}
|
||||
|
||||
private _hideHover(): void {
|
||||
this._contentHoverWidget.hide();
|
||||
this._participants.forEach(participant => participant.handleHide?.());
|
||||
}
|
||||
|
||||
private _getHoverContext(): IEditorHoverContext {
|
||||
const hide = () => {
|
||||
this.hide();
|
||||
|
@ -293,6 +303,10 @@ export class ContentHoverWidgetWrapper extends Disposable implements IHoverWidge
|
|||
}
|
||||
}
|
||||
|
||||
public set temporarilySticky(value: boolean) {
|
||||
this._temporarilySticky = value;
|
||||
}
|
||||
|
||||
public startShowingAtRange(range: Range, mode: HoverStartMode, source: HoverStartSource, focus: boolean): void {
|
||||
this._startShowingOrUpdateHover(new HoverRangeAnchor(0, range, undefined, undefined), mode, source, focus, null);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue