diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Sketch-on-face-with-none-z-up-1-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Sketch-on-face-with-none-z-up-1-Google-Chrome-linux.png index 897e5cc66..d6dc71f23 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Sketch-on-face-with-none-z-up-1-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Sketch-on-face-with-none-z-up-1-Google-Chrome-linux.png differ diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/code-color-goober-code-color-goober-1-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/code-color-goober-code-color-goober-1-Google-Chrome-linux.png index a6a0fd1f2..51f2107b1 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/code-color-goober-code-color-goober-1-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/code-color-goober-code-color-goober-1-Google-Chrome-linux.png differ diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable--XZ-1-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable--XZ-1-Google-Chrome-linux.png index aaf889c10..b886f4bca 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable--XZ-1-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable--XZ-1-Google-Chrome-linux.png differ diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable-XZ-1-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable-XZ-1-Google-Chrome-linux.png index 55703e3c2..266886d69 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable-XZ-1-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable-XZ-1-Google-Chrome-linux.png differ diff --git a/src/components/CommandBar/CommandBarKclInput.tsx b/src/components/CommandBar/CommandBarKclInput.tsx index 111b2a976..2f87dd57a 100644 --- a/src/components/CommandBar/CommandBarKclInput.tsx +++ b/src/components/CommandBar/CommandBarKclInput.tsx @@ -74,9 +74,11 @@ function CommandBarKclInput({ arg.name, previouslySetValue, ]) - const [value, setValue] = useState( - previouslySetValue?.valueText || defaultValue || '' + const initialValue = useMemo( + () => previouslySetValue?.valueText || defaultValue || '', + [previouslySetValue, defaultValue] ) + const [value, setValue] = useState(initialValue) const [createNewVariable, setCreateNewVariable] = useState( (previouslySetValue && 'variableName' in previouslySetValue) || arg.createVariableByDefault || @@ -105,7 +107,7 @@ function CommandBarKclInput({ })) const varMentionsExtension = varMentions(varMentionData) - const { setContainer } = useCodeMirror({ + const { setContainer, view } = useCodeMirror({ container: editorRef.current, initialDocValue: value, autoFocus: true, @@ -161,6 +163,21 @@ function CommandBarKclInput({ useEffect(() => { if (editorRef.current) { setContainer(editorRef.current) + // Reset the value when the arg changes and + // the new arg is also a KCL type, since the component + // sticks around. + view?.focus() + view?.dispatch({ + changes: { + from: 0, + to: view.state.doc.length, + insert: initialValue, + }, + selection: { + anchor: 0, + head: initialValue.length, + }, + }) } }, [arg, editorRef])