From a29f49235dc510753038b4877152a451e30d4a42 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 22 Jun 2018 14:08:45 +0200 Subject: [PATCH] Show hover from action immediately (#15667) --- src/vs/editor/contrib/hover/hover.ts | 9 +++--- src/vs/editor/contrib/hover/hoverOperation.ts | 29 +++++++++++++++---- .../editor/contrib/hover/modesContentHover.ts | 8 ++--- .../editor/contrib/hover/modesGlyphHover.ts | 6 ++-- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/vs/editor/contrib/hover/hover.ts b/src/vs/editor/contrib/hover/hover.ts index 1fdad70ae85..ddbc96953b3 100644 --- a/src/vs/editor/contrib/hover/hover.ts +++ b/src/vs/editor/contrib/hover/hover.ts @@ -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); } } diff --git a/src/vs/editor/contrib/hover/hoverOperation.ts b/src/vs/editor/contrib/hover/hoverOperation.ts index 432f7107116..3fdc36ff02f 100644 --- a/src/vs/editor/contrib/hover/hoverOperation.ts +++ b/src/vs/editor/contrib/hover/hoverOperation.ts @@ -46,6 +46,11 @@ const enum ComputeHoverOperationState { WAITING_FOR_ASYNC_COMPUTATION = 3 } +export const enum HoverStartMode { + Delayed = 0, + Immediate = 1 +} + export class HoverOperation { static HOVER_TIME = 300; @@ -152,11 +157,25 @@ export class HoverOperation { } } - 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; + } } } diff --git a/src/vs/editor/contrib/hover/modesContentHover.ts b/src/vs/editor/contrib/hover/modesContentHover.ts index bb029b40ded..d8a23d854fd 100644 --- a/src/vs/editor/contrib/hover/modesContentHover.ts +++ b/src/vs/editor/contrib/hover/modesContentHover.ts @@ -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 { diff --git a/src/vs/editor/contrib/hover/modesGlyphHover.ts b/src/vs/editor/contrib/hover/modesGlyphHover.ts index c1844e2e33e..535aab4a250 100644 --- a/src/vs/editor/contrib/hover/modesGlyphHover.ts +++ b/src/vs/editor/contrib/hover/modesGlyphHover.ts @@ -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 { -- GitLab