From 60816702f521af02860de9b62ee9ceeb661c8b60 Mon Sep 17 00:00:00 2001 From: Waleed Date: Wed, 29 Apr 2026 17:41:02 -0700 Subject: [PATCH] fix(files): use incremental applyEdits to prevent streaming flicker in Monaco editor (#4347) * fix(files): use incremental applyEdits to prevent streaming flicker in Monaco editor * fix(files): use actual model value for additive applyEdits guard * fix(files): use pushEditOperations instead of applyEdits to align with VS Code streaming pattern * fix(files): revert to applyEdits to avoid polluting undo stack during streaming --- .../components/file-viewer/text-editor.tsx | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx b/apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx index 91a70cebe4..26f9ace4e1 100644 --- a/apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx +++ b/apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx @@ -442,11 +442,24 @@ export const TextEditor = memo(function TextEditor({ textareaStuckRef.current = true } } - const viewState = - isStreamInteractionLocked && !textareaStuckRef.current ? editor.saveViewState() : null suppressScrollListenerRef.current = true - model.setValue(content) - if (viewState) editor.restoreViewState(viewState) + if (content.startsWith(monacoValue) && monacoValue.length < content.length) { + const lastLine = model.getLineCount() + const lastCol = model.getLineMaxColumn(lastLine) + model.applyEdits([ + { + range: { + startLineNumber: lastLine, + startColumn: lastCol, + endLineNumber: lastLine, + endColumn: lastCol, + }, + text: content.slice(monacoValue.length), + }, + ]) + } else { + model.applyEdits([{ range: model.getFullModelRange(), text: content }]) + } suppressScrollListenerRef.current = false lastSyncedContentRef.current = content }