Skip to content

Commit 6081670

Browse files
authored
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
1 parent a9d4e2e commit 6081670

1 file changed

Lines changed: 17 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: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,24 @@ 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+
if (content.startsWith(monacoValue) && monacoValue.length < content.length) {
447+
const lastLine = model.getLineCount()
448+
const lastCol = model.getLineMaxColumn(lastLine)
449+
model.applyEdits([
450+
{
451+
range: {
452+
startLineNumber: lastLine,
453+
startColumn: lastCol,
454+
endLineNumber: lastLine,
455+
endColumn: lastCol,
456+
},
457+
text: content.slice(monacoValue.length),
458+
},
459+
])
460+
} else {
461+
model.applyEdits([{ range: model.getFullModelRange(), text: content }])
462+
}
450463
suppressScrollListenerRef.current = false
451464
lastSyncedContentRef.current = content
452465
}

0 commit comments

Comments
 (0)