Skip to content

Commit

Permalink
Merge pull request #361 from aycabta/support-arg-digit-by-meta-num
Browse files Browse the repository at this point in the history
Support ed_argument_digit by M+num
  • Loading branch information
aycabta authored Sep 29, 2021
2 parents 4b2e1e0 + 9183cc2 commit 8bb90ff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,7 @@ def finish
end
end

private def em_delete_prev_char(key)
private def em_delete_prev_char(key, arg: 1)
if @is_multiline and @cursor == 0 and @line_index > 0
@buffer_of_lines[@line_index] = @line
@cursor = calculate_width(@buffer_of_lines[@line_index - 1])
Expand All @@ -2512,6 +2512,8 @@ def finish
@cursor -= width
@cursor_max -= width
end
arg -= 1
em_delete_prev_char(key, arg: arg) if arg > 0
end
alias_method :backward_delete_char, :em_delete_prev_char

Expand Down Expand Up @@ -3072,7 +3074,14 @@ def finish

private def ed_argument_digit(key)
if @vi_arg.nil?
unless key.chr.to_i.zero?
if key.chr.to_i.zero?
if key.anybits?(0b10000000)
unescaped_key = key ^ 0b10000000
unless unescaped_key.chr.to_i.zero?
@vi_arg = unescaped_key.chr.to_i
end
end
else
@vi_arg = key.chr.to_i
end
else
Expand Down
14 changes: 14 additions & 0 deletions test/reline/test_key_actor_emacs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,20 @@ def test_ignore_NUL_by_ed_quoted_insert
assert_cursor_max(2)
end

def test_ed_argument_digit_by_meta_num
input_keys('abcdef')
assert_byte_pointer_size('abcdef')
assert_cursor(6)
assert_cursor_max(6)
assert_line('abcdef')
input_keys("\M-2", false)
input_keys("\C-h", false)
assert_byte_pointer_size('abcd')
assert_cursor(4)
assert_cursor_max(4)
assert_line('abcd')
end

def test_input_unknown_char
input_keys('͸') # U+0378 (unassigned)
assert_line('͸')
Expand Down

0 comments on commit 8bb90ff

Please sign in to comment.