From ef1ef0078ab304716972cbb42223ce2fa77075ca Mon Sep 17 00:00:00 2001 From: qwyng Date: Thu, 30 May 2024 23:31:03 +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.rb | 2 +- lib/reline/line_editor.rb | 2 +- test/reline/test_key_actor_emacs.rb | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index fb00b96531..dd4e032c61 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -4,7 +4,7 @@ require 'reline/config' require 'reline/key_actor' require 'reline/key_stroke' -require 'reline/line_editor' +require_relative 'reline/line_editor' require 'reline/history' require 'reline/terminfo' require 'reline/face' 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