Skip to content

Commit 06bd6bb

Browse files
committed
fix(ui): stop auto-reformat from jumping cursor while typing
- Remove auto-reformat on debounce — formatting is now explicit (Format button only) - Comma auto-fix only runs when editor loses focus (not while user is typing) - Comma fix only applies if result is valid JSON
1 parent d188e3b commit 06bd6bb

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

‎ui/src/core/page-components/agent-detail/modals/edit-control/json-editor-view.tsx‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,24 +316,22 @@ export const JsonEditorView = ({
316316
if (hintTimer) window.clearTimeout(hintTimer);
317317
hintTimer = window.setTimeout(updateHints, HINT_DEBOUNCE_MS);
318318

319-
// 2. Debounced comma auto-fix + reformat
319+
// 2. Debounced comma auto-fix (no auto-reformat — that's the Format button's job)
320320
if (commaTimer) window.clearTimeout(commaTimer);
321321
commaTimer = window.setTimeout(() => {
322322
if (isSuggestWidgetVisible(editor)) return;
323+
if (editor.hasTextFocus()) return; // don't touch content while user is typing
323324
const current = editor.getValue();
324325
const commaFixed = fixJsonCommas(current);
325-
326-
// Only apply changes if the result is valid JSON.
327-
// Don't touch broken JSON mid-edit — comma insertion can corrupt it.
326+
if (commaFixed === current) return;
327+
// Only apply if the fix produces valid JSON
328328
try {
329-
const formatted = JSON.stringify(JSON.parse(commaFixed), null, 2);
330-
if (formatted !== current) {
331-
isProgrammaticEdit = true;
332-
replaceAllContent(editor, formatted, 'auto-reformat');
333-
handleJsonChange(formatted);
334-
}
329+
JSON.parse(commaFixed);
330+
isProgrammaticEdit = true;
331+
replaceAllContent(editor, commaFixed, 'auto-comma-fix');
332+
handleJsonChange(commaFixed);
335333
} catch {
336-
// JSON is invalid — leave it alone, user is still editing
334+
// Still invalid after comma fix — leave it alone
337335
}
338336
}, COMMA_FIX_DEBOUNCE_MS);
339337

0 commit comments

Comments
 (0)