ruby-changes:59029
From: aycabta <ko1@a...>
Date: Mon, 2 Dec 2019 03:11:28 +0900 (JST)
Subject: [ruby-changes:59029] e15b0313a7 (master): Search history to back in the middle of histories
https://git.ruby-lang.org/ruby.git/commit/?id=e15b0313a7 From e15b0313a78a6f381720cf362a1a94bda49f62ff Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Mon, 2 Dec 2019 03:05:10 +0900 Subject: Search history to back in the middle of histories diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 8c0b858..1286adb 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1145,10 +1145,12 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1145 alias_method :end_of_line, :ed_move_to_end private def ed_search_prev_history(key) - if @is_multiline - @line_backup_in_history = whole_buffer - else - @line_backup_in_history = @line + unless @history_pointer + if @is_multiline + @line_backup_in_history = whole_buffer + else + @line_backup_in_history = @line + end end searcher = Fiber.new do search_word = String.new(encoding: @encoding) @@ -1171,7 +1173,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1173 end end hit = nil - if @line_backup_in_history.include?(search_word) + if @line_backup_in_history&.include?(search_word) @history_pointer = nil hit = @line_backup_in_history else diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 776c325..da2d41a 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -1430,6 +1430,28 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_key_actor_emacs.rb#L1430 assert_cursor_max(0) end + def test_search_history_to_back_in_the_middle_of_histories + Reline::HISTORY.concat([ + '1235', # old + '12aa', + '1234' # new + ]) + assert_line('') + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(0) + input_keys("\C-p\C-p") + assert_line('12aa') + assert_byte_pointer_size('12aa') + assert_cursor(4) + assert_cursor_max(4) + input_keys("\C-r123") + assert_line('1235') + assert_byte_pointer_size('1235') + assert_cursor(4) + assert_cursor_max(4) + 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/