提交 a29f4923 编写于 作者: A Alex Dima

Show hover from action immediately (#15667)

上级 6d8e8f2f
......@@ -24,6 +24,7 @@ import { editorHoverHighlight, editorHoverBackground, editorHoverBorder, textLin
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
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 {
......@@ -143,7 +144,7 @@ export class ModesHoverController implements editorCommon.IEditorContribution {
if (this._editor.getConfiguration().contribInfo.hover && targetType === MouseTargetType.CONTENT_TEXT) {
this.glyphWidget.hide();
this.contentWidget.startShowingAt(mouseEvent.target.range, false);
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);
......@@ -174,8 +175,8 @@ export class ModesHoverController implements editorCommon.IEditorContribution {
this._glyphWidget = new ModesGlyphHoverWidget(this._editor, renderer);
}
public showContentHover(range: Range, focus: boolean): void {
this.contentWidget.startShowingAt(range, focus);
public showContentHover(range: Range, mode: HoverStartMode, focus: boolean): void {
this.contentWidget.startShowingAt(range, mode, focus);
}
public getId(): string {
......@@ -223,7 +224,7 @@ class ShowHoverAction extends EditorAction {
}
const position = editor.getPosition();
const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column);
controller.showContentHover(range, true);
controller.showContentHover(range, HoverStartMode.Immediate, true);
}
}
......
......@@ -46,6 +46,11 @@ const enum ComputeHoverOperationState {
WAITING_FOR_ASYNC_COMPUTATION = 3
}
export const enum HoverStartMode {
Delayed = 0,
Immediate = 1
}
export class HoverOperation<Result> {
static HOVER_TIME = 300;
......@@ -152,11 +157,25 @@ export class HoverOperation<Result> {
}
}
public start(): void {
if (this._state === ComputeHoverOperationState.IDLE) {
this._state = ComputeHoverOperationState.FIRST_WAIT;
this._firstWaitScheduler.schedule();
this._loadingMessageScheduler.schedule();
public start(mode: HoverStartMode): void {
if (mode === HoverStartMode.Delayed) {
if (this._state === ComputeHoverOperationState.IDLE) {
this._state = ComputeHoverOperationState.FIRST_WAIT;
this._firstWaitScheduler.schedule();
this._loadingMessageScheduler.schedule();
}
} else {
switch (this._state) {
case ComputeHoverOperationState.IDLE:
this._triggerAsyncComputation();
this._secondWaitScheduler.cancel();
this._triggerSyncComputation();
break;
case ComputeHoverOperationState.SECOND_WAIT:
this._secondWaitScheduler.cancel();
this._triggerSyncComputation();
break;
}
}
}
......
......@@ -12,7 +12,7 @@ import { Position } from 'vs/editor/common/core/position';
import { HoverProviderRegistry, Hover, IColor, DocumentColorProvider } from 'vs/editor/common/modes';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { getHover } from 'vs/editor/contrib/hover/getHover';
import { HoverOperation, IHoverComputer } from './hoverOperation';
import { HoverOperation, IHoverComputer, HoverStartMode } from './hoverOperation';
import { ContentHoverWidget } from './hoverWidgets';
import { IMarkdownString, MarkdownString, isEmptyMarkdownString, markedStringsEquals } from 'vs/base/common/htmlContent';
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
......@@ -220,12 +220,12 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
this._computer.clearResult();
if (!this._colorPicker) { // TODO@Michel ensure that displayed text for other decorations is computed even if color picker is in place
this._hoverOperation.start();
this._hoverOperation.start(HoverStartMode.Delayed);
}
}
}
startShowingAt(range: Range, focus: boolean): void {
startShowingAt(range: Range, mode: HoverStartMode, focus: boolean): void {
if (this._lastRange && this._lastRange.equalsRange(range)) {
// We have to show the widget at the exact same range as before, so no work is needed
return;
......@@ -262,7 +262,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
this._lastRange = range;
this._computer.setRange(range);
this._shouldFocus = focus;
this._hoverOperation.start();
this._hoverOperation.start(mode);
}
hide(): void {
......
......@@ -5,7 +5,7 @@
'use strict';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { HoverOperation, IHoverComputer } from './hoverOperation';
import { HoverOperation, IHoverComputer, HoverStartMode } from './hoverOperation';
import { GlyphHoverWidget } from './hoverWidgets';
import { $ } from 'vs/base/browser/dom';
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
......@@ -123,7 +123,7 @@ export class ModesGlyphHoverWidget extends GlyphHoverWidget {
// we need to recompute the displayed text
this._hoverOperation.cancel();
this._computer.clearResult();
this._hoverOperation.start();
this._hoverOperation.start(HoverStartMode.Delayed);
}
}
......@@ -139,7 +139,7 @@ export class ModesGlyphHoverWidget extends GlyphHoverWidget {
this._lastLineNumber = lineNumber;
this._computer.setLineNumber(lineNumber);
this._hoverOperation.start();
this._hoverOperation.start(HoverStartMode.Delayed);
}
public hide(): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册