UI: the shortcut recorder waits for the key; Interactive for PDF and Digital Publishing open their panels (#264)

* Keyboard Shortcuts: the recorder waits for the key pressed with the modifiers

* Workspaces: Interactive for PDF and Digital Publishing open their own panels
This commit is contained in:
aiongg authored and GitHub committed 2026-10-10 01:14:54 -04:00
1 parent 6a331e6712
commit 4fbf8938bf
2 files changed
+46 -3

No files matched your search

+23 -2
View File
@@ -144,6 +144,11 @@ fn user_dictionary(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {
});
}
fn is_modifier_key(key: egui::Key) -> bool {
use egui::Key::*;
matches!(key, ShiftLeft | ShiftRight | ControlLeft | ControlRight | AltLeft | AltRight | SuperLeft | SuperRight)
}
fn keyboard_shortcuts(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {
let mut q = d.s("query");
ui.add(
@@ -153,11 +158,12 @@ fn keyboard_shortcuts(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {
);
d.fields.insert("query".into(), json!(q));
let recording = d.s("recording");
// Capture the next key press for the command being recorded.
// Capture the next key press for the command being recorded. Pressing a modifier
// reports the modifier itself as a key; skip it and wait for the key it modifies.
if !recording.is_empty() {
let pressed = ui.input(|i| {
i.events.iter().find_map(|e| match e {
egui::Event::Key { key, pressed: true, modifiers, .. } => Some((*key, *modifiers)),
egui::Event::Key { key, pressed: true, modifiers, .. } if !is_modifier_key(*key) => Some((*key, *modifiers)),
_ => None,
})
});
@@ -2767,4 +2773,19 @@ mod tests {
let _ = command_fields(c.params);
}
}
#[test]
fn shortcut_recorder_waits_for_the_key_after_its_modifiers() {
let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
let mut d = Dialog::new("keyboardShortcuts", json!({"query": "", "recording": "app.palette"}));
let ctx = egui::Context::default();
let key = |key, modifiers| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers };
// Holding Ctrl reports Ctrl itself as a key press, then Ctrl+K arrives.
for event in [key(egui::Key::ControlLeft, egui::Modifiers::COMMAND), key(egui::Key::K, egui::Modifiers::COMMAND)] {
let input = egui::RawInput { events: vec![event], ..Default::default() };
ctx.run_ui(input, |ui| keyboard_shortcuts(&mut app, ui, &mut d)).textures_delta.clear();
}
assert_eq!(crate::menus::shortcut_of(&app, "app.palette").as_deref(), Some("Cmd+K"));
assert_eq!(d.s("recording"), "", "recording ends with the recorded shortcut");
}
}
+23 -1
View File
@@ -1360,10 +1360,20 @@ pub fn run_ui(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Value,
}
// Workspaces choose which bars and panels are visible.
app.ui.control_bar = matches!(name, "Advanced" | "Typography" | "Printing and Proofing" | "Book");
app.ui.dock_tab = if name == "Typography" { "properties".into() } else { app.ui.dock_tab.clone() };
let dock_tab = match name {
"Typography" => Some("properties"),
"Interactive for PDF" | "Digital Publishing" => Some("pages"),
_ => None,
};
if let Some(tab) = dock_tab {
app.ui.dock_tab = tab.into();
app.ui.dock_expanded = true;
}
app.ui.open_panel = match name {
"Typography" => Some("paragraphStyles".into()),
"Printing and Proofing" => Some("swatches".into()),
"Interactive for PDF" => Some("buttons".into()),
"Digital Publishing" => Some("liquid".into()),
_ => None,
};
app.ui.workspace = name.to_string();
@@ -2738,6 +2748,18 @@ mod tests {
assert_eq!(app.ui.workspace, "Essentials");
}
#[test]
fn interactive_workspaces_show_their_panels() {
let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
app.ui.dock_expanded = false;
run_ui(&mut app, "window.workspace", &json!({"name": "Interactive for PDF"})).unwrap().unwrap();
assert_eq!((app.ui.dock_tab.as_str(), app.ui.dock_expanded, app.ui.open_panel.as_deref()), ("pages", true, Some("buttons")));
run_ui(&mut app, "window.workspace", &json!({"name": "Digital Publishing"})).unwrap().unwrap();
assert_eq!((app.ui.dock_tab.as_str(), app.ui.open_panel.as_deref()), ("pages", Some("liquid")));
run_ui(&mut app, "window.workspace", &json!({"name": "Essentials"})).unwrap().unwrap();
assert_eq!(app.ui.open_panel, None);
}
#[test]
fn hide_and_show_menu_items() {
let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());