Skip to content

Commit

Permalink
Implement vi_change_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Jan 21, 2020
1 parent 298e279 commit 8538e0e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/reline/line_editor.rb
Expand Up @@ -1922,6 +1922,18 @@ def finish
end

private def vi_change_meta(key)
@waiting_operator_proc = proc { |cursor_diff, byte_pointer_diff|
if byte_pointer_diff > 0
@line, cut = byteslice!(@line, @byte_pointer, byte_pointer_diff)
elsif byte_pointer_diff < 0
@line, cut = byteslice!(@line, @byte_pointer + byte_pointer_diff, -byte_pointer_diff)
end
copy_for_vi(cut)
@cursor += cursor_diff if cursor_diff < 0
@cursor_max -= cursor_diff.abs
@byte_pointer += byte_pointer_diff if byte_pointer_diff < 0
@config.editing_mode = :vi_insert
}
end

private def vi_delete_meta(key)
Expand Down
23 changes: 23 additions & 0 deletions test/reline/test_key_actor_vi.rb
Expand Up @@ -1214,4 +1214,27 @@ def test_vi_delete_meta
assert_cursor_max(11)
assert_line('aaa ddd eee')
end

def test_vi_change_meta
input_keys("aaa bbb ccc ddd eee\C-[02w")
assert_byte_pointer_size('aaa bbb ')
assert_cursor(8)
assert_cursor_max(19)
assert_line('aaa bbb ccc ddd eee')
input_keys('cwaiueo ')
assert_byte_pointer_size('aaa bbb aiueo ')
assert_cursor(14)
assert_cursor_max(21)
assert_line('aaa bbb aiueo ddd eee')
input_keys("\C-[")
assert_byte_pointer_size('aaa bbb aiueo')
assert_cursor(13)
assert_cursor_max(21)
assert_line('aaa bbb aiueo ddd eee')
input_keys('cb')
assert_byte_pointer_size('aaa bbb ')
assert_cursor(8)
assert_cursor_max(16)
assert_line('aaa bbb ddd eee')
end
end

0 comments on commit 8538e0e

Please sign in to comment.