File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
src/json-crdt-extensions/peritext/overlay Expand file tree Collapse file tree 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 {
315315 * @returns Whether the point is a marker point.
316316 */
317317 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 ;
323321 }
324322
325323 // ----------------------------------------------------------------- Stateful
@@ -405,7 +403,6 @@ export class Overlay<T = string> implements Printable, Stateful {
405403 }
406404
407405 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.
409406 const point = this . mPoint ( slice , Anchor . Before ) ;
410407 const pivot = this . insPoint ( point ) ;
411408 if ( ! pivot ) {
Original file line number Diff line number Diff line change @@ -65,6 +65,18 @@ describe('markers', () => {
6565 peritext . overlay . refresh ( ) ;
6666 expect ( markerCount ( peritext ) ) . toBe ( 2 ) ;
6767 } ) ;
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+ } ) ;
6880 } ) ;
6981
7082 describe ( 'deletes' , ( ) => {
You can’t perform that action at this time.
0 commit comments