@@ -628,6 +628,7 @@ export class Editor {
628
628
let pgx = this . offscreen . width - this . charwidth ;
629
629
let pgy = this . offscreen . height - this . em ;
630
630
631
+ const delay = 0 ;
631
632
if ( center ) {
632
633
this . scroll_x = Math . max ( 0 , this . em * row + this . hpad - pgy / 2 ) ;
633
634
this . scroll_y = Math . max ( 0 , this . charwidth * col - pgx / 2 ) ;
@@ -636,34 +637,41 @@ export class Editor {
636
637
this . scroll_x / window . devicePixelRatio ;
637
638
this . dom_scroller . scrollTop =
638
639
this . scroll_y / window . devicePixelRatio ;
639
- } , 0 ) ;
640
+ } , delay ) ;
640
641
} else {
641
642
if ( this . em * row < this . scroll_y ) {
642
643
this . scroll_y = this . em * row ;
643
644
window . setTimeout ( ( ) => {
645
+ this . scroll_y = this . em * row ;
644
646
this . dom_scroller . scrollTop =
645
647
this . scroll_y / window . devicePixelRatio ;
646
- } , 0 ) ;
648
+ } , delay ) ;
647
649
} else if ( this . em * row > this . scroll_y + pgy ) {
648
650
this . scroll_y = this . em * row - pgy ;
649
651
window . setTimeout ( ( ) => {
652
+ this . scroll_y = this . em * row - pgy ;
650
653
this . dom_scroller . scrollTop =
651
654
this . scroll_y / window . devicePixelRatio ;
652
- } , 0 ) ;
655
+ } , delay ) ;
653
656
}
654
657
655
658
if ( this . charwidth * col - this . hpad < this . scroll_x ) {
656
659
this . scroll_x = Math . max ( 0 , this . charwidth * col - this . hpad ) ;
657
660
window . setTimeout ( ( ) => {
661
+ this . scroll_x = Math . max (
662
+ 0 ,
663
+ this . charwidth * col - this . hpad
664
+ ) ;
658
665
this . dom_scroller . scrollLeft =
659
666
this . scroll_x / window . devicePixelRatio ;
660
- } , 0 ) ;
667
+ } , delay ) ;
661
668
} else if ( this . charwidth * col + this . hpad > this . scroll_x + pgx ) {
662
669
this . scroll_x = this . charwidth * col + this . hpad - pgx ;
663
670
window . setTimeout ( ( ) => {
671
+ this . scroll_x = this . charwidth * col + this . hpad - pgx ;
664
672
this . dom_scroller . scrollLeft =
665
673
this . scroll_x / window . devicePixelRatio ;
666
- } , 0 ) ;
674
+ } , delay ) ;
667
675
}
668
676
}
669
677
}
@@ -779,7 +787,10 @@ export class Editor {
779
787
}
780
788
781
789
// Create, execute, and add a SimpleAction.
782
- private simpleAction ( ins : null | string | Uint32Array ) {
790
+ private simpleAction (
791
+ ins : null | string | Uint32Array ,
792
+ canMerge : boolean = true
793
+ ) {
783
794
if ( this . readOnly ) return ;
784
795
785
796
let pos = this . document . cursor ;
@@ -796,9 +807,10 @@ export class Editor {
796
807
this . document ,
797
808
pos ,
798
809
rem ,
799
- ins ? ins : null
810
+ ins ? ins : null ,
811
+ canMerge
800
812
) ;
801
- this . document . execute ( action , true ) ;
813
+ this . document . execute ( action , canMerge ) ;
802
814
this . scrollIntoView ( ) ;
803
815
if ( this . eventHandlers . changed ) {
804
816
let { line, removed, inserted } = action . linesChanged (
@@ -862,7 +874,6 @@ export class Editor {
862
874
this . document . cursor = this . document . size ( ) ;
863
875
} else if ( bound === "undo" && ! this . readOnly ) {
864
876
let action = this . document . undo ( ) ;
865
- this . scrollIntoView ( ) ;
866
877
if ( this . eventHandlers . changed ) {
867
878
if ( action && action instanceof SimpleAction ) {
868
879
let { line, removed, inserted } = action . linesChanged (
@@ -871,9 +882,9 @@ export class Editor {
871
882
this . eventHandlers . changed ( line , inserted , removed ) ; // swap of inserted and removed is intentional!
872
883
} else this . eventHandlers . changed ( null , null , null ) ;
873
884
}
885
+ this . scrollIntoView ( ) ;
874
886
} else if ( bound === "redo" && ! this . readOnly ) {
875
887
let action = this . document . redo ( ) ;
876
- this . scrollIntoView ( ) ;
877
888
if ( this . eventHandlers . changed ) {
878
889
if ( action && action instanceof SimpleAction ) {
879
890
let { line, removed, inserted } = action . linesChanged (
@@ -882,6 +893,7 @@ export class Editor {
882
893
this . eventHandlers . changed ( line , removed , inserted ) ;
883
894
} else this . eventHandlers . changed ( null , null , null ) ;
884
895
}
896
+ this . scrollIntoView ( ) ;
885
897
} else if ( bound === "toggle comment" && ! this . readOnly ) {
886
898
// toggle line comments
887
899
let marker = this . document . language . linecomment ;
@@ -1282,7 +1294,7 @@ export class Editor {
1282
1294
if ( event . clipboardData && ! this . readOnly ) {
1283
1295
let s = event . clipboardData . getData ( "Text" ) ;
1284
1296
if ( selected || s . length > 0 ) {
1285
- this . simpleAction ( s ) ;
1297
+ this . simpleAction ( s , false ) ;
1286
1298
this . docChanged ( ) ;
1287
1299
this . draw ( ) ;
1288
1300
}
0 commit comments