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

Commit29d75f1

Browse files
committed
update cursor after each edet and prevent errors from quill-cursor to bubble
1 parent73e4567 commit29d75f1

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

‎src/y-quill.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,22 @@ export const normQuillDelta = delta => {
3333
*@param {any} quillCursors
3434
*/
3535
constupdateCursor=(quillCursors,aw,clientId,doc,type)=>{
36-
if(aw&&aw.cursor&&clientId!==doc.clientID){
37-
constuser=aw.user||{}
38-
constcolor=user.color||'#ffa500'
39-
constname=user.name||`User:${clientId}`
40-
quillCursors.createCursor(clientId.toString(),name,color)
41-
constanchor=Y.createAbsolutePositionFromRelativePosition(Y.createRelativePositionFromJSON(aw.cursor.anchor),doc)
42-
consthead=Y.createAbsolutePositionFromRelativePosition(Y.createRelativePositionFromJSON(aw.cursor.head),doc)
43-
if(anchor&&head&&anchor.type===type){
44-
quillCursors.moveCursor(clientId.toString(),{index:anchor.index,length:head.index-anchor.index})
36+
try{
37+
if(aw&&aw.cursor&&clientId!==doc.clientID){
38+
constuser=aw.user||{}
39+
constcolor=user.color||'#ffa500'
40+
constname=user.name||`User:${clientId}`
41+
quillCursors.createCursor(clientId.toString(),name,color)
42+
constanchor=Y.createAbsolutePositionFromRelativePosition(Y.createRelativePositionFromJSON(aw.cursor.anchor),doc)
43+
consthead=Y.createAbsolutePositionFromRelativePosition(Y.createRelativePositionFromJSON(aw.cursor.head),doc)
44+
if(anchor&&head&&anchor.type===type){
45+
quillCursors.moveCursor(clientId.toString(),{index:anchor.index,length:head.index-anchor.index})
46+
}
47+
}else{
48+
quillCursors.removeCursor(clientId.toString())
4549
}
46-
}else{
47-
quillCursors.removeCursor(clientId.toString())
50+
}catch(err){
51+
console.error(err)
4852
}
4953
}
5054

@@ -132,6 +136,10 @@ export class QuillBinding {
132136
})
133137
}
134138
}
139+
// update all remote cursor locations
140+
awareness.getStates().forEach((aw,clientId)=>{
141+
updateCursor(quillCursors,aw,clientId,doc,type)
142+
})
135143
}
136144
}
137145
quill.on('editor-change',this._quillObserver)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp