From c49d18034df4fb16ef874c814f63566db7ab6aa6 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Tue, 24 Jul 2018 22:37:39 -0700 Subject: [PATCH] Fix focus cycle on dialogs without buttons --- src/views/dialog.rs | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/views/dialog.rs b/src/views/dialog.rs index d3ad79d..4477099 100644 --- a/src/views/dialog.rs +++ b/src/views/dialog.rs @@ -286,16 +286,38 @@ impl Dialog { match self.content.on_event( event.relativized((self.padding + self.borders).top_left()), ) { - EventResult::Ignored if !self.buttons.is_empty() => { - match event { - Event::Key(Key::Down) - | Event::Key(Key::Tab) - | Event::Shift(Key::Tab) => { - // Default to leftmost button when going down. - self.focus = DialogFocus::Button(0); - EventResult::Consumed(None) + EventResult::Ignored => { + if !self.buttons.is_empty() { + match event { + Event::Key(Key::Down) + | Event::Key(Key::Tab) + | Event::Shift(Key::Tab) => { + // Default to leftmost button when going down. + self.focus = DialogFocus::Button(0); + EventResult::Consumed(None) + } + _ => EventResult::Ignored, + } + } else { + match event { + Event::Shift(Key::Tab) => { + if self.content.take_focus(Direction::back()) { + self.focus = DialogFocus::Content; + EventResult::Consumed(None) + } else { + EventResult::Ignored + } + } + Event::Key(Key::Tab) => { + if self.content.take_focus(Direction::front()) { + self.focus = DialogFocus::Content; + EventResult::Consumed(None) + } else { + EventResult::Ignored + } + } + _ => EventResult::Ignored, } - _ => EventResult::Ignored, } } res => res,