From 8feb2d739709cbcdef3954f77150bb45c183c76d Mon Sep 17 00:00:00 2001 From: Ricardo Silva Date: Thu, 11 Jun 2026 09:52:59 +0100 Subject: [PATCH 1/2] fix reverte changes editor can edit text Signed-off-by: Ricardo Silva --- src/components/Editor/JsonEditor.tsx | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/components/Editor/JsonEditor.tsx b/src/components/Editor/JsonEditor.tsx index 33c1680..d1fda29 100644 --- a/src/components/Editor/JsonEditor.tsx +++ b/src/components/Editor/JsonEditor.tsx @@ -25,14 +25,6 @@ import { editor } from "monaco-editor"; type SchemaMapMessage = Map>; -// List of all Options can be found here: https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.IStandaloneEditorConstructionOptions.html - -let timeoutId: ReturnType; -const delay = (fn: (text: string) => void, text: string, ms: number) => { - clearTimeout(timeoutId); - timeoutId = setTimeout(() => fn(text), ms); -}; - type JsonEditorProps = { editorRef?: React.MutableRefObject; jsonIndentation: 2 | 4; @@ -42,6 +34,12 @@ interface JsonSchemaEntry { schema: Record; } +let timeoutId: ReturnType; +const delay = (fn: (text: string) => void, text: string, ms: number) => { + clearTimeout(timeoutId); + timeoutId = setTimeout(() => fn(text), ms); +}; + const JsonEditor: React.FC = ({ editorRef, jsonIndentation, @@ -239,19 +237,6 @@ const JsonEditor: React.FC = ({ } }, [context.linkedTd, context.offlineTD]); - useEffect(() => { - try { - const parsed = JSON.parse(context.offlineTD); - const formatted = JSON.stringify(parsed, null, jsonIndentation); - - if (formatted !== context.offlineTD) { - context.updateOfflineTD(formatted); - } - } catch { - // ignore invalid JSON - } - }, [jsonIndentation, context.offlineTD]); - const changeLinkedTd = async () => { let href = (document.getElementById("linkedTd") as HTMLSelectElement).value; changeBetweenTd(context, href); From 52f39d60ebcc3a464217c2d1234cccbfc8746169 Mon Sep 17 00:00:00 2001 From: Ricardo Silva Date: Thu, 11 Jun 2026 10:00:31 +0100 Subject: [PATCH 2/2] feat change on settings json identation do not break editing Signed-off-by: Ricardo Silva --- src/components/Editor/JsonEditor.tsx | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/components/Editor/JsonEditor.tsx b/src/components/Editor/JsonEditor.tsx index d1fda29..4d55221 100644 --- a/src/components/Editor/JsonEditor.tsx +++ b/src/components/Editor/JsonEditor.tsx @@ -237,6 +237,37 @@ const JsonEditor: React.FC = ({ } }, [context.linkedTd, context.offlineTD]); + useEffect(() => { + const currentEditor = editorInstance.current; + if (!currentEditor) { + return; + } + + const currentValue = currentEditor.getValue(); + if (!currentValue) { + return; + } + + try { + const parsed = JSON.parse(currentValue); + const formatted = JSON.stringify(parsed, null, jsonIndentation); + + if (formatted === currentValue) { + return; + } + + const viewState = currentEditor.saveViewState(); + setLocalTextState(formatted); + context.updateOfflineTD(formatted); + + if (viewState) { + setTimeout(() => { + editorInstance.current?.restoreViewState(viewState); + }, 0); + } + } catch {} + }, [jsonIndentation]); + const changeLinkedTd = async () => { let href = (document.getElementById("linkedTd") as HTMLSelectElement).value; changeBetweenTd(context, href);