From cefb9a10dca95bf46bf47b63fd3291092cb0dd94 Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Sun, 16 Jun 2024 08:45:04 -0400 Subject: [PATCH] add autocomplete for multiple unnamed args --- .../SlashCommandAutoCompleteNameResult.js | 10 ++++++++-- public/scripts/slash-commands/SlashCommandParser.js | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/public/scripts/slash-commands/SlashCommandAutoCompleteNameResult.js b/public/scripts/slash-commands/SlashCommandAutoCompleteNameResult.js index cdd7f1a77..56dd7535c 100644 --- a/public/scripts/slash-commands/SlashCommandAutoCompleteNameResult.js +++ b/public/scripts/slash-commands/SlashCommandAutoCompleteNameResult.js @@ -90,8 +90,8 @@ export class SlashCommandAutoCompleteNameResult extends AutoCompleteNameResult { } } else if (unamedArgLength > 0 && index >= this.executor.startUnnamedArgs && index <= this.executor.endUnnamedArgs) { // cursor is somewhere within the unnamed arguments - //TODO if index is in first array item and that is a string, treat it as an unfinished named arg - if (typeof this.executor.unnamedArgumentList[0].value == 'string') { + // if index is in first array item and that is a string, treat it as an unfinished named arg + if (typeof this.executor.unnamedArgumentList[0]?.value == 'string') { if (index <= this.executor.startUnnamedArgs + this.executor.unnamedArgumentList[0].value.length) { name = this.executor.unnamedArgumentList[0].value.slice(0, index - this.executor.startUnnamedArgs); start = this.executor.startUnnamedArgs; @@ -154,6 +154,9 @@ export class SlashCommandAutoCompleteNameResult extends AutoCompleteNameResult { if (idx > -1) { argAssign = this.executor.unnamedArgumentList[idx]; cmdArg = this.executor.command.unnamedArgumentList[idx]; + if (cmdArg === undefined && this.executor.command.unnamedArgumentList.slice(-1)[0].acceptsMultiple) { + cmdArg = this.executor.command.unnamedArgumentList.slice(-1)[0]; + } const enumList = cmdArg?.enumProvider?.(this.executor, this.scope) ?? cmdArg?.enumList; if (cmdArg && enumList.length > 0) { value = argAssign.value.toString().slice(0, index - argAssign.start); @@ -165,6 +168,9 @@ export class SlashCommandAutoCompleteNameResult extends AutoCompleteNameResult { value = ''; start = index; cmdArg = notProvidedArguments[0]; + if (cmdArg === undefined && this.executor.command.unnamedArgumentList.slice(-1)[0].acceptsMultiple) { + cmdArg = this.executor.command.unnamedArgumentList.slice(-1)[0]; + } } } else { return null; diff --git a/public/scripts/slash-commands/SlashCommandParser.js b/public/scripts/slash-commands/SlashCommandParser.js index 52796e063..fecd695f2 100644 --- a/public/scripts/slash-commands/SlashCommandParser.js +++ b/public/scripts/slash-commands/SlashCommandParser.js @@ -757,7 +757,7 @@ export class SlashCommandParser { this.discardWhitespace(); } this.discardWhitespace(); - cmd.startUnnamedArgs = this.index; + cmd.startUnnamedArgs = this.index - /\s(\s*)$/s.exec(this.behind)[1]?.length ?? 0; cmd.endUnnamedArgs = this.index; if (this.testUnnamedArgument()) { cmd.unnamedArgumentList = this.parseUnnamedArgument(cmd.command?.unnamedArgumentList?.length && cmd?.command?.splitUnnamedArgument);