From 73eec59f5848a54bdd9bb3cf75c09c1d42af302d Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Tue, 31 Aug 2021 02:11:49 +0200 Subject: [PATCH] ListEditor: better NavResult in dn(): avoid jumping when calling dn on lowest level --- nested/src/list/editor.rs | 6 +++--- shell/src/main.rs | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/nested/src/list/editor.rs b/nested/src/list/editor.rs index d04b754..f29638b 100644 --- a/nested/src/list/editor.rs +++ b/nested/src/list/editor.rs @@ -130,7 +130,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static, mode: new_cur.leaf_mode, idx: None }); - TreeNavResult::Exit + TreeNavResult::Continue } } @@ -328,12 +328,12 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static, ); } } + TreeNavResult::Continue } ListCursorMode::Modify => { - self.get_item().unwrap().write().unwrap().dn(); + self.get_item().unwrap().write().unwrap().dn() } } - TreeNavResult::Continue } fn pxev(&mut self) -> TreeNavResult { diff --git a/shell/src/main.rs b/shell/src/main.rs index e595bd8..24127ff 100644 --- a/shell/src/main.rs +++ b/shell/src/main.rs @@ -210,10 +210,13 @@ write:: } } TerminalEvent::Input(Event::Key(Key::Up)) => { te.up(); } - TerminalEvent::Input(Event::Key(Key::Down)) => { te.dn(); te.goto_home(); } + TerminalEvent::Input(Event::Key(Key::Down)) => { + if te.dn() == TreeNavResult::Continue { + te.goto_home(); + } + } TerminalEvent::Input(Event::Key(Key::Home)) => { if te.goto_home() == TreeNavResult::Exit { - te.goto_home(); } } @@ -334,6 +337,10 @@ write:: status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20)))); } status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)))); + } else { + for c in "Press to enter".chars() { + status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20)))); + } } }