Răsfoiți Sursa

Merge pull request #19158 from overleaf/mj-commands-autocomplete-optional-args

[web] Avoid double counting optional arguments for autocomplete

GitOrigin-RevId: 7abdc73657791b945bd5a7a9e29f5cd127c7882b
Mathias Jakobsen 2 ani în urmă
părinte
comite
abaf07a8bb

+ 4 - 2
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)
   }