From 9bde6bbd0a4ba93a8ef4bfb3e392058aa0680d6e Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sun, 2 Nov 2025 06:16:45 -0800 Subject: [PATCH] More efficient editor state saves --- src-web/components/core/Editor/Editor.tsx | 12 ++++++------ src-web/components/responseViewers/TextViewer.tsx | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src-web/components/core/Editor/Editor.tsx b/src-web/components/core/Editor/Editor.tsx index 41141ee3..6c3fcb66 100644 --- a/src-web/components/core/Editor/Editor.tsx +++ b/src-web/components/core/Editor/Editor.tsx @@ -327,7 +327,9 @@ export function Editor({ const onClickMissingVariable = useCallback(async (name: string) => { const activeEnvironment = jotaiStore.get(activeEnvironmentAtom); - await editEnvironment(activeEnvironment, { addOrFocusVariable: { name, value: '', enabled: true } }); + await editEnvironment(activeEnvironment, { + addOrFocusVariable: { name, value: '', enabled: true }, + }); }, []); const [, { focusParamValue }] = useRequestEditor(); @@ -374,7 +376,7 @@ export function Editor({ // Initialize the editor when ref mounts const initEditorRef = useCallback( - function initEditorRef(container: HTMLDivElement | null) { + function initializeCodemirror(container: HTMLDivElement | null) { if (container === null) { cm.current?.view.destroy(); cm.current = null; @@ -627,15 +629,13 @@ function getExtensions({ // Things that must be last // // ------------------------ // - // Fire onChange event EditorView.updateListener.of((update) => { + if (update.startState === update.state) return; + if (onChange && update.docChanged) { onChange.current?.(update.state.doc.toString()); } - }), - // Cache editor state - EditorView.updateListener.of((update) => { saveCachedEditorState(stateKey, update.state); }), ]; diff --git a/src-web/components/responseViewers/TextViewer.tsx b/src-web/components/responseViewers/TextViewer.tsx index 58608ebc..147542d2 100644 --- a/src-web/components/responseViewers/TextViewer.tsx +++ b/src-web/components/responseViewers/TextViewer.tsx @@ -132,6 +132,7 @@ export function TextViewer({ language, text, response, requestId, pretty, classN language={language} actions={actions} extraExtensions={extraExtensions} + // State key for storing fold state stateKey={'response.body.' + response.id} /> );