From e5b09791af968cc95838549b21cd79d2d5f54947 Mon Sep 17 00:00:00 2001 From: qwyng Date: Thu, 30 May 2024 23:32:26 +0900 Subject: [PATCH] In ed_search_next_history, make the cursor come to the end of the line when there is no search substr --- lib/reline/line_editor.rb | 2 +- test/reline/test_key_actor_emacs.rb | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index af03fcd0c3..cde844555d 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1784,7 +1784,7 @@ def finish h_pointer, line_index = search_history(substr, history_range) return if h_pointer.nil? and not substr.empty? - move_history(h_pointer, line: line_index || :start, cursor: @byte_pointer) + move_history(h_pointer, line: line_index || :start, cursor: substr.empty? ? :end : @byte_pointer) arg -= 1 ed_search_next_history(key, arg: arg) if arg > 0 end diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 33149f3743..c5975bc774 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -1293,15 +1293,17 @@ def test_ed_search_next_history_with_empty ]) # The ed_search_prev_history and ed_search_next_history doesn't have default binding @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) - assert_line_around_cursor('', '12345') + assert_line_around_cursor('12345', '') @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) - assert_line_around_cursor('', '12aaa') + assert_line_around_cursor('12345', '') + 3.times { input_key_by_symbol(:ed_prev_char) } @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) - assert_line_around_cursor('', '12356') + assert_line_around_cursor('12', 'aaa') @line_editor.__send__(:ed_search_next_history, "\C-n".ord) - assert_line_around_cursor('', '12aaa') + assert_line_around_cursor('12', '345') @line_editor.__send__(:ed_search_next_history, "\C-n".ord) - assert_line_around_cursor('', '12345') + assert_line_around_cursor('12', '345') + 2.times { input_key_by_symbol(:ed_prev_char) } @line_editor.__send__(:ed_search_next_history, "\C-n".ord) assert_line_around_cursor('', '') end