From abaf07a8bb7eae95c4a8d1c40b7c6a609a739dec Mon Sep 17 00:00:00 2001 From: Mathias Jakobsen Date: Wed, 26 Jun 2024 13:39:29 +0100 Subject: [PATCH] Merge pull request #19158 from overleaf/mj-commands-autocomplete-optional-args [web] Avoid double counting optional arguments for autocomplete GitOrigin-RevId: 7abdc73657791b945bd5a7a9e29f5cd127c7882b --- .../source-editor/utils/tree-operations/commands.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/utils/tree-operations/commands.ts b/services/web/frontend/js/features/source-editor/utils/tree-operations/commands.ts index 9cdab1ee75..f31516df94 100644 --- a/services/web/frontend/js/features/source-editor/utils/tree-operations/commands.ts +++ b/services/web/frontend/js/features/source-editor/utils/tree-operations/commands.ts @@ -108,7 +108,8 @@ export const enterNode = ( } const optionalArguments = commandNode.getChildren('OptionalArgument') - const commandArguments = commandNode.getChildren('$Argument') + const commandArgumentsIncludingOptional = + commandNode.getChildren('$Argument') const text = state.doc.sliceString(ctrlSeq.from, ctrlSeq.to) const thisCommand = { @@ -117,7 +118,8 @@ export const enterNode = ( from: commandNode.from, to: commandNode.to, optionalArgCount: optionalArguments.length, - requiredArgCount: commandArguments.length, + requiredArgCount: + commandArgumentsIncludingOptional.length - optionalArguments.length, } items.push(thisCommand) }