diff --git a/pkg/document/crdt/rga_tree_split.go b/pkg/document/crdt/rga_tree_split.go index d44251379..fc876f1fd 100644 --- a/pkg/document/crdt/rga_tree_split.go +++ b/pkg/document/crdt/rga_tree_split.go @@ -548,9 +548,10 @@ func (s *RGATreeSplit[V]) deleteNodes( var maxCreatedAt *time.Ticket var clientLamportAtChange int64 if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty { - // Local edit - use version vector comparison + // Case 1: local editing from json package clientLamportAtChange = time.MaxLamport } else if !isVersionVectorEmpty { + // Case 2: from operation with version vector(After v0.5.7) lamport, ok := versionVector.Get(actorID) if ok { clientLamportAtChange = lamport @@ -558,6 +559,7 @@ func (s *RGATreeSplit[V]) deleteNodes( clientLamportAtChange = 0 } } else { + // Case 3: from operation without version vector(Before v0.5.6) createdAt, ok := maxCreatedAtMapByActor[actorIDHex] if ok { maxCreatedAt = createdAt diff --git a/pkg/document/crdt/text.go b/pkg/document/crdt/text.go index 1b135d198..deaf90eac 100644 --- a/pkg/document/crdt/text.go +++ b/pkg/document/crdt/text.go @@ -324,9 +324,10 @@ func (t *Text) Style( var maxCreatedAt *time.Ticket var clientLamportAtChange int64 if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty { - // Local edit - use version vector comparison + // Case 1: local editing from json package clientLamportAtChange = time.MaxLamport } else if !isVersionVectorEmpty { + // Case 2: from operation with version vector(After v0.5.7) lamport, ok := versionVector.Get(actorID) if ok { clientLamportAtChange = lamport @@ -334,6 +335,7 @@ func (t *Text) Style( clientLamportAtChange = 0 } } else { + // Case 3: from operation without version vector(Before v0.5.6) createdAt, ok := maxCreatedAtMapByActor[actorIDHex] if ok { maxCreatedAt = createdAt diff --git a/pkg/document/crdt/tree.go b/pkg/document/crdt/tree.go index 3ba8dcb63..a6f19d2dc 100644 --- a/pkg/document/crdt/tree.go +++ b/pkg/document/crdt/tree.go @@ -872,10 +872,12 @@ func (t *Tree) collectBetween( var maxCreatedAt *time.Ticket var clientLamportAtChange int64 + if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty { - // Local edit - use version vector comparison + // Case 1: local editing from json package clientLamportAtChange = time.MaxLamport } else if !isVersionVectorEmpty { + // Case 2: from operation with version vector(After v0.5.7) lamport, ok := versionVector.Get(actorID) if ok { clientLamportAtChange = lamport @@ -883,6 +885,7 @@ func (t *Tree) collectBetween( clientLamportAtChange = 0 } } else { + // Case 3: from operation without version vector(Before v0.5.6) createdAt, ok := maxCreatedAtMapByActor[actorIDHex] if ok { maxCreatedAt = createdAt @@ -1016,9 +1019,10 @@ func (t *Tree) Style( var maxCreatedAt *time.Ticket var clientLamportAtChange int64 if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty { - // Local edit - use version vector comparison + // Case 1: local editing from json package clientLamportAtChange = time.MaxLamport } else if !isVersionVectorEmpty { + // Case 2: from operation with version vector(After v0.5.7) lamport, ok := versionVector.Get(actorID) if ok { clientLamportAtChange = lamport @@ -1026,6 +1030,7 @@ func (t *Tree) Style( clientLamportAtChange = 0 } } else { + // Case 3: from operation without version vector(Before v0.5.6) createdAt, ok := maxCreatedAtMapByActor[actorIDHex] if ok { maxCreatedAt = createdAt @@ -1088,9 +1093,10 @@ func (t *Tree) RemoveStyle( var maxCreatedAt *time.Ticket var clientLamportAtChange int64 if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty { - // Local edit - use version vector comparison + // Case 1: local editing from json package clientLamportAtChange = time.MaxLamport } else if !isVersionVectorEmpty { + // Case 2: from operation with version vector(After v0.5.7) lamport, ok := versionVector.Get(actorID) if ok { clientLamportAtChange = lamport @@ -1098,6 +1104,7 @@ func (t *Tree) RemoveStyle( clientLamportAtChange = 0 } } else { + // Case 3: from operation without version vector(Before v0.5.6) createdAt, ok := maxCreatedAtMapByActor[actorIDHex] if ok { maxCreatedAt = createdAt