From b9aa85c767ede6bce4974fc16b43c915db552a0e Mon Sep 17 00:00:00 2001
From: gwenn <gtreguier@gmail.com>
Date: Sat, 8 Apr 2017 18:13:18 +0200
Subject: [PATCH] Fix history-search-backward

---
 src/keymap.rs |  3 +++
 src/lib.rs    | 15 +++++----------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/keymap.rs b/src/keymap.rs
index 448409e4..6d215a06 100644
--- a/src/keymap.rs
+++ b/src/keymap.rs
@@ -256,6 +256,7 @@ impl EditState {
         }
         let (n, positive) = self.emacs_num_args(); // consume them in all cases
         if let Some(cmd) = self.custom_bindings.borrow().get(&key) {
+            debug!(target: "rustyline", "Custom command: {:?}", cmd);
             return Ok(if cmd.is_repeatable() {
                           cmd.redo(Some(n))
                       } else {
@@ -380,6 +381,7 @@ impl EditState {
         let no_num_args = self.num_args == 0;
         let n = self.vi_num_args(); // consume them in all cases
         if let Some(cmd) = self.custom_bindings.borrow().get(&key) {
+            debug!(target: "rustyline", "Custom command: {:?}", cmd);
             return Ok(if cmd.is_repeatable() {
                           if no_num_args {
                               cmd.redo(None)
@@ -536,6 +538,7 @@ impl EditState {
     fn vi_insert<R: RawReader>(&mut self, rdr: &mut R) -> Result<Cmd> {
         let key = try!(rdr.next_key());
         if let Some(cmd) = self.custom_bindings.borrow().get(&key) {
+            debug!(target: "rustyline", "Custom command: {:?}", cmd);
             return Ok(if cmd.is_repeatable() {
                           cmd.redo(None)
                       } else {
diff --git a/src/lib.rs b/src/lib.rs
index 883f086e..27e246bd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -566,17 +566,12 @@ fn edit_history_next(s: &mut State, history: &History, prev: bool) -> Result<()>
 
 fn edit_history_search(s: &mut State, history: &History, dir: Direction) -> Result<()> {
     if history.is_empty() {
-        return Ok(());
+        return beep();
     }
-    if s.history_index == history.len() {
-        if dir == Direction::Reverse {
-            // Save the current edited line before to overwrite it
-            s.snapshot();
-        } else {
-            return Ok(());
-        }
+    if s.history_index == history.len() && dir == Direction::Forward {
+        return beep();
     } else if s.history_index == 0 && dir == Direction::Reverse {
-        return Ok(());
+        return beep();
     }
     if dir == Direction::Reverse {
         s.history_index -= 1;
@@ -590,7 +585,7 @@ fn edit_history_search(s: &mut State, history: &History, dir: Direction) -> Resu
         s.line.update(buf, buf.len());
         s.refresh_line()
     } else {
-        Ok(())
+        beep()
     }
 }
 
-- 
GitLab