mirror of https://github.com/linebender/xilem
Fix tab focus when no widget is currently focused (#593)
This commit is contained in:
parent
09d9ad555d
commit
7679e7c75e
|
@ -548,12 +548,15 @@ impl RenderRoot {
|
|||
}
|
||||
|
||||
pub(crate) fn widget_from_focus_chain(&mut self, forward: bool) -> Option<WidgetId> {
|
||||
self.state.focused_widget.and_then(|focus| {
|
||||
let focused_widget = self.state.focused_widget;
|
||||
let focused_idx = focused_widget.and_then(|focused_widget| {
|
||||
self.focus_chain()
|
||||
.iter()
|
||||
// Find where the focused widget is in the focus chain
|
||||
.position(|id| id == &focus)
|
||||
.map(|idx| {
|
||||
.position(|id| id == &focused_widget)
|
||||
});
|
||||
|
||||
if let Some(idx) = focused_idx {
|
||||
// Return the id that's next to it in the focus chain
|
||||
let len = self.focus_chain().len();
|
||||
let new_idx = if forward {
|
||||
|
@ -561,18 +564,17 @@ impl RenderRoot {
|
|||
} else {
|
||||
(idx + len - 1) % len
|
||||
};
|
||||
self.focus_chain()[new_idx]
|
||||
})
|
||||
.or_else(|| {
|
||||
// If the currently focused widget isn't in the focus chain,
|
||||
Some(self.focus_chain()[new_idx])
|
||||
} else {
|
||||
// If no widget is currently focused or the
|
||||
// currently focused widget isn't in the focus chain,
|
||||
// then we'll just return the first/last entry of the chain, if any.
|
||||
if forward {
|
||||
self.focus_chain().first().copied()
|
||||
} else {
|
||||
self.focus_chain().last().copied()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - Store in RenderRootState
|
||||
|
|
Loading…
Reference in New Issue