From 4e6bd9e9436f87142eb8f765faea7aa022000b96 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 23 Jan 2020 22:25:34 +0200 Subject: [PATCH] Fix "$1" when completing nicks outside of textcomplete menu Fixes #3716 --- client/js/autocompletion.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) 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: "",