@@ -21,7 +21,16 @@ import type {Peritext} from '../Peritext';
2121import type { ChunkSlice } from '../util/ChunkSlice' ;
2222import type { MarkerSlice } from '../slice/MarkerSlice' ;
2323import type { SliceRegistry } from '../registry/SliceRegistry' ;
24- import type { CharIterator , CharPredicate , Position , TextRangeUnit , ViewStyle , ViewRange , ViewSlice } from './types' ;
24+ import type {
25+ CharIterator ,
26+ CharPredicate ,
27+ Position ,
28+ TextRangeUnit ,
29+ ViewStyle ,
30+ ViewRange ,
31+ ViewSlice ,
32+ EditorUi ,
33+ } from './types' ;
2534
2635/**
2736 * For inline boolean ("Overwrite") slices, both range endpoints should be
@@ -468,7 +477,7 @@ export class Editor<T = string> implements Printable {
468477 * @param unit The unit of move per step: "char", "word", "line", etc.
469478 * @returns The destination point after the move.
470479 */
471- public skip ( point : Point < T > , steps : number , unit : TextRangeUnit ) : Point < T > {
480+ public skip ( point : Point < T > , steps : number , unit : TextRangeUnit , ui ?: EditorUi < T > ) : Point < T > {
472481 if ( ! steps ) return point ;
473482 switch ( unit ) {
474483 case 'point' : {
@@ -485,10 +494,13 @@ export class Editor<T = string> implements Printable {
485494 return point ;
486495 }
487496 case 'line' : {
488- if ( steps > 0 ) for ( let i = 0 ; i < steps ; i ++ ) point = this . eol ( point ) ;
489- else for ( let i = 0 ; i < - steps ; i ++ ) point = this . bol ( point ) ;
497+ if ( steps > 0 ) for ( let i = 0 ; i < steps ; i ++ ) point = ui ?. eol ?. ( point , 1 ) ?? this . eol ( point ) ;
498+ else for ( let i = 0 ; i < - steps ; i ++ ) point = ui ?. eol ?. ( point , - 1 ) ?? this . bol ( point ) ;
490499 return point ;
491500 }
501+ case 'vert' : {
502+ return ui ?. vert ?.( point , steps ) || point ;
503+ }
492504 case 'block' : {
493505 if ( steps > 0 ) for ( let i = 0 ; i < steps ; i ++ ) point = this . eob ( point ) ;
494506 else for ( let i = 0 ; i < - steps ; i ++ ) point = this . bob ( point ) ;
@@ -507,26 +519,32 @@ export class Editor<T = string> implements Printable {
507519 * @param endpoint 0 for "focus", 1 for "anchor", 2 for both.
508520 * @param collapse Whether to collapse the range to a single point.
509521 */
510- public move ( steps : number , unit : TextRangeUnit , endpoint : 0 | 1 | 2 = 0 , collapse : boolean = true ) : void {
522+ public move (
523+ steps : number ,
524+ unit : TextRangeUnit ,
525+ endpoint : 0 | 1 | 2 = 0 ,
526+ collapse : boolean = true ,
527+ ui ?: EditorUi < T > ,
528+ ) : void {
511529 this . forCursor ( ( cursor ) => {
512530 switch ( endpoint ) {
513531 case 0 : {
514532 let point = cursor . focus ( ) ;
515- point = this . skip ( point , steps , unit ) ;
533+ point = this . skip ( point , steps , unit , ui ) ;
516534 if ( collapse ) cursor . set ( point ) ;
517535 else cursor . setEndpoint ( point , 0 ) ;
518536 break ;
519537 }
520538 case 1 : {
521539 let point = cursor . anchor ( ) ;
522- point = this . skip ( point , steps , unit ) ;
540+ point = this . skip ( point , steps , unit , ui ) ;
523541 if ( collapse ) cursor . set ( point ) ;
524542 else cursor . setEndpoint ( point , 1 ) ;
525543 break ;
526544 }
527545 case 2 : {
528- const start = this . skip ( cursor . start , steps , unit ) ;
529- const end = collapse ? start . clone ( ) : this . skip ( cursor . end , steps , unit ) ;
546+ const start = this . skip ( cursor . start , steps , unit , ui ) ;
547+ const end = collapse ? start . clone ( ) : this . skip ( cursor . end , steps , unit , ui ) ;
530548 cursor . set ( start , end ) ;
531549 break ;
532550 }
@@ -572,24 +590,24 @@ export class Editor<T = string> implements Printable {
572590 * @param unit Unit of the range expansion.
573591 * @returns Range which contains the specified unit.
574592 */
575- public range ( point : Point < T > , unit : TextRangeUnit ) : Range < T > | undefined {
593+ public range ( point : Point < T > , unit : TextRangeUnit , ui ?: EditorUi < T > ) : Range < T > | undefined {
576594 if ( unit === 'word' ) return this . rangeWord ( point ) ;
577- const point1 = this . skip ( point , - 1 , unit ) ;
578- const point2 = this . skip ( point , 1 , unit ) ;
595+ const point1 = this . skip ( point , - 1 , unit , ui ) ;
596+ const point2 = this . skip ( point , 1 , unit , ui ) ;
579597 return this . txt . range ( point1 , point2 ) ;
580598 }
581599
582- public select ( unit : TextRangeUnit ) : void {
600+ public select ( unit : TextRangeUnit , ui ?: EditorUi < T > ) : void {
583601 this . forCursor ( ( cursor ) => {
584- const range = this . range ( cursor . start , unit ) ;
602+ const range = this . range ( cursor . start , unit , ui ) ;
585603 if ( range ) cursor . set ( range . start , range . end , CursorAnchor . Start ) ;
586604 else this . delCursors ;
587605 } ) ;
588606 }
589607
590- public selectAt ( at : Position < T > , unit : TextRangeUnit | '' ) : void {
608+ public selectAt ( at : Position < T > , unit : TextRangeUnit | '' , ui ?: EditorUi < T > ) : void {
591609 this . cursor . set ( this . point ( at ) ) ;
592- if ( unit ) this . select ( unit ) ;
610+ if ( unit ) this . select ( unit , ui ) ;
593611 }
594612
595613 // --------------------------------------------------------------- formatting
0 commit comments