Skip to content

Commit 2ce42fb

Browse files
committed
fix(ui): auto-reformat after code action edits (multi-line changes only)
1 parent 1ebe626 commit 2ce42fb

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,34 @@ export const JsonEditorView = ({
357357
});
358358
};
359359

360-
const disposable = editor.onDidChangeModelContent(() => {
360+
const disposable = editor.onDidChangeModelContent((e) => {
361361
if (isProgrammaticEdit) {
362362
isProgrammaticEdit = false;
363363
return;
364364
}
365365

366366
const text = editor.getValue();
367367

368+
// Immediate reformat for multi-line edits (e.g., code actions like "Wrap in AND").
369+
// Only triggers when a single change spans multiple lines — normal typing
370+
// is single-line and won't match, avoiding cursor-jump issues.
371+
const isMultiLineEdit =
372+
!e.isUndoing &&
373+
!e.isRedoing &&
374+
e.changes.length === 1 &&
375+
(e.changes[0].text.includes('\n') ||
376+
e.changes[0].range.endLineNumber >
377+
e.changes[0].range.startLineNumber);
378+
if (isMultiLineEdit) {
379+
const formatted = tryFormat(text);
380+
if (formatted && formatted !== text) {
381+
isProgrammaticEdit = true;
382+
replaceAllContent(editor, formatted, 'auto-reformat');
383+
handleJsonChange(formatted);
384+
return;
385+
}
386+
}
387+
368388
// Debounced hints
369389
if (hintTimer) window.clearTimeout(hintTimer);
370390
hintTimer = window.setTimeout(updateHints, HINT_DEBOUNCE_MS);

0 commit comments

Comments
 (0)