@@ -30,7 +30,7 @@ const loroCursorPluginKey = new PluginKey<{ awarenessUpdated: boolean }>(
3030function createDecorations (
3131 state : EditorState ,
3232 awareness : CursorAwareness ,
33- plugin : Plugin < DecorationSet > ,
33+ _plugin : Plugin < DecorationSet > ,
3434 createSelection : ( user : PeerID ) => DecorationAttrs ,
3535 createCursor : ( user : PeerID ) => Element ,
3636) : DecorationSet {
@@ -106,13 +106,15 @@ export const LoroCursorPlugin = (
106106 } ,
107107) => {
108108 const getSelection = options . getSelection || ( ( state ) => state . selection ) ;
109- const createSelection = options . createSelection ||
109+ const createSelection =
110+ options . createSelection ||
110111 ( ( user ) => ( {
111112 class : "loro-selection" ,
112113 "data-peer" : user ,
113114 style : `background-color: rgba(228, 208, 102, 0.5)` ,
114115 } ) ) ;
115- const createCursor = options . createCursor ||
116+ const createCursor =
117+ options . createCursor ||
116118 ( ( user ) => {
117119 const awarenessData = awareness . getAllStates ( ) ;
118120 const cursorUserData = awarenessData [ user ] ;
@@ -152,9 +154,8 @@ export const LoroCursorPlugin = (
152154 } ,
153155 apply ( tr , prevState , _oldState , newState ) {
154156 const loroState = loroSyncPluginKey . getState ( newState ) ;
155- const loroCursorState : { awarenessUpdated : boolean } = tr . getMeta (
156- loroCursorPluginKey ,
157- ) ;
157+ const loroCursorState : { awarenessUpdated : boolean } =
158+ tr . getMeta ( loroCursorPluginKey ) ;
158159 if (
159160 ( loroState && loroState . changedBy !== "local" ) ||
160161 ( loroCursorState && loroCursorState . awarenessUpdated )
@@ -252,14 +253,15 @@ export function convertPmSelectionToCursors(
252253 loroState . doc as LoroDocType ,
253254 loroState . mapping ,
254255 ) ;
255- const focus = selection . head == selection . anchor
256- ? anchor
257- : absolutePositionToCursor (
258- pmRootNode ,
259- selection . head ,
260- loroState . doc as LoroDocType ,
261- loroState . mapping ,
262- ) ;
256+ const focus =
257+ selection . head == selection . anchor
258+ ? anchor
259+ : absolutePositionToCursor (
260+ pmRootNode ,
261+ selection . head ,
262+ loroState . doc as LoroDocType ,
263+ loroState . mapping ,
264+ ) ;
263265 return { anchor, focus } ;
264266}
265267
@@ -279,7 +281,8 @@ function absolutePositionToCursor(
279281 const nodeParent = pos . node ( pos . depth ) ;
280282 const offset = pos . parentOffset ;
281283
282- const loroId = WEAK_NODE_TO_LORO_CONTAINER_MAPPING . get ( nodeParent ) ??
284+ const loroId =
285+ WEAK_NODE_TO_LORO_CONTAINER_MAPPING . get ( nodeParent ) ??
283286 getByValue ( mapping , nodeParent ) ;
284287 if ( ! loroId ) {
285288 if ( anchor > 1 ) {
@@ -301,11 +304,7 @@ function absolutePositionToCursor(
301304 const child = children . get ( childIndex ) ;
302305 childIndex += 1 ;
303306 if ( child instanceof LoroText ) {
304- if ( child . length >= index ) {
305- return child . getCursor ( index ) ;
306- } else {
307- index -= child . length ;
308- }
307+ return child . getCursor ( index ) ;
309308 } else {
310309 if ( index == 0 ) {
311310 // This happens when user selects an image or a horizontal rule
0 commit comments