Skip to content

Commit

Permalink
Implement vi_insert_at_bol and vi_add_at_eol
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Jan 16, 2020
1 parent ec0b366 commit 800c2a8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/reline/line_editor.rb
Expand Up @@ -1890,6 +1890,16 @@ def finish
end
end

private def vi_insert_at_bol(key)
ed_move_to_beg(key)
@config.editing_mode = :vi_insert
end

private def vi_add_at_eol(key)
ed_move_to_end(key)
@config.editing_mode = :vi_insert
end

private def ed_delete_prev_char(key, arg: 1)
deleted = ''
arg.times do
Expand Down
36 changes: 36 additions & 0 deletions test/reline/test_key_actor_vi.rb
Expand Up @@ -56,6 +56,42 @@ def test_vi_add
assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
end

def test_vi_insert_at_bol
input_keys('I')
assert_line('I')
assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
input_keys("12345\C-[hh")
assert_line('I12345')
assert_byte_pointer_size('I12')
assert_cursor(3)
assert_cursor_max(6)
assert_instance_of(Reline::KeyActor::ViCommand, @config.editing_mode)
input_keys('I')
assert_line('I12345')
assert_byte_pointer_size('')
assert_cursor(0)
assert_cursor_max(6)
assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
end

def test_vi_add_at_eol
input_keys('A')
assert_line('A')
assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
input_keys("12345\C-[hh")
assert_line('A12345')
assert_byte_pointer_size('A12')
assert_cursor(3)
assert_cursor_max(6)
assert_instance_of(Reline::KeyActor::ViCommand, @config.editing_mode)
input_keys('A')
assert_line('A12345')
assert_byte_pointer_size('A12345')
assert_cursor(6)
assert_cursor_max(6)
assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
end

def test_ed_insert_one
input_keys('a')
assert_line('a')
Expand Down

0 comments on commit 800c2a8

Please sign in to comment.