More efficient editor state saves

This commit is contained in:
Gregory Schier
2025-11-02 06:16:45 -08:00
parent df5be218a5
commit 9bde6bbd0a
2 changed files with 7 additions and 6 deletions

View File

@@ -327,7 +327,9 @@ export function Editor({
const onClickMissingVariable = useCallback(async (name: string) => { const onClickMissingVariable = useCallback(async (name: string) => {
const activeEnvironment = jotaiStore.get(activeEnvironmentAtom); const activeEnvironment = jotaiStore.get(activeEnvironmentAtom);
await editEnvironment(activeEnvironment, { addOrFocusVariable: { name, value: '', enabled: true } }); await editEnvironment(activeEnvironment, {
addOrFocusVariable: { name, value: '', enabled: true },
});
}, []); }, []);
const [, { focusParamValue }] = useRequestEditor(); const [, { focusParamValue }] = useRequestEditor();
@@ -374,7 +376,7 @@ export function Editor({
// Initialize the editor when ref mounts // Initialize the editor when ref mounts
const initEditorRef = useCallback( const initEditorRef = useCallback(
function initEditorRef(container: HTMLDivElement | null) { function initializeCodemirror(container: HTMLDivElement | null) {
if (container === null) { if (container === null) {
cm.current?.view.destroy(); cm.current?.view.destroy();
cm.current = null; cm.current = null;
@@ -627,15 +629,13 @@ function getExtensions({
// Things that must be last // // Things that must be last //
// ------------------------ // // ------------------------ //
// Fire onChange event
EditorView.updateListener.of((update) => { EditorView.updateListener.of((update) => {
if (update.startState === update.state) return;
if (onChange && update.docChanged) { if (onChange && update.docChanged) {
onChange.current?.(update.state.doc.toString()); onChange.current?.(update.state.doc.toString());
} }
}),
// Cache editor state
EditorView.updateListener.of((update) => {
saveCachedEditorState(stateKey, update.state); saveCachedEditorState(stateKey, update.state);
}), }),
]; ];

View File

@@ -132,6 +132,7 @@ export function TextViewer({ language, text, response, requestId, pretty, classN
language={language} language={language}
actions={actions} actions={actions}
extraExtensions={extraExtensions} extraExtensions={extraExtensions}
// State key for storing fold state
stateKey={'response.body.' + response.id} stateKey={'response.body.' + response.id}
/> />
); );