Skip to content

Commit

Permalink
Force undo manager to stop capture when pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Sep 24, 2021
1 parent 820f61c commit 25cddab
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/y-codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ const typeObserver = (binding, event) => {
const targetObserver = (binding, changes) => {
binding._mux(() => {
binding.doc.transact(() => {
const hasPaste = binding.yUndoManager && changes.some(change => change.origin === 'paste');
if (hasPaste) {
binding.yUndoManager.stopCapturing();
}

if (changes.length > 1) {
// If there are several consecutive changes, we can't reliably compute the positions anymore. See y-codemirror#11
// Instead, we will compute the diff and apply the changes
Expand All @@ -98,6 +103,10 @@ const targetObserver = (binding, changes) => {
binding.type.insert(start, change.text.join('\n'))
}
}

if (hasPaste) {
binding.yUndoManager.stopCapturing();
}
}, binding)
})
}
Expand Down

0 comments on commit 25cddab

Please sign in to comment.