ruby-changes:63939
From: aycabta <ko1@a...>
Date: Sat, 5 Dec 2020 03:09:42 +0900 (JST)
Subject: [ruby-changes:63939] c85035363f (master): [ruby/reline] Key strokes like 2dl should behave d2l
https://git.ruby-lang.org/ruby.git/commit/?id=c85035363f From c85035363feb79d283a753db1fe795fff0067213 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sat, 14 Nov 2020 22:52:38 +0900 Subject: [ruby/reline] Key strokes like 2dl should behave d2l Key strokes, vi arg, operator, and motion should be treated as operator, vi arg, and motion. https://github.com/ruby/reline/commit/d1a7e74aa4 diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index ea1c913..c7b4e47 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -179,6 +179,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L179 @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 @@ -698,6 +699,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L699 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 @@ -721,6 +723,8 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L723 block.(false) end @waiting_operator_proc = nil + @waiting_operator_vi_arg = nil + @vi_arg = nil else block.(false) end @@ -2088,7 +2092,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L2092 @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) @@ -2101,9 +2105,10 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L2105 @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) @@ -2115,9 +2120,10 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L2120 @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) @@ -2126,6 +2132,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L2132 end copy_for_vi(cut) } + @waiting_operator_vi_arg = arg end private def vi_list_or_eof(key) diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb index fb7c804..edef573 100644 --- a/test/reline/test_key_actor_vi.rb +++ b/test/reline/test_key_actor_vi.rb @@ -1234,11 +1234,11 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_key_actor_vi.rb#L1234 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/