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

Make hover delay time configurable (#15667)

上级 a29f4923
......@@ -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,
......
......@@ -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,
......
......@@ -10,11 +10,6 @@ import { TPromise } from 'vs/base/common/winjs.base';
export interface IHoverComputer<Result> {
/**
* Overwrite the default hover time
*/
getHoverTimeMillis?: () => number;
/**
* This is called after half the hover time
*/
......@@ -57,6 +52,7 @@ export class HoverOperation<Result> {
private _computer: IHoverComputer<Result>;
private _state: ComputeHoverOperationState;
private _hoverTime: number;
private _firstWaitScheduler: RunOnceScheduler;
private _secondWaitScheduler: RunOnceScheduler;
......@@ -71,10 +67,11 @@ export class HoverOperation<Result> {
constructor(computer: IHoverComputer<Result>, 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<Result> {
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<Result> {
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) {
......
......@@ -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 {
......
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册