Skip to content

Commit

Permalink
[ruby/reline] Key strokes like 2dl should behave d2l
Browse files Browse the repository at this point in the history
Key strokes, vi arg, operator, and motion should be treated as operator, vi
arg, and motion.

ruby/reline@d1a7e74aa4
  • Loading branch information
aycabta committed Dec 4, 2020
1 parent 21f2601 commit c850353
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions lib/reline/line_editor.rb
Expand Up @@ -179,6 +179,7 @@ def reset_variables(prompt = '', encoding:)
@vi_arg = nil
@waiting_proc = nil
@waiting_operator_proc = nil
@waiting_operator_vi_arg = nil
@completion_journey_data = nil
@completion_state = CompletionState::NORMAL
@perfect_matched = nil
Expand Down Expand Up @@ -698,6 +699,7 @@ def editing_mode
if @waiting_operator_proc
if VI_MOTIONS.include?(method_symbol)
old_cursor, old_byte_pointer = @cursor, @byte_pointer
@vi_arg = @waiting_operator_vi_arg if @waiting_operator_vi_arg > 1
block.(true)
unless @waiting_proc
cursor_diff, byte_pointer_diff = @cursor - old_cursor, @byte_pointer - old_byte_pointer
Expand All @@ -721,6 +723,8 @@ def editing_mode
block.(false)
end
@waiting_operator_proc = nil
@waiting_operator_vi_arg = nil
@vi_arg = nil
else
block.(false)
end
Expand Down Expand Up @@ -2088,7 +2092,7 @@ def finish
@cursor = 0
end

private def vi_change_meta(key)
private def vi_change_meta(key, arg: 1)
@waiting_operator_proc = proc { |cursor_diff, byte_pointer_diff|
if byte_pointer_diff > 0
@line, cut = byteslice!(@line, @byte_pointer, byte_pointer_diff)
Expand All @@ -2101,9 +2105,10 @@ def finish
@byte_pointer += byte_pointer_diff if byte_pointer_diff < 0
@config.editing_mode = :vi_insert
}
@waiting_operator_vi_arg = arg
end

private def vi_delete_meta(key)
private def vi_delete_meta(key, arg: 1)
@waiting_operator_proc = proc { |cursor_diff, byte_pointer_diff|
if byte_pointer_diff > 0
@line, cut = byteslice!(@line, @byte_pointer, byte_pointer_diff)
Expand All @@ -2115,9 +2120,10 @@ def finish
@cursor_max -= cursor_diff.abs
@byte_pointer += byte_pointer_diff if byte_pointer_diff < 0
}
@waiting_operator_vi_arg = arg
end

private def vi_yank(key)
private def vi_yank(key, arg: 1)
@waiting_operator_proc = proc { |cursor_diff, byte_pointer_diff|
if byte_pointer_diff > 0
cut = @line.byteslice(@byte_pointer, byte_pointer_diff)
Expand All @@ -2126,6 +2132,7 @@ def finish
end
copy_for_vi(cut)
}
@waiting_operator_vi_arg = arg
end

private def vi_list_or_eof(key)
Expand Down
6 changes: 3 additions & 3 deletions test/reline/test_key_actor_vi.rb
Expand Up @@ -1234,11 +1234,11 @@ def test_vi_delete_meta_with_arg
assert_cursor(8)
assert_cursor_max(11)
assert_line('aaa bbb ccc')
input_keys('2dl') # TODO This should delete 2 chars.
input_keys('2dl')
assert_byte_pointer_size('aaa bbb ')
assert_cursor(8)
assert_cursor_max(10)
assert_line('aaa bbb cc')
assert_cursor_max(9)
assert_line('aaa bbb c')
end

def test_vi_change_meta
Expand Down

0 comments on commit c850353

Please sign in to comment.