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 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);
}),
];

View File

@@ -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}
/>
);