diff options
author | aycabta <aycabta@gmail.com> | 2020-01-17 13:44:07 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2020-01-20 19:13:19 +0900 |
commit | b17797a6940cb196c9893edc088828b49772554c (patch) | |
tree | 4a687d1039f6fb8ebd63daf16f4a37a1befa5925 /lib | |
parent | 9f99760dafac6eaa53287470b8ff59b1be0bf6d6 (diff) | |
download | ruby-b17797a6940cb196c9893edc088828b49772554c.tar.gz |
[ruby/reline] Implement vi_to_next_char
https://github.com/ruby/reline/commit/066ecb0a21
Diffstat (limited to 'lib')
-rw-r--r-- | lib/reline/line_editor.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 1387bfa876..6890fa544a 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -2087,12 +2087,17 @@ class Reline::LineEditor @waiting_proc = ->(key_for_proc) { search_next_char(key_for_proc, arg) } end - private def search_next_char(key, arg) + private def vi_to_next_char(key, arg: 1) + @waiting_proc = ->(key_for_proc) { search_next_char(key_for_proc, arg, true) } + end + + private def search_next_char(key, arg, need_prev_char = false) if key.instance_of?(String) inputed_char = key else inputed_char = key.chr end + prev_total = nil total = nil found = false @line.byteslice(@byte_pointer..-1).grapheme_clusters.each do |mbchar| @@ -2110,13 +2115,18 @@ class Reline::LineEditor end end width = Reline::Unicode.get_mbchar_width(mbchar) + prev_total = total total = [total.first + mbchar.bytesize, total.last + width] end end - if found and total + if not need_prev_char and found and total byte_size, width = total @byte_pointer += byte_size @cursor += width + elsif need_prev_char and found and prev_total + byte_size, width = prev_total + @byte_pointer += byte_size + @cursor += width end @waiting_proc = nil end |