mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user