fix(inbounds): preserve formatting in the advanced JSON editor (#6857)

In the inbound form's Advanced → All editor, pressing Enter or adding any
whitespace while the JSON stayed valid made the panel replace the operator's
text with its own formatting, dropping the new line and moving the caret.

Edits that only change formatting are now left alone, while changes made
elsewhere in the form still reach the editor, a tag change patches only the
tag, and an edit the form rejects (a non-numeric port, a removed section) is
replaced by what the form will actually save, so the editor never shows JSON
the panel will not submit.
This commit is contained in:
Hamed
2026-10-24 06:24:19 +03:30
committed by GitHub
parent 0516a1f87c
commit 5a135d2adb
4 changed files with 228 additions and 13 deletions
+11 -1
View File
@@ -157,8 +157,18 @@ const JsonEditor = forwardRef<JsonEditorHandle, JsonEditorProps>(function JsonEd
if (!view) return;
const current = view.state.doc.toString();
if (value === current) return;
let from = 0;
while (from < current.length && from < value.length && current[from] === value[from]) {
from += 1;
}
let oldEnd = current.length;
let newEnd = value.length;
while (oldEnd > from && newEnd > from && current[oldEnd - 1] === value[newEnd - 1]) {
oldEnd -= 1;
newEnd -= 1;
}
valueRef.current = value;
view.dispatch({ changes: { from: 0, to: current.length, insert: value } });
view.dispatch({ changes: { from, to: oldEnd, insert: value.slice(from, newEnd) } });
}, [value]);
useEffect(() => {