diff --git a/client/js/autocompletion.js b/client/js/autocompletion.js index 2a40a42c..c75f3606 100644 --- a/client/js/autocompletion.js +++ b/client/js/autocompletion.js @@ -45,19 +45,8 @@ const nicksStrategy = { template([string]) { return string; }, - replace([, original], position = 1) { - // If no postfix specified, return autocompleted nick as-is - if (!store.state.settings.nickPostfix) { - return "$1" + original; - } - - // If there is whitespace in the input already, append space to nick - if (position > 0 && /\s/.test(store.state.activeChannel.channel.pendingMessage)) { - return "$1" + original + " "; - } - - // If nick is first in the input, append specified postfix - return "$1" + original + store.state.settings.nickPostfix; + replace([, original]) { + return "$1" + replaceNick(original); }, index: 2, }; @@ -205,8 +194,8 @@ function enableAutocomplete(input) { } const position = input.selectionStart - lastMatch.length; - const newMatch = nicksStrategy.replace( - [0, currentMatches[tabCount % currentMatches.length]], + const newMatch = replaceNick( + currentMatches[tabCount % currentMatches.length], position ); const remainder = text.substr(input.selectionStart); @@ -272,6 +261,21 @@ function enableAutocomplete(input) { }; } +function replaceNick(original, position = 1) { + // If no postfix specified, return autocompleted nick as-is + if (!store.state.settings.nickPostfix) { + return original; + } + + // If there is whitespace in the input already, append space to nick + if (position > 0 && /\s/.test(store.state.activeChannel.channel.pendingMessage)) { + return original + " "; + } + + // If nick is first in the input, append specified postfix + return original + store.state.settings.nickPostfix; +} + function fuzzyGrep(term, array) { const results = fuzzy.filter(term, array, { pre: "",