Fix "$1" when completing nicks outside of textcomplete menu

Fixes #3716
This commit is contained in:
Pavel Djundik 2020-01-23 22:25:34 +02:00
parent e8ba4f4fb9
commit 4e6bd9e943

View file

@ -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: "<b>",