From 357c6dca0143bc3316e6d84e88bd56bfc1bd46ba Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 18 Jan 2016 22:34:27 +0200 Subject: [PATCH] Fixes #2068: Update find and replace strings in state on `input` event --- src/vs/base/browser/ui/findinput/findInput.ts | 4 ++++ src/vs/editor/contrib/find/browser/findWidget.ts | 15 ++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/vs/base/browser/ui/findinput/findInput.ts b/src/vs/base/browser/ui/findinput/findInput.ts index 7c770764ca2..1ea38c09171 100644 --- a/src/vs/base/browser/ui/findinput/findInput.ts +++ b/src/vs/base/browser/ui/findinput/findInput.ts @@ -61,6 +61,9 @@ export class FindInput extends Widget { private _onKeyDown = this._register(new Emitter()); public onKeyDown: Event = this._onKeyDown.event; + private _onInput = this._register(new Emitter()); + public onInput: Event = this._onInput.event; + private _onKeyUp = this._register(new Emitter()); public onKeyUp: Event = this._onKeyUp.event; @@ -89,6 +92,7 @@ export class FindInput extends Widget { this.onkeydown(this.inputBox.inputElement, (e) => this._onKeyDown.fire(e)); this.onkeyup(this.inputBox.inputElement, (e) => this._onKeyUp.fire(e)); + this.oninput(this.inputBox.inputElement, (e) => this._onInput.fire()); } public enable(): void { diff --git a/src/vs/editor/contrib/find/browser/findWidget.ts b/src/vs/editor/contrib/find/browser/findWidget.ts index df1747714b0..766ad026209 100644 --- a/src/vs/editor/contrib/find/browser/findWidget.ts +++ b/src/vs/editor/contrib/find/browser/findWidget.ts @@ -316,11 +316,6 @@ export class FindWidget extends Widget implements EditorBrowser.IOverlayWidget { e.preventDefault(); return; } - - // getValue() is not updated right away - setTimeout(() => { - this._state.change({ searchString: this._findInput.getValue() }, true); - }, 10); } private _onReplaceInputKeyDown(e:DomUtils.IKeyboardEvent): void { @@ -351,10 +346,6 @@ export class FindWidget extends Widget implements EditorBrowser.IOverlayWidget { e.preventDefault(); return; } - - setTimeout(() => { - this._state.change({ replaceString: this._replaceInputBox.value }, false); - }, 10); } // ----- initialization @@ -392,6 +383,9 @@ export class FindWidget extends Widget implements EditorBrowser.IOverlayWidget { } })); this._register(this._findInput.onKeyDown((e) => this._onFindInputKeyDown(e))); + this._register(this._findInput.onInput(() => { + this._state.change({ searchString: this._findInput.getValue() }, true); + })); this._register(this._findInput.onDidOptionChange(() => { this._state.change({ isRegex: this._findInput.getRegex(), @@ -484,6 +478,9 @@ export class FindWidget extends Widget implements EditorBrowser.IOverlayWidget { })); this._register(DomUtils.addStandardDisposableListener(this._replaceInputBox.inputElement, 'keydown', (e) => this._onReplaceInputKeyDown(e))); + this._register(DomUtils.addStandardDisposableListener(this._replaceInputBox.inputElement, 'input', (e) => { + this._state.change({ replaceString: this._replaceInputBox.value }, false); + })); // Replace one button this._replaceBtn = this._register(new SimpleButton({