mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 23:31:21 +02:00
More efficient editor state saves
This commit is contained in:
@@ -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);
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -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}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user