提交 f1abc274 编写于 作者: R Rob Lourens

Fix #19199 - debounce F4/Shift+F4

上级 ddad50c5
......@@ -305,9 +305,9 @@ export function any<T>(...events: Event<T>[]): Event<T> {
return emitter.event;
}
export function debounceEvent<T>(event: Event<T>, merger: (last: T, event: T) => T, delay?: number): Event<T>;
export function debounceEvent<I, O>(event: Event<I>, merger: (last: O, event: I) => O, delay?: number): Event<O>;
export function debounceEvent<I, O>(event: Event<I>, merger: (last: O, event: I) => O, delay: number = 100): Event<O> {
export function debounceEvent<T>(event: Event<T>, merger: (last: T, event: T) => T, delay?: number, leading?: boolean): Event<T>;
export function debounceEvent<I, O>(event: Event<I>, merger: (last: O, event: I) => O, delay?: number, leading?: boolean): Event<O>;
export function debounceEvent<I, O>(event: Event<I>, merger: (last: O, event: I) => O, delay: number = 100, leading = false): Event<O> {
let subscription: IDisposable;
let output: O;
......@@ -317,11 +317,16 @@ export function debounceEvent<I, O>(event: Event<I>, merger: (last: O, event: I)
onFirstListenerAdd() {
subscription = event(cur => {
output = merger(output, cur);
if (!handle && leading) {
emitter.fire(output);
}
clearTimeout(handle);
handle = setTimeout(() => {
let _output = output;
output = undefined;
emitter.fire(_output);
handle = null;
}, delay);
});
},
......
......@@ -276,7 +276,7 @@ export class FocusNextSearchResultAction extends Action {
public run(): TPromise<any> {
return this.viewletService.openViewlet(Constants.VIEWLET_ID).then((searchViewlet: SearchViewlet) => {
searchViewlet.selectNextResult();
searchViewlet.selectNextMatch();
});
}
}
......@@ -291,7 +291,7 @@ export class FocusPreviousSearchResultAction extends Action {
public run(): TPromise<any> {
return this.viewletService.openViewlet(Constants.VIEWLET_ID).then((searchViewlet: SearchViewlet) => {
searchViewlet.selectPreviousResult();
searchViewlet.selectPreviousMatch();
});
}
}
......
......@@ -8,6 +8,7 @@
import 'vs/css!./media/searchviewlet';
import nls = require('vs/nls');
import { TPromise } from 'vs/base/common/winjs.base';
import { Emitter, debounceEvent } from 'vs/base/common/event';
import { EditorType, ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import lifecycle = require('vs/base/common/lifecycle');
import errors = require('vs/base/common/errors');
......@@ -88,6 +89,8 @@ export class SearchViewlet extends Viewlet {
private currentSelectedFileMatch: FileMatch;
private selectCurrentMatchEmitter: Emitter<string>;
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@IFileService private fileService: IFileService,
......@@ -121,6 +124,10 @@ export class SearchViewlet extends Viewlet {
this.toUnbind.push(this.untitledEditorService.onDidChangeDirty(e => this.onUntitledDidChangeDirty(e)));
this.toUnbind.push(this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config)));
this.selectCurrentMatchEmitter = new Emitter<string>();
debounceEvent(this.selectCurrentMatchEmitter.event, (l, e) => e, 100, /*leading=*/true)
(() => this.selectCurrentMatch());
}
private onConfigurationUpdated(configuration: any): void {
......@@ -481,7 +488,10 @@ export class SearchViewlet extends Viewlet {
}
this.currentSelectedFileMatch = selectedMatch.parent();
this.currentSelectedFileMatch.setSelectedMatch(selectedMatch);
this.onFocus(selectedMatch, !focusEditor, sideBySide, doubleClick);
if (!event.payload.preventEditorOpen) {
this.onFocus(selectedMatch, !focusEditor, sideBySide, doubleClick);
}
}
}));
});
......@@ -511,8 +521,13 @@ export class SearchViewlet extends Viewlet {
}
}
public selectNextResult(): void {
public selectCurrentMatch(): void {
const focused = this.tree.getFocus();
const eventPayload = { focusEditor: true };
this.tree.setSelection([focused], eventPayload);
}
public selectNextMatch(): void {
const [selected]: FileMatchOrMatch[] = this.tree.getSelection();
const navigator = this.tree.getNavigator(selected, /*subTreeOnly=*/false);
let next = navigator.next();
......@@ -532,13 +547,14 @@ export class SearchViewlet extends Viewlet {
}
// Reveal the newly selected element
const eventPayload = { preventEditorOpen: true };
this.tree.setFocus(next, eventPayload);
this.tree.setSelection([next], eventPayload);
this.tree.reveal(next);
this.selectCurrentMatchEmitter.fire();
}
public selectPreviousResult(): void {
const eventPayload = { focusEditor: true };
public selectPreviousMatch(): void {
const [selected]: FileMatchOrMatch[] = this.tree.getSelection();
const navigator = this.tree.getNavigator(selected, /*subTreeOnly=*/false);
......@@ -561,9 +577,11 @@ export class SearchViewlet extends Viewlet {
// Reveal the newly selected element
if (prev) {
const eventPayload = { preventEditorOpen: true };
this.tree.setFocus(prev, eventPayload);
this.tree.setSelection([prev], eventPayload);
this.tree.reveal(prev);
this.selectCurrentMatchEmitter.fire();
}
}
......@@ -1136,7 +1154,9 @@ export class SearchViewlet extends Viewlet {
this.telemetryService.publicLog('searchResultChosen');
return (this.viewModel.isReplaceActive() && !!this.viewModel.replaceString) ? this.replaceService.openReplacePreview(lineMatch, preserveFocus, sideBySide, pinned) : this.open(lineMatch, preserveFocus, sideBySide, pinned);
return (this.viewModel.isReplaceActive() && !!this.viewModel.replaceString) ?
this.replaceService.openReplacePreview(lineMatch, preserveFocus, sideBySide, pinned) :
this.open(lineMatch, preserveFocus, sideBySide, pinned);
}
public open(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册