Skip to content

Commit 1956f85

Browse files
committed
fix(files): use incremental applyEdits to prevent streaming flicker in Monaco editor
1 parent a9d4e2e commit 1956f85

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/files/components/file-viewer

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,25 @@ export const TextEditor = memo(function TextEditor({
442442
textareaStuckRef.current = true
443443
}
444444
}
445-
const viewState =
446-
isStreamInteractionLocked && !textareaStuckRef.current ? editor.saveViewState() : null
447445
suppressScrollListenerRef.current = true
448-
model.setValue(content)
449-
if (viewState) editor.restoreViewState(viewState)
446+
const prev = lastSyncedContentRef.current
447+
if (content.startsWith(prev) && prev.length < content.length) {
448+
const lastLine = model.getLineCount()
449+
const lastCol = model.getLineMaxColumn(lastLine)
450+
model.applyEdits([
451+
{
452+
range: {
453+
startLineNumber: lastLine,
454+
startColumn: lastCol,
455+
endLineNumber: lastLine,
456+
endColumn: lastCol,
457+
},
458+
text: content.slice(prev.length),
459+
},
460+
])
461+
} else {
462+
model.applyEdits([{ range: model.getFullModelRange(), text: content }])
463+
}
450464
suppressScrollListenerRef.current = false
451465
lastSyncedContentRef.current = content
452466
}

0 commit comments

Comments
 (0)