From d51772f7147b9132658b8fb567fdbe53e30d2d09 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 1 Sep 2016 11:37:03 -0700 Subject: [PATCH] EditView: move cursor on content change To the end of the content. --- src/lib.rs | 5 +---- src/views/edit_view.rs | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6421d32..061b31c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -348,10 +348,7 @@ impl Cursive { /// # } /// ``` pub fn find(&mut self, sel: &view::Selector) -> Option<&mut V> { - match self.find_any(sel) { - None => None, - Some(b) => b.downcast_mut::(), - } + self.find_any(sel).and_then(|b| b.downcast_mut::()) } /// Convenient method to use `find` with a `view::Selector::Id`. diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index 4293a0d..c886498 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -166,9 +166,9 @@ impl EditView { /// Replace the entire content of the view with the given one. pub fn set_content(&mut self, content: &str) { - self.offset = 0; - self.cursor = 0; self.content = Rc::new(content.to_string()); + self.offset = 0; + self.set_cursor(content.len()); } /// Get the current text.