diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 73ca10fd3cd1791c16f85074a5af4b428381ae84..7a327a52752827386eaf48e9b5472d5572cd8fdc 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -347,6 +347,11 @@ const editorConfiguration: IConfigurationNode = { 'default': EDITOR_DEFAULTS.contribInfo.hover.enabled, 'description': nls.localize('hover.enabled', "Controls if the hover is shown") }, + 'editor.hover.delay': { + 'type': 'number', + 'default': EDITOR_DEFAULTS.contribInfo.hover.delay, + 'description': nls.localize('hover.delay', "Controls the delay after which to show the hover") + }, 'editor.find.seedSearchStringFromSelection': { 'type': 'boolean', 'default': EDITOR_DEFAULTS.contribInfo.find.seedSearchStringFromSelection, diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index da1276644d050763ff1bfda752d41143280c421c..7e20281925b2fbfc52799f4f715f72827f4765e2 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -146,6 +146,11 @@ export interface IEditorHoverOptions { * Defaults to true. */ enabled?: boolean; + /** + * Delay for showing the hover. + * Defaults to 300. + */ + delay?: number; } /** @@ -816,6 +821,7 @@ export interface InternalEditorFindOptions { export interface InternalEditorHoverOptions { readonly enabled: boolean; + readonly delay: number; } export interface EditorWrappingInfo { @@ -1209,6 +1215,7 @@ export class InternalEditorOptions { private static _equalsHoverOptions(a: InternalEditorHoverOptions, b: InternalEditorHoverOptions): boolean { return ( a.enabled === b.enabled + && a.delay === b.delay ); } @@ -1694,7 +1701,8 @@ export class EditorOptionsValidator { } return { - enabled: _boolean(opts.enabled, defaults.enabled) + enabled: _boolean(opts.enabled, defaults.enabled), + delay: _clampedInt(opts.delay, defaults.delay, 0, 10000) }; } @@ -2392,7 +2400,8 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { contribInfo: { selectionClipboard: true, hover: { - enabled: true + enabled: true, + delay: 300 }, links: true, contextmenu: true, diff --git a/src/vs/editor/contrib/hover/hoverOperation.ts b/src/vs/editor/contrib/hover/hoverOperation.ts index 3fdc36ff02fd44a17bdee2c37600aef4b968dd62..fa6b0e949d1e907d473f4d81bda163eebbfa9f8b 100644 --- a/src/vs/editor/contrib/hover/hoverOperation.ts +++ b/src/vs/editor/contrib/hover/hoverOperation.ts @@ -10,11 +10,6 @@ import { TPromise } from 'vs/base/common/winjs.base'; export interface IHoverComputer { - /** - * Overwrite the default hover time - */ - getHoverTimeMillis?: () => number; - /** * This is called after half the hover time */ @@ -57,6 +52,7 @@ export class HoverOperation { private _computer: IHoverComputer; private _state: ComputeHoverOperationState; + private _hoverTime: number; private _firstWaitScheduler: RunOnceScheduler; private _secondWaitScheduler: RunOnceScheduler; @@ -71,10 +67,11 @@ export class HoverOperation { constructor(computer: IHoverComputer, success: (r: Result) => void, error: (err: any) => void, progress: (progress: any) => void) { this._computer = computer; this._state = ComputeHoverOperationState.IDLE; + this._hoverTime = HoverOperation.HOVER_TIME; - this._firstWaitScheduler = new RunOnceScheduler(() => this._triggerAsyncComputation(), this._getHoverTimeMillis() / 2); - this._secondWaitScheduler = new RunOnceScheduler(() => this._triggerSyncComputation(), this._getHoverTimeMillis() / 2); - this._loadingMessageScheduler = new RunOnceScheduler(() => this._showLoadingMessage(), 3 * this._getHoverTimeMillis()); + this._firstWaitScheduler = new RunOnceScheduler(() => this._triggerAsyncComputation(), 0); + this._secondWaitScheduler = new RunOnceScheduler(() => this._triggerSyncComputation(), 0); + this._loadingMessageScheduler = new RunOnceScheduler(() => this._showLoadingMessage(), 0); this._asyncComputationPromise = null; this._asyncComputationPromiseDone = false; @@ -84,16 +81,25 @@ export class HoverOperation { this._progressCallback = progress; } - private _getHoverTimeMillis(): number { - if (this._computer.getHoverTimeMillis) { - return this._computer.getHoverTimeMillis(); - } - return HoverOperation.HOVER_TIME; + public setHoverTime(hoverTime: number): void { + this._hoverTime = hoverTime; + } + + private _firstWaitTime(): number { + return this._hoverTime / 2; + } + + private _secondWaitTime(): number { + return this._hoverTime / 2; + } + + private _loadingMessageTime(): number { + return 3 * this._hoverTime; } private _triggerAsyncComputation(): void { this._state = ComputeHoverOperationState.SECOND_WAIT; - this._secondWaitScheduler.schedule(); + this._secondWaitScheduler.schedule(this._secondWaitTime()); if (this._computer.computeAsync) { this._asyncComputationPromiseDone = false; @@ -161,8 +167,8 @@ export class HoverOperation { if (mode === HoverStartMode.Delayed) { if (this._state === ComputeHoverOperationState.IDLE) { this._state = ComputeHoverOperationState.FIRST_WAIT; - this._firstWaitScheduler.schedule(); - this._loadingMessageScheduler.schedule(); + this._firstWaitScheduler.schedule(this._firstWaitTime()); + this._loadingMessageScheduler.schedule(this._loadingMessageTime()); } } else { switch (this._state) { diff --git a/src/vs/editor/contrib/hover/modesContentHover.ts b/src/vs/editor/contrib/hover/modesContentHover.ts index d8a23d854fd74afe498af06dd963a2bd81e18476..af946d803c91f71219bb2215b53bb93bf426cb0f 100644 --- a/src/vs/editor/contrib/hover/modesContentHover.ts +++ b/src/vs/editor/contrib/hover/modesContentHover.ts @@ -199,6 +199,9 @@ export class ModesContentHoverWidget extends ContentHoverWidget { this.toDispose.push(dom.addStandardDisposableListener(this.getDomNode(), dom.EventType.BLUR, () => { dom.removeClass(this.getDomNode(), 'colorpicker-hover'); })); + this.toDispose.push(editor.onDidChangeConfiguration((e) => { + this._hoverOperation.setHoverTime(this._editor.getConfiguration().contribInfo.hover.delay); + })); } dispose(): void { diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 693de61b9f24acdb7ebd369d4879a41802938514..bbf5b00e602ff98fa87d68b8abaf357fd25afa4a 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2496,6 +2496,11 @@ declare namespace monaco.editor { * Defaults to true. */ enabled?: boolean; + /** + * Delay for showing the hover. + * Defaults to 300. + */ + delay?: number; } /** @@ -3095,6 +3100,7 @@ declare namespace monaco.editor { export interface InternalEditorHoverOptions { readonly enabled: boolean; + readonly delay: number; } export interface EditorWrappingInfo {