8000 Implement vi_to_next_char · ruby/reline@066ecb0 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 066ecb0

Browse files
committed
Implement vi_to_next_char
1 parent e4fc1ee commit 066ecb0

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/reline/line_editor.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,12 +2087,17 @@ def finish
20872087
@waiting_proc = ->(key_for_proc) { search_next_char(key_for_proc, arg) }
20882088
end
20892089

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)
20912095
if key.instance_of?(String)
20922096
inputed_char = key
20932097
else
20942098
inputed_char = key.chr
20952099
end
2100+
prev_total = nil
20962101
total = nil
20972102
found = false
20982103
@line.byteslice(@byte_pointer..-1).grapheme_clusters.each do |mbchar|
@@ -2110,13 +2115,18 @@ def finish
21102115
end
21112116
end
21122117
width = Reline::Unicode.get_mbchar_width(mbchar)
2118+
prev_total = total
21132119
total = [total.first + mbchar.bytesize, total.last + width]
21142120
end
21152121
end
2116-
if found and total
2122+
if not need_prev_char and found and total
21172123
byte_size, width = total
21182124
@byte_pointer += byte_size
21192125
@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
21202130
end
21212131
@waiting_proc = nil
21222132
end

test/reline/test_key_actor_vi.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,24 @@ def test_vi_next_char
633633
assert_cursor_max(6)
634634
end
635635

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+
636654
def test_vi_delete_next_char
637655
input_keys("abc\C-[h")
638656
assert_byte_pointer_size('a')

0 commit comments

Comments
 (0)
0