From 4a90f262c65ce104b7ef32dfb9d3c3c6be2b304c Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 15:34:40 +0000 Subject: [PATCH 1/2] fix zero length tab complete behaviour --- src/TabComplete.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/TabComplete.js b/src/TabComplete.js index 3005411e13..c82d8e4644 100644 --- a/src/TabComplete.js +++ b/src/TabComplete.js @@ -83,10 +83,10 @@ class TabComplete { this._notifyStateChange(); } - startTabCompleting() { + startTabCompleting(passive) { this.completing = true; this.currentIndex = 0; - this._calculateCompletions(); + this._calculateCompletions(passive); } /** @@ -137,7 +137,7 @@ class TabComplete { this.inPassiveMode = passive; if (!this.completing) { - this.startTabCompleting(); + this.startTabCompleting(passive); } if (shiftKey) { @@ -270,7 +270,7 @@ class TabComplete { }); } - _calculateCompletions() { + _calculateCompletions(passive) { this.originalText = this.textArea.value; // cache starting text // grab the partial word from the text which we'll be tab-completing @@ -283,6 +283,11 @@ class TabComplete { var [ , boundaryGroup, partialGroup] = res; this.isFirstWord = partialGroup.length === this.originalText.length; + if (partialGroup.length === 0 && passive) { + this.stopTabCompleting(); + return; + } + this.matchedList = [ new Entry(partialGroup) // first entry is always the original partial ]; From 42479cf011b9566b8a91017a805aad535b0f4401 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 16:46:54 +0000 Subject: [PATCH 2/2] PR feedback --- src/TabComplete.js | 63 ++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/src/TabComplete.js b/src/TabComplete.js index c82d8e4644..0cf6e1948a 100644 --- a/src/TabComplete.js +++ b/src/TabComplete.js @@ -84,9 +84,38 @@ class TabComplete { } startTabCompleting(passive) { + this.originalText = this.textArea.value; // cache starting text + + // grab the partial word from the text which we'll be tab-completing + var res = MATCH_REGEX.exec(this.originalText); + if (!res) { + this.matchedList = []; + return; + } + // ES6 destructuring; ignore first element (the complete match) + var [ , boundaryGroup, partialGroup] = res; + + if (partialGroup.length === 0 && passive) { + return; + } + + this.isFirstWord = partialGroup.length === this.originalText.length; + this.completing = true; this.currentIndex = 0; - this._calculateCompletions(passive); + + this.matchedList = [ + new Entry(partialGroup) // first entry is always the original partial + ]; + + // find matching entries in the set of entries given to us + this.list.forEach((entry) => { + if (entry.text.toLowerCase().indexOf(partialGroup.toLowerCase()) === 0) { + this.matchedList.push(entry); + } + }); + + // console.log("calculated completions => %s", JSON.stringify(this.matchedList)); } /** @@ -270,38 +299,6 @@ class TabComplete { }); } - _calculateCompletions(passive) { - this.originalText = this.textArea.value; // cache starting text - - // grab the partial word from the text which we'll be tab-completing - var res = MATCH_REGEX.exec(this.originalText); - if (!res) { - this.matchedList = []; - return; - } - // ES6 destructuring; ignore first element (the complete match) - var [ , boundaryGroup, partialGroup] = res; - this.isFirstWord = partialGroup.length === this.originalText.length; - - if (partialGroup.length === 0 && passive) { - this.stopTabCompleting(); - return; - } - - this.matchedList = [ - new Entry(partialGroup) // first entry is always the original partial - ]; - - // find matching entries in the set of entries given to us - this.list.forEach((entry) => { - if (entry.text.toLowerCase().indexOf(partialGroup.toLowerCase()) === 0) { - this.matchedList.push(entry); - } - }); - - // console.log("_calculateCompletions => %s", JSON.stringify(this.matchedList)); - } - _notifyStateChange() { if (this.opts.onStateChange) { this.opts.onStateChange(this.completing);