Skip to content

Commit

Permalink
🐛 (editor) Fix code editor variable insertion position
Browse files Browse the repository at this point in the history
Closes #367
  • Loading branch information
baptisteArno committed Mar 10, 2023
1 parent e680d13 commit 5bbb539
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion apps/builder/src/components/inputs/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ export const CodeEditor = ({
const handleChange = (newValue: string) => {
if (isDefined(props.value)) return
setValue(newValue)
setCarretPosition(codeEditor.current?.state?.selection.main.head ?? 0)
}

const rememberCarretPosition = () => {
setCarretPosition(
codeEditor.current?.view?.state?.selection.asSingle().main.head ?? 0
)
}

useEffect(
Expand Down Expand Up @@ -114,6 +119,7 @@ export const CodeEditor = ({
ref={codeEditor}
value={props.value ?? value}
onChange={handleChange}
onBlur={rememberCarretPosition}
theme={theme}
extensions={[loadLanguage(lang)].filter(isDefined)}
editable={!isReadOnly}
Expand Down

0 comments on commit 5bbb539

Please sign in to comment.