File tree 2 files changed +15
-6
lines changed
src/json-crdt-extensions/peritext/overlay
2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -315,11 +315,9 @@ export class Overlay<T = string> implements Printable, Stateful {
315
315
* @returns Whether the point is a marker point.
316
316
*/
317
317
public isMarker ( id : ITimestampStruct ) : boolean {
318
- const point = this . txt . point ( id , Anchor . Before ) ;
319
- const overlayPoint = this . getOrNextLower ( point ) ;
320
- return (
321
- overlayPoint instanceof MarkerOverlayPoint && overlayPoint . id . time === id . time && overlayPoint . id . sid === id . sid
322
- ) ;
318
+ const p = this . txt . point ( id , Anchor . Before ) ;
319
+ const op = this . getOrNextLower ( p ) ;
320
+ return op instanceof MarkerOverlayPoint && op . id . time === id . time && op . id . sid === id . sid ;
323
321
}
324
322
325
323
// ----------------------------------------------------------------- Stateful
@@ -405,7 +403,6 @@ export class Overlay<T = string> implements Printable, Stateful {
405
403
}
406
404
407
405
private insMarker ( slice : MarkerSlice < T > ) : [ start : OverlayPoint < T > , end : OverlayPoint < T > ] {
408
- // TODO: When marker is at rel start, and cursor too, the overlay point should have reference to the cursor.
409
406
const point = this . mPoint ( slice , Anchor . Before ) ;
410
407
const pivot = this . insPoint ( point ) ;
411
408
if ( ! pivot ) {
Original file line number Diff line number Diff line change @@ -65,6 +65,18 @@ describe('markers', () => {
65
65
peritext . overlay . refresh ( ) ;
66
66
expect ( markerCount ( peritext ) ) . toBe ( 2 ) ;
67
67
} ) ;
68
+
69
+ test ( 'does reference cursor, when marker and cursor are at the same position' , ( ) => {
70
+ const { peritext} = setup ( ) ;
71
+ peritext . editor . cursor . setAt ( 3 ) ;
72
+ const [ marker ] = peritext . editor . saved . insMarker ( [ 'p' ] , '¶' ) ;
73
+ peritext . editor . cursor . set ( marker . start . clone ( ) ) ;
74
+ peritext . overlay . refresh ( ) ;
75
+ const overlayMarkerPoint = peritext . overlay . root2 ! ;
76
+ expect ( overlayMarkerPoint instanceof MarkerOverlayPoint ) . toBe ( true ) ;
77
+ expect ( overlayMarkerPoint . markers . length ) . toBe ( 1 ) ;
78
+ expect ( overlayMarkerPoint . markers . find ( ( m ) => m === peritext . editor . cursor ) ) . toBe ( peritext . editor . cursor ) ;
79
+ } ) ;
68
80
} ) ;
69
81
70
82
describe ( 'deletes' , ( ) => {
You can’t perform that action at this time.
0 commit comments