Skip to main content

fret_runtime/
window_key_context_stack.rs

1use std::collections::HashMap;
2use std::sync::Arc;
3
4use fret_core::AppWindowId;
5
6/// Window-scoped key-context stack snapshots published by the UI runtime.
7///
8/// This is a data-only integration seam that allows keymap `when` expressions (`keyctx.*`) and
9/// cross-surface command gating (menus, palette, shortcut help) to observe the active key contexts
10/// without depending on `fret-ui` internals.
11#[derive(Debug, Default)]
12pub struct WindowKeyContextStackService {
13    by_window: HashMap<AppWindowId, Vec<Arc<str>>>,
14}
15
16impl WindowKeyContextStackService {
17    pub fn snapshot(&self, window: AppWindowId) -> Option<&[Arc<str>]> {
18        self.by_window.get(&window).map(|v| v.as_slice())
19    }
20
21    pub fn set_snapshot(&mut self, window: AppWindowId, key_contexts: Vec<Arc<str>>) {
22        self.by_window.insert(window, key_contexts);
23    }
24
25    pub fn remove_window(&mut self, window: AppWindowId) {
26        self.by_window.remove(&window);
27    }
28}