Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vi_yank #200

Merged
merged 1 commit into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,14 @@ def finish
end

private def vi_yank(key)
@waiting_operator_proc = proc { |cursor_diff, byte_pointer_diff|
if byte_pointer_diff > 0
cut = @line.byteslice(@byte_pointer, byte_pointer_diff)
elsif byte_pointer_diff < 0
cut = @line.byteslice(@byte_pointer + byte_pointer_diff, -byte_pointer_diff)
end
copy_for_vi(cut)
}
end

private def vi_list_or_eof(key)
Expand Down
18 changes: 18 additions & 0 deletions test/reline/test_key_actor_vi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1276,4 +1276,22 @@ def test_unimplemented_vi_command_should_be_no_op
assert_cursor_max(3)
assert_line('abc')
end

def test_vi_yank
input_keys("foo bar\C-[0")
assert_line('foo bar')
assert_byte_pointer_size('')
assert_cursor(0)
assert_cursor_max(7)
input_keys('y3l')
assert_line('foo bar')
assert_byte_pointer_size('')
assert_cursor(0)
assert_cursor_max(7)
input_keys('P')
assert_line('foofoo bar')
assert_byte_pointer_size('fo')
assert_cursor(2)
assert_cursor_max(10)
end
end