diff --git a/src/TabComplete.js b/src/TabComplete.js index 3b117ca689..59f3cec3a0 100644 --- a/src/TabComplete.js +++ b/src/TabComplete.js @@ -32,8 +32,6 @@ const MATCH_REGEX = /(^|\s)(\S+)$/; class TabComplete { constructor(opts) { - opts.startingWordSuffix = opts.startingWordSuffix || ""; - opts.wordSuffix = opts.wordSuffix || ""; opts.allowLooping = opts.allowLooping || false; opts.autoEnterTabComplete = opts.autoEnterTabComplete || false; opts.onClickCompletes = opts.onClickCompletes || false; @@ -96,7 +94,9 @@ class TabComplete { * @param {Entry} entry The tab-complete entry to complete to. */ completeTo(entry) { - this.textArea.value = this._replaceWith(entry.getText(), true, entry.getOverrideSuffix()); + this.textArea.value = this._replaceWith( + entry.getText(), true, entry.getSuffix(this.isFirstWord) + ); this.stopTabCompleting(); // keep focus on the text area this.textArea.focus(); @@ -224,7 +224,7 @@ class TabComplete { this.textArea.value = this._replaceWith( this.matchedList[this.currentIndex].getText(), this.currentIndex !== 0, // don't suffix the original text! - this.matchedList[this.currentIndex].getOverrideSuffix() + this.matchedList[this.currentIndex].getSuffix(this.isFirstWord) ); } @@ -244,7 +244,7 @@ class TabComplete { } } - _replaceWith(newVal, includeSuffix, overrideSuffix) { + _replaceWith(newVal, includeSuffix, suffix) { // The regex to replace the input matches a character of whitespace AND // the partial word. If we just use string.replace() with the regex it will // replace the partial word AND the character of whitespace. We want to @@ -259,14 +259,9 @@ class TabComplete { boundaryChar = ""; } - var suffix = ""; - if (includeSuffix) { - if (overrideSuffix) { - suffix = overrideSuffix; - } - else { - suffix = (this.isFirstWord ? this.opts.startingWordSuffix : this.opts.wordSuffix); - } + suffix = suffix || ""; + if (!includeSuffix) { + suffix = ""; } var replacementText = boundaryChar + newVal + suffix; diff --git a/src/TabCompleteEntries.js b/src/TabCompleteEntries.js index 4b7fbc5d0e..79e0a9a46b 100644 --- a/src/TabCompleteEntries.js +++ b/src/TabCompleteEntries.js @@ -43,10 +43,10 @@ class Entry { } /** - * @return {?string} The suffix to override whatever the default is, or null to + * @return {?string} The suffix to append to the tab-complete, or null to * not do this. */ - getOverrideSuffix() { + getSuffix(isFirstWord) { return null; } @@ -67,7 +67,7 @@ class CommandEntry extends Entry { return this.getText(); } - getOverrideSuffix() { + getSuffix(isFirstWord) { return " "; // force a space after the command. } } @@ -94,6 +94,10 @@ class MemberEntry extends Entry { getKey() { return this.member.userId; } + + getSuffix(isFirstWord) { + return isFirstWord ? ": " : " "; + } } MemberEntry.fromMemberList = function(members) { diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index bc6438a97c..abfa2e27f1 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -96,8 +96,6 @@ module.exports = React.createClass({ // xchat-style tab complete, add a colon if tab // completing at the start of the text this.tabComplete = new TabComplete({ - startingWordSuffix: ": ", - wordSuffix: " ", allowLooping: false, autoEnterTabComplete: true, onClickCompletes: true,