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

ruby-changes:59024

From: aycabta <ko1@a...>
Date: Sun, 1 Dec 2019 23:56:32 +0900 (JST)
Subject: [ruby-changes:59024] 8cb3f29abf (master): The ed_search_prev_history should always search to backward

https://git.ruby-lang.org/ruby.git/commit/?id=8cb3f29abf

From 8cb3f29abf9290838bdc3b9904868c78752427e8 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Sun, 1 Dec 2019 23:53:59 +0900
Subject: The ed_search_prev_history should always search to backward


diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 71d7651..8c0b858 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -1175,7 +1175,12 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1175
           @history_pointer = nil
           hit = @line_backup_in_history
         else
-          hit_index = Reline::HISTORY.rindex { |item|
+          if @history_pointer
+            history = Reline::HISTORY[0..@history_pointer]
+          else
+            history = Reline::HISTORY
+          end
+          hit_index = history.rindex { |item|
             item.include?(search_word)
           }
           if hit_index
diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb
index 5857f65..931e596 100644
--- a/test/reline/test_key_actor_emacs.rb
+++ b/test/reline/test_key_actor_emacs.rb
@@ -1403,6 +1403,34 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_key_actor_emacs.rb#L1403
     @config.history_size = history_size
   end
 
+  def test_search_history_to_back
+    setup_editor
+    Reline::HISTORY.concat([
+      '1235', # old
+      '12aa',
+      '1234' # new
+    ])
+    assert_line('')
+    assert_byte_pointer_size('')
+    assert_cursor(0)
+    assert_cursor_max(0)
+    input_keys("\C-r123")
+    assert_line('1234')
+    assert_byte_pointer_size('')
+    assert_cursor(0)
+    assert_cursor_max(0) # doesn't determine yet
+    input_keys("\C-ha")
+    assert_line('12aa')
+    assert_byte_pointer_size('')
+    assert_cursor(0)
+    assert_cursor_max(0)
+    input_keys("\C-h3")
+    assert_line('1235')
+    assert_byte_pointer_size('')
+    assert_cursor(0)
+    assert_cursor_max(0)
+  end
+
   def test_em_set_mark_and_em_exchange_mark
     input_keys('aaa bbb ccc ddd')
     assert_byte_pointer_size('aaa bbb ccc ddd')
-- 
cgit v0.10.2


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

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