@@ -58,6 +58,8 @@ use modalkit::editing::{
58
58
use modalkit:: errors:: { EditError , EditResult , UIResult } ;
59
59
use modalkit:: prelude:: * ;
60
60
61
+ use unicode_width:: UnicodeWidthStr ;
62
+
61
63
use super :: { ScrollActions , TerminalCursor , WindowOps } ;
62
64
63
65
/// Line annotation shown in the left gutter.
@@ -859,13 +861,18 @@ where
859
861
}
860
862
}
861
863
862
- let _ = buf. set_stringn ( x, y, s, width, self . style ) ;
863
-
864
864
if cursor_line {
865
- let coff = ( cursor. x - start) as u16 ;
865
+ let coff = s[ ..s
866
+ . char_indices ( )
867
+ . map ( |( i, _) | i)
868
+ . nth ( cursor. x . saturating_sub ( start) )
869
+ . unwrap_or ( s. len ( ) ) ] . width_cjk ( ) as u16 ;
870
+
866
871
state. term_cursor = ( x + coff, y) ;
867
872
}
868
873
874
+ let _ = buf. set_stringn ( x, y, s, width, self . style ) ;
875
+
869
876
self . _highlight_followers ( line, start, end, ( x, y) , & finfo, buf) ;
870
877
self . _highlight_line ( line, start, end, ( x, y) , & hinfo, buf) ;
871
878
@@ -1002,13 +1009,19 @@ where
1002
1009
1003
1010
let s = s. to_string ( ) ;
1004
1011
let w = ( right - x) as usize ;
1005
- let ( xres, _) = buf. set_stringn ( x, y, s, w, self . style ) ;
1006
1012
1007
1013
if cursor_line {
1008
- let coff = cursor. x . saturating_sub ( start) as u16 ;
1014
+ let coff = s[ ..s
1015
+ . char_indices ( )
1016
+ . map ( |( i, _) | i)
1017
+ . nth ( cursor. x . saturating_sub ( start) )
1018
+ . unwrap_or ( s. len ( ) ) ] . width_cjk ( ) as u16 ;
1019
+
1009
1020
state. term_cursor = ( x + coff, y) ;
1010
1021
}
1011
1022
1023
+ let ( xres, _) = buf. set_stringn ( x, y, s, w, self . style ) ;
1024
+
1012
1025
self . _highlight_followers ( line, start, end, ( x, y) , & finfo, buf) ;
1013
1026
self . _highlight_line ( line, start, end, ( x, y) , & hinfo, buf) ;
1014
1027
0 commit comments