diff --git a/src/TabComplete.js b/src/TabComplete.js index 32d25da554..be1520c5cd 100644 --- a/src/TabComplete.js +++ b/src/TabComplete.js @@ -27,6 +27,7 @@ class TabComplete { opts.startingWordSuffix = opts.startingWordSuffix || ""; opts.wordSuffix = opts.wordSuffix || ""; opts.allowLooping = opts.allowLooping || false; + opts.autoEnterTabComplete = opts.autoEnterTabComplete || false; this.opts = opts; this.completing = false; this.list = []; // full set of tab-completable things @@ -35,6 +36,7 @@ class TabComplete { this.originalText = null; // original input text when tab was first hit this.textArea = opts.textArea; // DOMElement this.isFirstWord = false; // true if you tab-complete on the first word + this.enterTabCompleteTimerId = null; } /** @@ -64,6 +66,12 @@ class TabComplete { this._notifyStateChange(); } + startTabCompleting() { + this.completing = true; + this.currentIndex = 0; + this._calculateCompletions(); + } + /** * @param {Number} numAheadToPeek Return *up to* this many elements. * @return {TabComplete.Entry[]} @@ -106,6 +114,31 @@ class TabComplete { this.stopTabCompleting(); return true; } + + if (this.opts.autoEnterTabComplete) { + /* + TODO: + - This is passive so we shouldn't clobber the partial word that + the user may have entered. This requires more logic to handle + that vs a normal TAB which does clobber. + - The first invocation of this timer will give no results because + we horribly set the enumeration onKeyDown in MessageComposer, which + was never actually hit. We should hook into RoomView's RoomState.members + event and set the list there. + + + clearTimeout(this.enterTabCompleteTimerId); + this.enterTabCompleteTimerId = setTimeout(() => { + if (!this.completing) { + // inject a fake tab event so we use the same code paths + this.onKeyDown({ + keyCode: KEY_TAB, + preventDefault: function(){} // NOP + }) + } + }, DELAY_TIME_MS); */ + } + return false; } @@ -116,9 +149,7 @@ class TabComplete { // init struct if necessary if (!this.completing) { - this.completing = true; - this.currentIndex = 0; - this._calculateCompletions(); + this.startTabCompleting(); } if (ev.shiftKey) { diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index d3b516c786..6233986362 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -92,6 +92,7 @@ module.exports = React.createClass({ startingWordSuffix: ": ", wordSuffix: " ", allowLooping: false, + autoEnterTabComplete: true, onStateChange: (isCompleting) => { this.forceUpdate(); }