Fallback for old safari

This commit is contained in:
Cohee
2024-05-14 23:43:17 +03:00
parent 1dec93de8a
commit f0016b5368

View File

@ -50,6 +50,14 @@ export class SlashCommandAutoCompleteNameResult extends AutoCompleteNameResult {
} }
getNamedArgumentAt(text, index, isSelect) { getNamedArgumentAt(text, index, isSelect) {
function getSplitRegex() {
try {
return new RegExp('(?<==)');
} catch {
// For browsers that don't support lookbehind
return new RegExp('=(.*)');
}
}
const notProvidedNamedArguments = this.executor.command.namedArgumentList.filter(arg=>!this.executor.namedArgumentList.find(it=>it.name == arg.name)); const notProvidedNamedArguments = this.executor.command.namedArgumentList.filter(arg=>!this.executor.namedArgumentList.find(it=>it.name == arg.name));
let name; let name;
let value; let value;
@ -62,7 +70,7 @@ export class SlashCommandAutoCompleteNameResult extends AutoCompleteNameResult {
// cursor is somewhere within the named arguments (including final space) // cursor is somewhere within the named arguments (including final space)
argAssign = this.executor.namedArgumentList.find(it=>it.start <= index && it.end >= index); argAssign = this.executor.namedArgumentList.find(it=>it.start <= index && it.end >= index);
if (argAssign) { if (argAssign) {
const [argName, ...v] = text.slice(argAssign.start, index).split(/(?<==)/); const [argName, ...v] = text.slice(argAssign.start, index).split(getSplitRegex());
name = argName; name = argName;
value = v.join(''); value = v.join('');
start = argAssign.start; start = argAssign.start;