@@ -11,7 +11,7 @@ import {CommonSliceType, type SliceTypeSteps, type SliceType, type SliceTypeStep
1111import { isLetter , isPunctuation , isWhitespace , stepsEqual } from './util' ;
1212import { ValueSyncStore } from '../../../util/events/sync-store' ;
1313import { MarkerOverlayPoint } from '../overlay/MarkerOverlayPoint' ;
14- import { UndefEndIter , type UndefIterator } from '../../../util/iterator' ;
14+ import { UndEndIterator , type UndEndNext } from '../../../util/iterator' ;
1515import { tick , Timespan , type ITimespanStruct } from '../../../json-crdt-patch' ;
1616import { CursorAnchor , SliceStacking , SliceHeaderMask , SliceHeaderShift , SliceTypeCon } from '../slice/constants' ;
1717import type { Point } from '../rga/Point' ;
@@ -114,7 +114,7 @@ export class Editor<T = string> implements Printable {
114114 return cursor ?? this . addCursor ( ) ;
115115 }
116116
117- public cursors0 ( ) : UndefIterator < Cursor < T > > {
117+ public cursors0 ( ) : UndEndNext < Cursor < T > > {
118118 const iterator = this . txt . localSlices . iterator0 ( ) ;
119119 return ( ) => {
120120 while ( true ) {
@@ -130,7 +130,7 @@ export class Editor<T = string> implements Printable {
130130 }
131131
132132 public cursors ( ) {
133- return new UndefEndIter ( this . cursors0 ( ) ) ;
133+ return new UndEndIterator ( this . cursors0 ( ) ) ;
134134 }
135135
136136 public forCursor ( callback : ( cursor : Cursor < T > ) => void ) : void {
@@ -777,7 +777,7 @@ export class Editor<T = string> implements Printable {
777777 * @param type The type of the marker.
778778 * @returns The inserted marker slice.
779779 */
780- public insStartMarker ( type : SliceType ) : MarkerSlice < T > {
780+ public insStartMarker ( type : SliceTypeSteps ) : MarkerSlice < T > {
781781 const txt = this . txt ;
782782 const start = txt . pointStart ( ) ?? txt . pointAbsStart ( ) ;
783783 start . refAfter ( ) ;
@@ -794,7 +794,7 @@ export class Editor<T = string> implements Printable {
794794 * @param type The new block type.
795795 * @returns The marker slice at the point, or a new marker slice if there is none.
796796 */
797- public setBlockType ( point : Point < T > , type : SliceType ) : MarkerSlice < T > {
797+ public setBlockType ( point : Point < T > , type : SliceTypeSteps ) : MarkerSlice < T > {
798798 const marker = this . getMarker ( point ) ;
799799 if ( marker ) {
800800 marker . update ( { type} ) ;
@@ -894,16 +894,15 @@ export class Editor<T = string> implements Printable {
894894 }
895895 }
896896
897- public setStartMarker ( type : SliceType , data ?: unknown , slices : EditorSlices < T > = this . saved ) : MarkerSlice < T > {
897+ public setStartMarker ( type : SliceTypeSteps , data ?: unknown , slices : EditorSlices < T > = this . saved ) : MarkerSlice < T > {
898898 const after = this . txt . pointStart ( ) ?? this . txt . pointAbsStart ( ) ;
899899 after . refAfter ( ) ;
900- if ( Array . isArray ( type ) && type . length === 1 ) type = type [ 0 ] ;
901900 return slices . slices . insMarkerAfter ( after . id , type , data ) ;
902901 }
903902
904903 public tglMarkerAt (
905904 point : Point < T > ,
906- type : SliceType ,
905+ type : SliceTypeSteps ,
907906 data ?: unknown ,
908907 slices : EditorSlices < T > = this . saved ,
909908 def : SliceTypeStep = SliceTypeCon . p ,
@@ -912,21 +911,24 @@ export class Editor<T = string> implements Printable {
912911 const markerPoint = overlay . getOrNextLowerMarker ( point ) ;
913912 if ( markerPoint ) {
914913 const marker = markerPoint . marker ;
915- const tag = marker . tag ( ) ;
916- if ( ! Array . isArray ( type ) ) type = [ type ] ;
917- const typeTag = type [ type . length - 1 ] ;
918- if ( tag === typeTag ) type = [ ...type . slice ( 0 , - 1 ) , def ] ;
919- if ( Array . isArray ( type ) && type . length === 1 ) type = type [ 0 ] ;
914+ const markerTag = marker . tag ( ) ;
915+ const tagStep = type [ type . length - 1 ] ;
916+ const tag = Array . isArray ( tagStep ) ? tagStep [ 0 ] : tagStep ;
917+ if ( markerTag === tag ) type = [ ...type . slice ( 0 , - 1 ) , def ] ;
920918 marker . update ( { type} ) ;
921919 } else this . setStartMarker ( type , data , slices ) ;
922920 }
923921
924- public updMarkerAt ( point : Point < T > , type : SliceType , data ?: unknown , slices : EditorSlices < T > = this . saved ) : void {
922+ public updMarkerAt (
923+ point : Point < T > ,
924+ type : SliceTypeSteps ,
925+ data ?: unknown ,
926+ slices : EditorSlices < T > = this . saved ,
927+ ) : void {
925928 const overlay = this . txt . overlay ;
926929 const markerPoint = overlay . getOrNextLowerMarker ( point ) ;
927930 if ( markerPoint ) {
928931 const marker = markerPoint . marker ;
929- if ( Array . isArray ( type ) && type . length === 1 ) type = type [ 0 ] ;
930932 marker . update ( { type} ) ;
931933 } else this . setStartMarker ( type , data , slices ) ;
932934 }
@@ -939,7 +941,7 @@ export class Editor<T = string> implements Printable {
939941 * @param data Custom data of the slice.
940942 */
941943 public tglMarker (
942- type : SliceType ,
944+ type : SliceTypeSteps ,
943945 data ?: unknown ,
944946 selection : Range < T > [ ] | IterableIterator < Range < T > > = this . cursors ( ) ,
945947 slices : EditorSlices < T > = this . saved ,
@@ -957,7 +959,7 @@ export class Editor<T = string> implements Printable {
957959 * of the document.
958960 */
959961 public updMarker (
960- type : SliceType ,
962+ type : SliceTypeSteps ,
961963 data ?: unknown ,
962964 selection : Range < T > [ ] | IterableIterator < Range < T > > = this . cursors ( ) ,
963965 slices : EditorSlices < T > = this . saved ,
@@ -1103,7 +1105,7 @@ export class Editor<T = string> implements Printable {
11031105 const [ , , , type , data ] = split ;
11041106 const after = txt . pointAt ( curr ) ;
11051107 after . refAfter ( ) ;
1106- txt . savedSlices . insMarkerAfter ( after . id , type , data ) ;
1108+ txt . savedSlices . insMarkerAfter ( after . id , type as SliceTypeSteps , data ) ;
11071109 curr += 1 ;
11081110 }
11091111 }
0 commit comments