Change autosuggestions to include second word in web UI (#39622)
This commit is contained in:
1 parent
89fa67c0e3
commit
ed8fbafb56
3 files changed
+32
-51
No files matched your search
@@ -0,0 +1,29 @@
|
||||
export const textAtCursorMatchesToken = (
|
||||
str: string,
|
||||
caretPosition: number,
|
||||
searchTokens: string[],
|
||||
) => {
|
||||
let word: string;
|
||||
|
||||
const regex = new RegExp(`[${searchTokens.join('')}\\w]+(\\s[\\w]+)?$`);
|
||||
const left = str.slice(0, caretPosition).search(regex);
|
||||
const right = str.slice(caretPosition).search(/\s/);
|
||||
|
||||
if (right < 0) {
|
||||
word = str.slice(left);
|
||||
} else {
|
||||
word = str.slice(left, right + caretPosition);
|
||||
}
|
||||
|
||||
word = word.trim();
|
||||
|
||||
if (word.length < 3 || (word[0] && !searchTokens.includes(word[0]))) {
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
if (word.length > 0) {
|
||||
return [left + 1, word];
|
||||
} else {
|
||||
return [null, null];
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user