[前][次][番号順一覧][スレッド一覧]

ruby-changes:64841

From: aycabta <ko1@a...>
Date: Wed, 13 Jan 2021 01:13:34 +0900 (JST)
Subject: [ruby-changes:64841] 44817db28b (master): [ruby/reline] Handle ed_search_{prev, next}_history in multiline correctly

https://git.ruby-lang.org/ruby.git/commit/?id=44817db28b

From 44817db28bfc9a426732977893229e018687919d Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Sat, 9 Jan 2021 00:40:10 +0900
Subject: [ruby/reline] Handle ed_search_{prev,next}_history in multiline
 correctly

The current line was being handled incorrectly when displaying the hit
history, so it has been fixed to be correct.

https://github.com/ruby/reline/commit/a3df4343b3

diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 31211cd..3ecaef1 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -1732,7 +1732,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1732
       @buffer_of_lines = Reline::HISTORY[@history_pointer].split("\n")
       @buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty?
       @line_index = line_no
-      @line = @buffer_of_lines.last
+      @line = @buffer_of_lines[@line_index]
       @rerender_all = true
     else
       @line = Reline::HISTORY[@history_pointer]
@@ -1780,7 +1780,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1780
         @line_index = line_no
       end
       @buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty?
-      @line = @buffer_of_lines.last
+      @line = @buffer_of_lines[@line_index]
       @rerender_all = true
     else
       if @history_pointer.nil? and substr.empty?
diff --git a/test/reline/helper.rb b/test/reline/helper.rb
index 5593b0a..9712dde 100644
--- a/test/reline/helper.rb
+++ b/test/reline/helper.rb
@@ -96,4 +96,18 @@ class Reline::TestCase < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/helper.rb#L96
   def assert_cursor_max(expected)
     assert_equal(expected, @line_editor.instance_variable_get(:@cursor_max))
   end
+
+  def assert_line_index(expected)
+    assert_equal(expected, @line_editor.instance_variable_get(:@line_index))
+  end
+
+  def assert_whole_lines(expected)
+    previous_line_index = @line_editor.instance_variable_get(:@previous_line_index)
+    if previous_line_index
+      lines = @line_editor.whole_lines(index: previous_line_index)
+    else
+      lines = @line_editor.whole_lines
+    end
+    assert_equal(expected, lines)
+  end
 end
diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb
index 84233a9..b4dc3a1 100644
--- a/test/reline/test_key_actor_emacs.rb
+++ b/test/reline/test_key_actor_emacs.rb
@@ -2233,6 +2233,53 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_key_actor_emacs.rb#L2233
     assert_line('def hoge')
   end
 
+  def test_ed_search_prev_next_history_in_multibyte
+    Reline::HISTORY.concat([
+      "def hoge\n  67890\n  12345\nend", # old
+      "def aiu\n  0xDEADBEEF\nend",
+      "def foo\n  12345\nend" # new
+    ])
+    @line_editor.multiline_on
+    input_keys('  123')
+    # The ed_search_prev_history doesn't have default binding
+    @line_editor.__send__(:ed_search_prev_history, "\C-p".ord)
+    assert_whole_lines(['def foo', '  12345', 'end'])
+    assert_line_index(1)
+    assert_whole_lines(['def foo', '  12345', 'end'])
+    assert_byte_pointer_size('  123')
+    assert_cursor(5)
+    assert_cursor_max(7)
+    assert_line('  12345')
+    @line_editor.__send__(:ed_search_prev_history, "\C-p".ord)
+    assert_line_index(2)
+    assert_whole_lines(['def hoge', '  67890', '  12345', 'end'])
+    assert_byte_pointer_size('  123')
+    assert_cursor(5)
+    assert_cursor_max(7)
+    assert_line('  12345')
+    @line_editor.__send__(:ed_search_prev_history, "\C-p".ord)
+    assert_line_index(2)
+    assert_whole_lines(['def hoge', '  67890', '  12345', 'end'])
+    assert_byte_pointer_size('  123')
+    assert_cursor(5)
+    assert_cursor_max(7)
+    assert_line('  12345')
+    @line_editor.__send__(:ed_search_next_history, "\C-n".ord)
+    assert_line_index(1)
+    assert_whole_lines(['def foo', '  12345', 'end'])
+    assert_byte_pointer_size('  123')
+    assert_cursor(5)
+    assert_cursor_max(7)
+    assert_line('  12345')
+    @line_editor.__send__(:ed_search_next_history, "\C-n".ord)
+    assert_line_index(1)
+    assert_whole_lines(['def foo', '  12345', 'end'])
+    assert_byte_pointer_size('  123')
+    assert_cursor(5)
+    assert_cursor_max(7)
+    assert_line('  12345')
+  end
+
 =begin # TODO: move KeyStroke instance from Reline to LineEditor
   def test_key_delete
     input_keys('ab')
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]