Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd072642

Browse files
committed
remove usage of lib0/mutex
1 parent708cdcc commitd072642

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

‎src/y-quill.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
*@module bindings/quill
33
*/
44

5-
import{createMutex}from'lib0/mutex.js'
65
import*asYfrom'yjs'// eslint-disable-line
76
import{Awareness}from'y-protocols/awareness.js'// eslint-disable-line
87

@@ -59,9 +58,7 @@ export class QuillBinding {
5958
*@param {Awareness} [awareness]
6059
*/
6160
constructor(type,quill,awareness){
62-
constmux=createMutex()
6361
constdoc=/**@type {Y.Doc} */(type.doc)
64-
this.mux=mux
6562
this.type=type
6663
this.doc=doc
6764
this.quill=quill
@@ -82,8 +79,11 @@ export class QuillBinding {
8279
quillCursors.removeCursor(id.toString())
8380
})
8481
}
82+
/**
83+
*@param {Y.YTextEvent} event
84+
*/
8585
this._typeObserver=event=>{
86-
mux(()=>{
86+
if(event.transaction.origin!==this){
8787
consteventDelta=event.delta
8888
// We always explicitly set attributes, otherwise concurrent edits may
8989
// result in quill assuming that a text insertion shall inherit existing
@@ -97,11 +97,11 @@ export class QuillBinding {
9797
delta.push(d)
9898
}
9999
}
100-
quill.updateContents(delta,'yjs')
101-
})
100+
quill.updateContents(delta,this)
101+
}
102102
}
103103
type.observe(this._typeObserver)
104-
this._quillObserver=(eventType,delta)=>{
104+
this._quillObserver=(eventType,delta,state,origin)=>{
105105
if(delta&&delta.ops){
106106
// update content
107107
constops=delta.ops
@@ -114,9 +114,11 @@ export class QuillBinding {
114114
}
115115
}
116116
})
117-
mux(()=>{
118-
type.applyDelta(ops)
119-
})
117+
if(origin!==this){
118+
doc.transact(()=>{
119+
type.applyDelta(ops)
120+
},this)
121+
}
120122
}
121123
// always check selection
122124
if(awareness&&quillCursors){
@@ -143,11 +145,9 @@ export class QuillBinding {
143145
}
144146
}
145147
quill.on('editor-change',this._quillObserver)
146-
mux(()=>{
147-
// This indirectly initializes _negatedUsedFormats.
148-
// Make sure that this call this after the _quillObserver is set.
149-
quill.setContents(type.toDelta())
150-
})
148+
// This indirectly initializes _negatedUsedFormats.
149+
// Make sure that this call this after the _quillObserver is set.
150+
quill.setContents(type.toDelta(),this)
151151
// init remote cursors
152152
if(quillCursors!==null&&awareness){
153153
awareness.getStates().forEach((aw,clientId)=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp