Repository: cloudhead/rx (language: rust)

Issue:
Command line ignores Home/End
While trying to figure out the best animation speed by eye, I discovered that, after using the up arrow in rx 0.4.0 to pull the `set` command back out of the command history, Home/End had no effect and I was forced to wait on the right arrow to get me to the value I wanted to tweak.


Discussion / hints:

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index f1fb12c..141d914 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -559,7 +559,7 @@ dependencies = [
 
 [[package]]
 name = "rx"
-version = "0.5.0"
+version = "0.5.1"
 dependencies = [
  "arrayvec",
  "chrono",
diff --git a/src/cmd.rs b/src/cmd.rs
index a4ab44a..463feb1 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -602,6 +602,17 @@ impl CommandLine {
         }
     }
 
+    pub fn cursor_back(&mut self) {
+        if self.cursor > 1 {
+            self.cursor = 1;
+            self.autocomplete.invalidate();
+        }
+    }
+
+    pub fn cursor_front(&mut self) {
+        self.cursor = self.input.len();
+    }
+
     pub fn putc(&mut self, c: char) {
         if self.input.len() + c.len_utf8() > self.input.capacity() {
             return;
@@ -1334,6 +1345,19 @@ mod test {
 
         cli.delc();
         assert_eq!(cli.input(), ":e");
+
+        cli.clear();
+        cli.puts(":echo");
+
+        assert_eq!(cli.peek(), None);
+        cli.cursor_back();
+
+        assert_eq!(cli.peek(), Some('e'));
+        assert_eq!(cli.peek_back(), Some(':'));
+
+        cli.cursor_front();
+        assert_eq!(cli.peek(), None);
+        assert_eq!(cli.peek_back(), Some('o'));
     }
 
     #[test]
diff --git a/src/session.rs b/src/session.rs
index 9017ad7..cbbbcf1 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -2286,6 +2286,12 @@ impl Session {
                             platform::Key::Escape => {
                                 self.cmdline_hide();
                             }
+                            platform::Key::Home => {
+                                self.cmdline.cursor_back();
+                            }
+                            platform::Key::End => {
+                                self.cmdline.cursor_front();
+                            }
                             _ => {}
                         }
                     }


Test patch: