use super::nav::Nav;
use crate::context::{key_routing::Owner, Context, DiagnosticKind};
use winit::keyboard::KeyCode;
impl Context {
pub(in crate::context) fn group_key(&mut self, code: KeyCode) -> bool {
let mods = self.input.modifiers;
if mods.control_key()
|| mods.alt_key()
|| mods.super_key()
|| mods.shift_key()
|| self.key_capture_active()
{
return false;
}
let Some(focused) = self.interaction.focused else {
return false;
};
let nav = self.focus_groups.navigate(focused, code);
if nav == Nav::Unhandled {
return false;
}
let in_open_layer = self
.interaction
.previous_hits
.iter()
.find(|hit| hit.id == focused && hit.action.focusable())
.is_some_and(|hit| self.key_layer_open(hit.window));
if !in_open_layer {
return false;
}
match nav {
Nav::Unhandled | Nav::Stay => {}
Nav::Move { target, group } => {
self.set_focus(Some(target));
self.interaction.keyboard_active = None;
self.focus_groups.moved.insert(group, target);
}
}
self.input.unpress(code);
self.keys.owners.insert(code, Owner::Navigation);
true
}
pub(crate) fn publish_focus_groups(&mut self) {
if self.focus_groups.is_open() {
self.report(DiagnosticKind::UnbalancedScope, None, None, || {
"focus group left open at the end of the pass; its closure did not return".into()
});
}
self.focus_groups
.publish(&self.interaction.previous_hits, self.interaction.focused);
}
}