Skip to content

Commit

Permalink
Clean up yDoc observers on PM plugin destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
AdventureBeard committed Apr 14, 2021
1 parent 8cd9639 commit 90ddee1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/plugins/sync-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,17 @@ export class ProsemirrorBinding {
* current selection as relative positions in the Yjs model
*/
this.beforeTransactionSelection = null
this.doc.on('beforeAllTransactions', () => {
this.beforeAllTransactions = () => {
if (this.beforeTransactionSelection === null) {
this.beforeTransactionSelection = getRelativeSelection(this, prosemirrorView.state)
}
})
this.doc.on('afterAllTransactions', e => {
}
this.afterAllTransactions = () => {
this.beforeTransactionSelection = null
})
}

this.doc.on('beforeAllTransactions', this.beforeAllTransactions)
this.doc.on('afterAllTransactions', this.afterAllTransactions)
yXmlFragment.observeDeep(this._observeFunction)

this._domSelectionInView = null
Expand Down Expand Up @@ -370,6 +373,8 @@ export class ProsemirrorBinding {

destroy () {
this.type.unobserveDeep(this._observeFunction)
this.doc.off('beforeAllTransactions', this.beforeAllTransactions)
this.doc.off('afterAllTransactions', this.afterAllTransactions)
}
}

Expand Down

0 comments on commit 90ddee1

Please sign in to comment.