From 82ff5c5e529fa78524240a0c33137105944c617d Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 23 Dec 2015 13:48:44 +0000 Subject: [PATCH] Factor out handleTabPress and remove passive flag onKeyDown --- src/TabComplete.js | 61 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/TabComplete.js b/src/TabComplete.js index fb2571a8f8..334c9a93ab 100644 --- a/src/TabComplete.js +++ b/src/TabComplete.js @@ -132,12 +132,38 @@ class TabComplete { return peekList; } + handleTabPress(passive, shiftKey) { + var wasInPassiveMode = this.inPassiveMode && !passive; + console.log( + "handleTabPress passive=%s, shift=%s wasPassive=%s", + passive, shiftKey, wasInPassiveMode + ); + this.inPassiveMode = passive; + + if (!this.completing) { + this.startTabCompleting(); + } + + if (shiftKey) { + this.nextMatchedEntry(-1); + } + else { + // if we were in passive mode we got out of sync by incrementing the + // index to show the peek view but not set the text area. Therefore, + // we want to set the *current* index rather than the *next* index. + this.nextMatchedEntry(wasInPassiveMode ? 0 : 1); + } + this._notifyStateChange(); + } + /** * @param {DOMEvent} e */ onKeyDown(ev) { - var wasInPassiveMode = this.inPassiveMode && !ev.passive; - this.inPassiveMode = ev.passive; + if (!this.textArea) { + console.error("onKeyDown called before a