Merge pull request #3696 from thelounge/xpaw/fix-2960

Trigger autocompletion only after whitespace
This commit is contained in:
Pavel Djundik 2020-01-22 10:28:11 +02:00 committed by GitHub
commit f1a11d3a0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 15 deletions

View File

@ -14,24 +14,25 @@ export default enableAutocomplete;
const emojiSearchTerms = Object.keys(emojiMap); const emojiSearchTerms = Object.keys(emojiMap);
const emojiStrategy = { const emojiStrategy = {
id: "emoji", id: "emoji",
match: /\B:([-+\w:?]{2,}):?$/, match: /(^|\s):([-+\w:?]{2,}):?$/,
search(term, callback) { search(term, callback) {
// Trim colon from the matched term, // Trim colon from the matched term,
// as we are unable to get a clean string from match regex // as we are unable to get a clean string from match regex
(term = term.replace(/:$/, "")), callback(fuzzyGrep(term, emojiSearchTerms)); term = term.replace(/:$/, "");
callback(fuzzyGrep(term, emojiSearchTerms));
}, },
template([string, original]) { template([string, original]) {
return `<span class="emoji">${emojiMap[original]}</span> ${string}`; return `<span class="emoji">${emojiMap[original]}</span> ${string}`;
}, },
replace([, original]) { replace([, original]) {
return emojiMap[original]; return "$1" + emojiMap[original];
}, },
index: 1, index: 2,
}; };
const nicksStrategy = { const nicksStrategy = {
id: "nicks", id: "nicks",
match: /\B(@([a-zA-Z_[\]\\^{}|`@][a-zA-Z0-9_[\]\\^{}|`-]*)?)$/, match: /(^|\s)(@([a-zA-Z_[\]\\^{}|`@][a-zA-Z0-9_[\]\\^{}|`-]*)?)$/,
search(term, callback) { search(term, callback) {
term = term.slice(1); term = term.slice(1);
@ -47,33 +48,33 @@ const nicksStrategy = {
replace([, original], position = 1) { replace([, original], position = 1) {
// If no postfix specified, return autocompleted nick as-is // If no postfix specified, return autocompleted nick as-is
if (!store.state.settings.nickPostfix) { if (!store.state.settings.nickPostfix) {
return original; return "$1" + original;
} }
// If there is whitespace in the input already, append space to nick // If there is whitespace in the input already, append space to nick
if (position > 0 && /\s/.test(store.state.activeChannel.channel.pendingMessage)) { if (position > 0 && /\s/.test(store.state.activeChannel.channel.pendingMessage)) {
return original + " "; return "$1" + original + " ";
} }
// If nick is first in the input, append specified postfix // If nick is first in the input, append specified postfix
return original + store.state.settings.nickPostfix; return "$1" + original + store.state.settings.nickPostfix;
}, },
index: 1, index: 2,
}; };
const chanStrategy = { const chanStrategy = {
id: "chans", id: "chans",
match: /\B((#|\+|&|![A-Z0-9]{5})([^\x00\x0A\x0D\x20\x2C\x3A]+(:[^\x00\x0A\x0D\x20\x2C\x3A]*)?)?)$/, match: /(^|\s)((?:#|\+|&|![A-Z0-9]{5})(?:[^\s]+)?)$/,
search(term, callback, match) { search(term, callback) {
callback(completeChans(match[0])); callback(completeChans(term));
}, },
template([string]) { template([string]) {
return string; return string;
}, },
replace([, original]) { replace([, original]) {
return original; return "$1" + original;
}, },
index: 1, index: 2,
}; };
const commandStrategy = { const commandStrategy = {
@ -319,7 +320,8 @@ function completeChans(word) {
const words = []; const words = [];
for (const channel of store.state.activeChannel.network.channels) { for (const channel of store.state.activeChannel.network.channels) {
if (channel.type === "channel") { // Push all channels that start with the same CHANTYPE
if (channel.type === "channel" && channel.name[0] === word[0]) {
words.push(channel.name); words.push(channel.name);
} }
} }