提交 40a823ba 编写于 作者: A Alex Dima

Make hover delay time configurable (#15667)

上级 a29f4923
...@@ -347,6 +347,11 @@ const editorConfiguration: IConfigurationNode = { ...@@ -347,6 +347,11 @@ const editorConfiguration: IConfigurationNode = {
'default': EDITOR_DEFAULTS.contribInfo.hover.enabled, 'default': EDITOR_DEFAULTS.contribInfo.hover.enabled,
'description': nls.localize('hover.enabled', "Controls if the hover is shown") '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': { 'editor.find.seedSearchStringFromSelection': {
'type': 'boolean', 'type': 'boolean',
'default': EDITOR_DEFAULTS.contribInfo.find.seedSearchStringFromSelection, 'default': EDITOR_DEFAULTS.contribInfo.find.seedSearchStringFromSelection,
......
...@@ -146,6 +146,11 @@ export interface IEditorHoverOptions { ...@@ -146,6 +146,11 @@ export interface IEditorHoverOptions {
* Defaults to true. * Defaults to true.
*/ */
enabled?: boolean; enabled?: boolean;
/**
* Delay for showing the hover.
* Defaults to 300.
*/
delay?: number;
} }
/** /**
...@@ -816,6 +821,7 @@ export interface InternalEditorFindOptions { ...@@ -816,6 +821,7 @@ export interface InternalEditorFindOptions {
export interface InternalEditorHoverOptions { export interface InternalEditorHoverOptions {
readonly enabled: boolean; readonly enabled: boolean;
readonly delay: number;
} }
export interface EditorWrappingInfo { export interface EditorWrappingInfo {
...@@ -1209,6 +1215,7 @@ export class InternalEditorOptions { ...@@ -1209,6 +1215,7 @@ export class InternalEditorOptions {
private static _equalsHoverOptions(a: InternalEditorHoverOptions, b: InternalEditorHoverOptions): boolean { private static _equalsHoverOptions(a: InternalEditorHoverOptions, b: InternalEditorHoverOptions): boolean {
return ( return (
a.enabled === b.enabled a.enabled === b.enabled
&& a.delay === b.delay
); );
} }
...@@ -1694,7 +1701,8 @@ export class EditorOptionsValidator { ...@@ -1694,7 +1701,8 @@ export class EditorOptionsValidator {
} }
return { 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 = { ...@@ -2392,7 +2400,8 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
contribInfo: { contribInfo: {
selectionClipboard: true, selectionClipboard: true,
hover: { hover: {
enabled: true enabled: true,
delay: 300
}, },
links: true, links: true,
contextmenu: true, contextmenu: true,
......
...@@ -10,11 +10,6 @@ import { TPromise } from 'vs/base/common/winjs.base'; ...@@ -10,11 +10,6 @@ import { TPromise } from 'vs/base/common/winjs.base';
export interface IHoverComputer<Result> { export interface IHoverComputer<Result> {
/**
* Overwrite the default hover time
*/
getHoverTimeMillis?: () => number;
/** /**
* This is called after half the hover time * This is called after half the hover time
*/ */
...@@ -57,6 +52,7 @@ export class HoverOperation<Result> { ...@@ -57,6 +52,7 @@ export class HoverOperation<Result> {
private _computer: IHoverComputer<Result>; private _computer: IHoverComputer<Result>;
private _state: ComputeHoverOperationState; private _state: ComputeHoverOperationState;
private _hoverTime: number;
private _firstWaitScheduler: RunOnceScheduler; private _firstWaitScheduler: RunOnceScheduler;
private _secondWaitScheduler: RunOnceScheduler; private _secondWaitScheduler: RunOnceScheduler;
...@@ -71,10 +67,11 @@ export class HoverOperation<Result> { ...@@ -71,10 +67,11 @@ export class HoverOperation<Result> {
constructor(computer: IHoverComputer<Result>, success: (r: Result) => void, error: (err: any) => void, progress: (progress: any) => void) { constructor(computer: IHoverComputer<Result>, success: (r: Result) => void, error: (err: any) => void, progress: (progress: any) => void) {
this._computer = computer; this._computer = computer;
this._state = ComputeHoverOperationState.IDLE; this._state = ComputeHoverOperationState.IDLE;
this._hoverTime = HoverOperation.HOVER_TIME;
this._firstWaitScheduler = new RunOnceScheduler(() => this._triggerAsyncComputation(), this._getHoverTimeMillis() / 2); this._firstWaitScheduler = new RunOnceScheduler(() => this._triggerAsyncComputation(), 0);
this._secondWaitScheduler = new RunOnceScheduler(() => this._triggerSyncComputation(), this._getHoverTimeMillis() / 2); this._secondWaitScheduler = new RunOnceScheduler(() => this._triggerSyncComputation(), 0);
this._loadingMessageScheduler = new RunOnceScheduler(() => this._showLoadingMessage(), 3 * this._getHoverTimeMillis()); this._loadingMessageScheduler = new RunOnceScheduler(() => this._showLoadingMessage(), 0);
this._asyncComputationPromise = null; this._asyncComputationPromise = null;
this._asyncComputationPromiseDone = false; this._asyncComputationPromiseDone = false;
...@@ -84,16 +81,25 @@ export class HoverOperation<Result> { ...@@ -84,16 +81,25 @@ export class HoverOperation<Result> {
this._progressCallback = progress; this._progressCallback = progress;
} }
private _getHoverTimeMillis(): number { public setHoverTime(hoverTime: number): void {
if (this._computer.getHoverTimeMillis) { this._hoverTime = hoverTime;
return this._computer.getHoverTimeMillis(); }
}
return HoverOperation.HOVER_TIME; private _firstWaitTime(): number {
return this._hoverTime / 2;
}
private _secondWaitTime(): number {
return this._hoverTime / 2;
}
private _loadingMessageTime(): number {
return 3 * this._hoverTime;
} }
private _triggerAsyncComputation(): void { private _triggerAsyncComputation(): void {
this._state = ComputeHoverOperationState.SECOND_WAIT; this._state = ComputeHoverOperationState.SECOND_WAIT;
this._secondWaitScheduler.schedule(); this._secondWaitScheduler.schedule(this._secondWaitTime());
if (this._computer.computeAsync) { if (this._computer.computeAsync) {
this._asyncComputationPromiseDone = false; this._asyncComputationPromiseDone = false;
...@@ -161,8 +167,8 @@ export class HoverOperation<Result> { ...@@ -161,8 +167,8 @@ export class HoverOperation<Result> {
if (mode === HoverStartMode.Delayed) { if (mode === HoverStartMode.Delayed) {
if (this._state === ComputeHoverOperationState.IDLE) { if (this._state === ComputeHoverOperationState.IDLE) {
this._state = ComputeHoverOperationState.FIRST_WAIT; this._state = ComputeHoverOperationState.FIRST_WAIT;
this._firstWaitScheduler.schedule(); this._firstWaitScheduler.schedule(this._firstWaitTime());
this._loadingMessageScheduler.schedule(); this._loadingMessageScheduler.schedule(this._loadingMessageTime());
} }
} else { } else {
switch (this._state) { switch (this._state) {
......
...@@ -199,6 +199,9 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -199,6 +199,9 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
this.toDispose.push(dom.addStandardDisposableListener(this.getDomNode(), dom.EventType.BLUR, () => { this.toDispose.push(dom.addStandardDisposableListener(this.getDomNode(), dom.EventType.BLUR, () => {
dom.removeClass(this.getDomNode(), 'colorpicker-hover'); dom.removeClass(this.getDomNode(), 'colorpicker-hover');
})); }));
this.toDispose.push(editor.onDidChangeConfiguration((e) => {
this._hoverOperation.setHoverTime(this._editor.getConfiguration().contribInfo.hover.delay);
}));
} }
dispose(): void { dispose(): void {
......
...@@ -2496,6 +2496,11 @@ declare namespace monaco.editor { ...@@ -2496,6 +2496,11 @@ declare namespace monaco.editor {
* Defaults to true. * Defaults to true.
*/ */
enabled?: boolean; enabled?: boolean;
/**
* Delay for showing the hover.
* Defaults to 300.
*/
delay?: number;
} }
/** /**
...@@ -3095,6 +3100,7 @@ declare namespace monaco.editor { ...@@ -3095,6 +3100,7 @@ declare namespace monaco.editor {
export interface InternalEditorHoverOptions { export interface InternalEditorHoverOptions {
readonly enabled: boolean; readonly enabled: boolean;
readonly delay: number;
} }
export interface EditorWrappingInfo { export interface EditorWrappingInfo {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册