diff options
author | aycabta <aycabta@gmail.com> | 2019-12-17 13:10:39 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2019-12-17 13:10:39 +0900 |
commit | 618d09115185efa05f6948247d86087f4aa96118 (patch) | |
tree | a19f68b868bf51e07ac9720e89c0ef5b68dc80ee /lib | |
parent | a14a0244b48c422e392547b198af6fb57f7ca568 (diff) |
Support change search direction
Diffstat (limited to 'lib')
-rw-r--r-- | lib/reline/line_editor.rb | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index c74db5286d..9d8185ff00 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1196,6 +1196,7 @@ class Reline::LineEditor loop do key = Fiber.yield(search_word) search_again = false + change_direction = false case key when -1 # determined Reline.last_incremental_search = search_word @@ -1207,7 +1208,11 @@ class Reline::LineEditor search_word = grapheme_clusters.join end when "\C-r".ord, "\C-s".ord - search_again = true if prev_search_key == key + if prev_search_key == key + search_again = true + else + change_direction = true + end prev_search_key = key else multibyte_buf << key @@ -1229,10 +1234,19 @@ class Reline::LineEditor case prev_search_key when "\C-r".ord history_pointer_base = 0 - history = Reline::HISTORY[0..(@history_pointer - 1)] + if change_direction + history = Reline::HISTORY[0..@history_pointer] + else + history = Reline::HISTORY[0..(@history_pointer - 1)] + end when "\C-s".ord - history_pointer_base = @history_pointer + 1 - history = Reline::HISTORY[(@history_pointer + 1)..-1] + if change_direction + history_pointer_base = @history_pointer + history = Reline::HISTORY[(@history_pointer)..-1] + else + history_pointer_base = @history_pointer + 1 + history = Reline::HISTORY[(@history_pointer + 1)..-1] + end end else history_pointer_base = 0 @@ -1242,10 +1256,19 @@ class Reline::LineEditor case prev_search_key when "\C-r".ord history_pointer_base = 0 - history = Reline::HISTORY[0..@history_pointer] + if change_direction + history = Reline::HISTORY[0..@history_pointer] + else + history = Reline::HISTORY[0..@history_pointer] + end when "\C-s".ord - history_pointer_base = @history_pointer - history = Reline::HISTORY[@history_pointer..-1] + if change_direction + history_pointer_base = @history_pointer + history = Reline::HISTORY[(@history_pointer - 1)..-1] + else + history_pointer_base = @history_pointer + history = Reline::HISTORY[@history_pointer..-1] + end end else history_pointer_base = 0 |