From 7101c174f272581e2cedd9de41cb6678e71ee7b3 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Tue, 2 Mar 2021 09:10:36 -0800 Subject: [PATCH] Fix Dialog focus after removing buttons --- cursive-core/src/views/dialog.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cursive-core/src/views/dialog.rs b/cursive-core/src/views/dialog.rs index 15cc370..1d0cea2 100644 --- a/cursive-core/src/views/dialog.rs +++ b/cursive-core/src/views/dialog.rs @@ -230,7 +230,8 @@ impl Dialog { pub fn clear_buttons(&mut self) { self.buttons.clear(); self.invalidate(); - // Fix focus? + self.content.take_focus(Direction::none()); + self.focus = DialogFocus::Content; } /// Removes a button from this dialog. @@ -242,6 +243,17 @@ impl Dialog { self.buttons.remove(i); self.invalidate(); // Fix focus? + match (self.buttons.len(), self.focus) { + // TODO: take focus? + (0, ref mut focus) => { + self.content.take_focus(Direction::none()); + *focus = DialogFocus::Content; + } + (n, DialogFocus::Button(ref mut i)) => { + *i = usize::min(*i, n - 1); + } + _ => (), + } } /// Sets the horizontal alignment for the buttons, if any.