Repository navigation
fix(editor): cancel paste when its target model changes - #34904
Conversation
9b00453 to
87d8338
Compare
[Medium impact] The PR appears safe to merge. SummaryKeeps paste tied to the editor model it started with.
No actionable issues found. Review used source inspection; tests were not run.
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 8 minutes. View limit details
No actionable comments were generated in the recent review.
|
Snapshot the paste target (model, container, focus) before the context-menu clipboard IPC read and before the yielding byte measurement of large pastes, and re-check it afterwards so a model swapped during the await (e.g. a diff refresh via setModel) does not receive the paste.
87d8338 to
63ee345
Compare
Problem
Paste can land in a different model than the one it was aimed at when the editor's model is replaced while the paste is awaiting:
hasTextFocus()(native path), so if the model was swapped with focus retained, e.g. a diff refresh callingsetModelon the same diff widget while an agent rewrites the file, the paste went into the replacement model at its cursor.Fix
snapshotMonacoPasteTarget/isMonacoPasteTargetCurrentfrommonaco-large-text-paste.ts.noop/target-lost.executeMonacoLargeTextPastesnapshots before measurement and passes the snapshot toinsertMonacoTextInChunks, which re-validates it before inserting.If the race is hit, Paste does nothing instead of inserting into the swapped model. Normal paste behavior is unchanged.
Tests
monaco-context-menu-paste.test.ts: native and chunked context-menu paste are rejected when the model is replaced during the clipboard read.monaco-large-text-paste.test.ts: a model replaced during the yielded byte measurement receives no edits.All three fail without the fix.
pnpm check:changedpasses.