File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -2087,12 +2087,17 @@ def finish
2087
2087
@waiting_proc = -> ( key_for_proc ) { search_next_char ( key_for_proc , arg ) }
2088
2088
end
2089
2089
2090
- private def search_next_char ( key , arg )
2090
+ private def vi_to_next_char ( key , arg : 1 )
2091
+ @waiting_proc = -> ( key_for_proc ) { search_next_char ( key_for_proc , arg , true ) }
2092
+ end
2093
+
2094
+ private def search_next_char ( key , arg , need_prev_char = false )
2091
2095
if key . instance_of? ( String )
2092
2096
inputed_char = key
2093
2097
else
2094
2098
inputed_char = key . chr
2095
2099
end
2100
+ prev_total = nil
2096
2101
total = nil
2097
2102
found = false
2098
2103
@line . byteslice ( @byte_pointer ..-1 ) . grapheme_clusters . each do |mbchar |
@@ -2110,13 +2115,18 @@ def finish
2110
2115
end
2111
2116
end
2112
2117
width = Reline ::Unicode . get_mbchar_width ( mbchar )
2118
+ prev_total = total
2113
2119
total = [ total . first + mbchar . bytesize , total . last + width ]
2114
2120
end
2115
2121
end
2116
- if found and total
2122
+ if not need_prev_char and found and total
2117
2123
byte_size , width = total
2118
2124
@byte_pointer += byte_size
2119
2125
@cursor += width
2126
+ elsif need_prev_char and found and prev_total
2127
+ byte_size , width = prev_total
2128
+ @byte_pointer += byte_size
2129
+ @cursor += width
2120
2130
end
2121
2131
@waiting_proc = nil
2122
2132
end
Original file line number Diff line number Diff line change @@ -633,6 +633,24 @@ def test_vi_next_char
633
633
assert_cursor_max ( 6 )
634
634
end
635
635
636
+ def test_vi_to_next_char
637
+ input_keys ( "abcdef\C -[0" )
638
+ assert_line ( 'abcdef' )
639
+ assert_byte_pointer_size ( '' )
640
+ assert_cursor ( 0 )
641
+ assert_cursor_max ( 6 )
642
+ input_keys ( 'tz' )
643
+ assert_line ( 'abcdef' )
644
+ assert_byte_pointer_size ( '' )
645
+ assert_cursor ( 0 )
646
+ assert_cursor_max ( 6 )
647
+ input_keys ( 'te' )
648
+ assert_line ( 'abcdef' )
649
+ assert_byte_pointer_size ( 'abc' )
650
+ assert_cursor ( 3 )
651
+ assert_cursor_max ( 6 )
652
+ end
653
+
636
654
def test_vi_delete_next_char
637
655
input_keys ( "abc\C -[h" )
638
656
assert_byte_pointer_size ( 'a' )
You can’t perform that action at this time.
0 commit comments