aboutsummaryrefslogtreecommitdiffstats
path: root/lib/reline
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-12-02 04:17:47 +0900
committeraycabta <aycabta@gmail.com>2019-12-02 04:18:22 +0900
commit103b04128f4e40b87bb9c7fb2916d2a800bfd94f (patch)
tree70296df70b50552e6c66b45bb35963e980e51062 /lib/reline
parentb3ea0980db87404c2b7763a3fdbe898c3812843d (diff)
downloadruby-103b04128f4e40b87bb9c7fb2916d2a800bfd94f.tar.gz
Support incremental search again by C-r in incremental search
Diffstat (limited to 'lib/reline')
-rw-r--r--lib/reline/line_editor.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 950bc3a955..fb0b47d7ee 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -1158,6 +1158,7 @@ class Reline::LineEditor
last_hit = nil
loop do
key = Fiber.yield(search_word)
+ search_again = false
case key
when "\C-h".ord, "\C-?".ord
grapheme_clusters = search_word.grapheme_clusters
@@ -1165,6 +1166,8 @@ class Reline::LineEditor
grapheme_clusters.pop
search_word = grapheme_clusters.join
end
+ when "\C-r".ord
+ search_again = true
else
multibyte_buf << key
if multibyte_buf.dup.force_encoding(@encoding).valid_encoding?
@@ -1177,7 +1180,11 @@ class Reline::LineEditor
@history_pointer = nil
hit = @line_backup_in_history
else
- if @history_pointer
+ if search_again
+ if @history_pointer
+ history = Reline::HISTORY[0..(@history_pointer - 1)]
+ end
+ elsif @history_pointer
history = Reline::HISTORY[0..@history_pointer]
else
history = Reline::HISTORY
@@ -1237,7 +1244,7 @@ class Reline::LineEditor
@cursor = @byte_pointer = 0
else
chr = k.is_a?(String) ? k : k.chr(Encoding::ASCII_8BIT)
- if chr.match?(/[[:print:]]/) or k == "\C-h".ord or k == "\C-?".ord
+ if chr.match?(/[[:print:]]/) or k == "\C-h".ord or k == "\C-?".ord or k == "\C-r".ord
searcher.resume(k)
else
if @history_pointer