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
This commit is contained in:
Waleed
2026-04-29 17:41:02 -07:00
committed by GitHub
parent a9d4e2eca8
commit 60816702f5
@@ -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
}