未验证 提交 aa8f371e 编写于 作者: A Alexandru Dima 提交者: GitHub

Merge pull request #52147 from LeonardoBraga/fixes-persistent-hover-manually-triggered

Fixes stuck hover widget when triggered manually, with "editor.hover": false
......@@ -13,7 +13,8 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IModeService } from 'vs/editor/common/services/modeService';
import { Range } from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IEditorContribution, IScrollEvent } from 'vs/editor/common/editorCommon';
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
import { registerEditorAction, registerEditorContribution, ServicesAccessor, EditorAction } from 'vs/editor/browser/editorExtensions';
import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser';
import { ModesContentHoverWidget } from './modesContentHover';
......@@ -26,12 +27,12 @@ import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
import { IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget';
import { HoverStartMode } from 'vs/editor/contrib/hover/hoverOperation';
export class ModesHoverController implements editorCommon.IEditorContribution {
export class ModesHoverController implements IEditorContribution {
private static readonly ID = 'editor.contrib.hover';
private _editor: ICodeEditor;
private _toUnhook: IDisposable[];
private _didChangeConfigurationHandler: IDisposable;
private _contentWidget: ModesContentHoverWidget;
private _glyphWidget: ModesGlyphHoverWidget;
......@@ -52,35 +53,54 @@ export class ModesHoverController implements editorCommon.IEditorContribution {
private _isMouseDown: boolean;
private _hoverClicked: boolean;
private _isHoverEnabled: boolean;
static get(editor: ICodeEditor): ModesHoverController {
return editor.getContribution<ModesHoverController>(ModesHoverController.ID);
}
constructor(editor: ICodeEditor,
constructor(private readonly _editor: ICodeEditor,
@IOpenerService private readonly _openerService: IOpenerService,
@IModeService private readonly _modeService: IModeService,
@IThemeService private readonly _themeService: IThemeService
) {
this._editor = editor;
this._toUnhook = [];
this._isMouseDown = false;
this._hoverClicked = false;
this._hookEvents();
this._didChangeConfigurationHandler = this._editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => {
if (e.contribInfo) {
this._hideWidgets();
this._unhookEvents();
this._hookEvents();
}
});
}
private _hookEvents(): void {
const hideWidgetsEventHandler = () => this._hideWidgets();
if (editor.getConfiguration().contribInfo.hover) {
this._isHoverEnabled = this._editor.getConfiguration().contribInfo.hover.enabled;
if (this._isHoverEnabled) {
this._toUnhook.push(this._editor.onMouseDown((e: IEditorMouseEvent) => this._onEditorMouseDown(e)));
this._toUnhook.push(this._editor.onMouseUp((e: IEditorMouseEvent) => this._onEditorMouseUp(e)));
this._toUnhook.push(this._editor.onMouseMove((e: IEditorMouseEvent) => this._onEditorMouseMove(e)));
this._toUnhook.push(this._editor.onMouseLeave((e: IEditorMouseEvent) => this._hideWidgets()));
this._toUnhook.push(this._editor.onKeyDown((e: IKeyboardEvent) => this._onKeyDown(e)));
this._toUnhook.push(this._editor.onDidChangeModel(() => this._hideWidgets()));
this._toUnhook.push(this._editor.onDidChangeModelDecorations(() => this._onModelDecorationsChanged()));
this._toUnhook.push(this._editor.onDidScrollChange((e) => {
if (e.scrollTopChanged || e.scrollLeftChanged) {
this._hideWidgets();
}
}));
} else {
this._toUnhook.push(this._editor.onMouseMove(hideWidgetsEventHandler));
}
this._toUnhook.push(this._editor.onMouseLeave(hideWidgetsEventHandler));
this._toUnhook.push(this._editor.onDidChangeModel(hideWidgetsEventHandler));
this._toUnhook.push(this._editor.onDidScrollChange((e: IScrollEvent) => this._onEditorScrollChanged(e)));
}
private _unhookEvents(): void {
this._toUnhook = dispose(this._toUnhook);
}
private _onModelDecorationsChanged(): void {
......@@ -88,6 +108,12 @@ export class ModesHoverController implements editorCommon.IEditorContribution {
this.glyphWidget.onModelDecorationsChanged();
}
private _onEditorScrollChanged(e: IScrollEvent): void {
if (e.scrollTopChanged || e.scrollLeftChanged) {
this._hideWidgets();
}
}
private _onEditorMouseDown(mouseEvent: IEditorMouseEvent): void {
this._isMouseDown = true;
......@@ -142,12 +168,18 @@ export class ModesHoverController implements editorCommon.IEditorContribution {
}
}
if (this._editor.getConfiguration().contribInfo.hover && targetType === MouseTargetType.CONTENT_TEXT) {
if (targetType === MouseTargetType.CONTENT_TEXT) {
this.glyphWidget.hide();
this.contentWidget.startShowingAt(mouseEvent.target.range, HoverStartMode.Delayed, false);
if (this._isHoverEnabled) {
this.contentWidget.startShowingAt(mouseEvent.target.range, HoverStartMode.Delayed, false);
}
} else if (targetType === MouseTargetType.GUTTER_GLYPH_MARGIN) {
this.contentWidget.hide();
this.glyphWidget.startShowingAt(mouseEvent.target.position.lineNumber);
if (this._isHoverEnabled) {
this.glyphWidget.startShowingAt(mouseEvent.target.position.lineNumber);
}
} else {
this._hideWidgets();
}
......@@ -184,7 +216,9 @@ export class ModesHoverController implements editorCommon.IEditorContribution {
}
public dispose(): void {
this._toUnhook = dispose(this._toUnhook);
this._unhookEvents();
this._didChangeConfigurationHandler.dispose();
if (this._glyphWidget) {
this._glyphWidget.dispose();
this._glyphWidget = null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册