diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 13ea74557..6ccb765c0 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -31,7 +31,7 @@ //! `ui.rename {text?, commit?}` finishes the rename box //! - `ui.window {action: minimize|maximize|restore|toggle|close}`: what the title bar's buttons do //! - `ui.confirm {accept?}`: the Delete confirmation (without `accept`: what it lists) -//! - `ui.shortcut {command, key?, replace?}`: a command's key, or bind one ("" clears) +//! - `ui.shortcut {command, key?, slot?, replace?}`: a command's keys, or bind one ("" clears) //! - `ui.help {item?: about|shortcuts|report}`: the Help menu; returns the version and diagnostics //! - `ui.prefs {...}`: the preferences (default_units, nav, zoom_reverse, orbit_around, msaa, //! length_decimals, angle_decimals); returns them all @@ -1022,12 +1022,14 @@ fn dispatch(app: &mut SolveApp, ctx: &egui::Context, method: &str, p: &Value) -> }, "ui.shortcut" => { let Some(id) = s("command") else { return err("missing `command`") }; + let slot = p.get("slot").and_then(Value::as_u64).map(|n| usize::try_from(n).unwrap_or(usize::MAX)); + let report = |app: &SolveApp| ok(json!({"command": id, "key": crate::keymap::effective(app, id), "keys": crate::keymap::keys(app, id)})); match s("key") { - Some(k) => match crate::keymap::bind(app, id, k, b("replace")) { - Ok(()) => ok(json!({"command": id, "key": crate::keymap::effective(app, id)})), + Some(k) => match crate::keymap::bind_at(app, id, slot, k, b("replace")) { + Ok(()) => report(app), Err(e) => err(e), }, - None => ok(json!({"command": id, "key": crate::keymap::effective(app, id)})), + None => report(app), } } "ui.browser" => ok(json!({ diff --git a/crates/ui-egui/src/keymap.rs b/crates/ui-egui/src/keymap.rs index f05e04029..0660ab43f 100644 --- a/crates/ui-egui/src/keymap.rs +++ b/crates/ui-egui/src/keymap.rs @@ -1,5 +1,5 @@ //! Keyboard shortcuts: every command's default key comes from its `CommandSpec`; the user can -//! rebind or clear any of them (Preferences › Keyboard Shortcuts). A new key that another command +//! rebind or clear any of them, or give one several keys (Preferences › Keyboard Shortcuts). A new key that another command //! already uses is reported and only taken over on request; keys the app itself handles (Esc, S, //! V, Delete, Ctrl+Z…) can't be bound. Changes are kept between runs. @@ -48,10 +48,14 @@ pub const RESERVED: &[&str] = &[ "Ctrl+8", ]; +/// The most keys one command keeps; more from a settings file are dropped. +const MAX_KEYS: usize = 8; + #[derive(Default)] pub struct Keymap { - /// Command id → key (`""`: no key). Only the changed ones. - pub custom: BTreeMap, + /// Command id → its keys, the first one shown in menus and tooltips (none: no key). Only the + /// changed ones. + pub custom: BTreeMap>, /// Asks for the Keyboard Shortcuts page of Preferences (File and Help menus). pub open: bool, /// Opened from Help: a list to read, not to edit. @@ -59,9 +63,11 @@ pub struct Keymap { filter: String, /// The command waiting for a key press. capturing: Option, + /// Which of its keys the press replaces; one past the last adds a key. + slot: usize, recorder: Recorder, - /// A key that another command uses: (command, key, the other commands). - conflict: Option<(String, String, Vec)>, + /// A key that another command uses: (command, key, its slot, the other commands). + conflict: Option<(String, String, usize, Vec)>, message: Option, } @@ -172,15 +178,28 @@ impl Recorder { } impl Keymap { + /// One key is saved as a string, as before a command could have several, so older versions + /// still read it. pub fn prefs(&self) -> Value { - json!(self.custom) + Value::Object( + self.custom + .iter() + .map(|(id, keys)| { + let v = match keys.as_slice() { + [] => json!(""), + [key] => json!(key), + _ => json!(keys), + }; + (id.clone(), v) + }) + .collect(), + ) } pub fn load(&mut self, v: &Value) { - self.custom = - v.as_object().map(|o| o.iter().take(2000).filter_map(|(k, v)| Some((k.clone(), v.as_str()?.to_string()))).collect()).unwrap_or_default(); - // A shortcut that named a modifier key twice ("Shift+ShiftLeft", from before the shift + self.custom = v.as_object().map(|o| o.iter().take(2000).filter_map(|(k, v)| Some((k.clone(), saved_keys(v)?))).collect()).unwrap_or_default(); + // A shortcut that named a modifier key twice ("Shift+ShiftLeft", before shift // keys were named after themselves) is the modifier itself (#4582). - for key in self.custom.values_mut() { + for key in self.custom.values_mut().flatten() { if let Some(named) = named_modifier_key(key) { *key = named; } @@ -188,6 +207,16 @@ impl Keymap { } } +/// A command's saved keys: `""` (none), one key, or a list of them. +fn saved_keys(v: &Value) -> Option> { + match v { + Value::String(key) if key.is_empty() => Some(Vec::new()), + Value::String(key) => Some(vec![key.clone()]), + Value::Array(keys) => Some(keys.iter().filter_map(Value::as_str).filter(|k| !k.is_empty()).take(MAX_KEYS).map(str::to_string).collect()), + _ => None, + } +} + /// A key press as a shortcut name: `E`, `Shift+E`, `Ctrl+Alt+K`, `F5`, `Delete`. /// /// A modifier key is the shortcut itself, and its two sides are the same shortcut (the app's @@ -277,18 +306,25 @@ fn named_modifier_key(key: &str) -> Option { Some(parts.join("+")) } -/// The key a command runs from now. +/// The key a command runs from now, the one menus and tooltips show: its first. pub fn effective(app: &SolveApp, id: &str) -> Option { + keys(app, id).into_iter().next() +} + +/// Every key a command runs from now. +pub fn keys(app: &SolveApp, id: &str) -> Vec { match app.keymap.custom.get(id) { - Some(k) if k.is_empty() => None, - Some(k) => Some(k.clone()), - None => solidcraft_engine::find_command(id).and_then(|c| c.shortcut).map(str::to_string), + Some(keys) => keys.clone(), + None => solidcraft_engine::find_command(id).and_then(|c| c.shortcut).filter(|k| !k.is_empty()).map(str::to_string).into_iter().collect(), } } /// Use the spec already available when walking the command list. -fn effective_for_spec<'a>(app: &'a SolveApp, command: &CommandSpec) -> Option<&'a str> { - app.keymap.custom.get(command.id).map(String::as_str).or(command.shortcut).filter(|key| !key.is_empty()) +fn keys_for_spec<'a>(app: &'a SolveApp, command: &CommandSpec) -> Vec<&'a str> { + match app.keymap.custom.get(command.id) { + Some(keys) => keys.iter().map(String::as_str).collect(), + None => command.shortcut.filter(|k| !k.is_empty()).into_iter().collect(), + } } /// Presentation only: stored Ctrl bindings retain their historical primary-modifier alias. @@ -315,7 +351,7 @@ pub fn display_for(app: &SolveApp, id: &str) -> Option { /// Commands bound to `key` now. pub fn commands_for(app: &SolveApp, key: &str) -> Vec<&'static str> { - command_specs().into_iter().filter(|c| effective(app, c.id).as_deref() == Some(key)).map(|c| c.id).collect() + command_specs().into_iter().filter(|c| keys_for_spec(app, c).contains(&key)).map(|c| c.id).collect() } /// Where a command's shortcut works: in a sketch (the SKETCH tab's tools), in the model (the @@ -417,14 +453,24 @@ fn sketch_tool_for(app: &SolveApp, key: &str) -> Option<&'static str> { }) } -/// Bind `key` to a command (`""` clears it). Refused for reserved keys, and when other commands -/// use the key unless `replace` (they lose it). A sketch tool and a model command may share a -/// key: each runs in its own mode. +/// Make `key` a command's only key (`""` clears its keys). See [`bind_at`]. pub fn bind(app: &mut SolveApp, id: &str, key: &str, replace: bool) -> Result<(), String> { + bind_at(app, id, None, key, replace) +} + +/// Give a command `key`: as its only key (`slot` `None`), or in place of its key at `slot` (one +/// past the last adds a key; `""` there removes that key). Refused for reserved keys, and when +/// other commands use the key unless `replace` (they lose that key and keep their others). A +/// sketch tool and a model command may share a key: each runs in its own mode. +pub fn bind_at(app: &mut SolveApp, id: &str, slot: Option, key: &str, replace: bool) -> Result<(), String> { let spec = solidcraft_engine::find_command(id).ok_or_else(|| format!("no command `{id}`"))?; if RESERVED.contains(&key) { return Err(format!("{key} is used by SolidCraft itself")); } + let mut list = keys(app, id); + if slot.is_some_and(|n| n >= list.len()) && list.len() >= MAX_KEYS { + return Err(format!("a command has at most {MAX_KEYS} keys")); + } if !key.is_empty() { let others: Vec<&'static str> = commands_for(app, key).into_iter().filter(|o| *o != id && clash(o, id)).collect(); if !others.is_empty() && !replace { @@ -432,15 +478,37 @@ pub fn bind(app: &mut SolveApp, id: &str, key: &str, replace: bool) -> Result<() return Err(format!("{key} is already used by {}", names.join(", "))); } for o in others { - app.keymap.custom.insert(o.to_string(), String::new()); + let mut theirs = keys(app, o); + theirs.retain(|k| k != key); + set_keys(app, o, theirs); } } - if spec.shortcut.unwrap_or("") == key { + match slot { + None => list = vec![key.to_string()], + Some(n) if n < list.len() && key.is_empty() => drop(list.remove(n)), + Some(n) => match list.get_mut(n) { + Some(old) => *old = key.to_string(), + None => list.push(key.to_string()), + }, + } + let mut unique: Vec = Vec::new(); + for k in list { + if !k.is_empty() && !unique.contains(&k) { + unique.push(k); + } + } + set_keys(app, spec.id, unique); + Ok(()) +} + +/// Keep a command's keys, as a change only when they aren't its default. +fn set_keys(app: &mut SolveApp, id: &str, keys: Vec) { + let default = solidcraft_engine::find_command(id).and_then(|c| c.shortcut).filter(|k| !k.is_empty()); + if keys.iter().map(String::as_str).eq(default) { app.keymap.custom.remove(id); } else { - app.keymap.custom.insert(id.to_string(), key.to_string()); + app.keymap.custom.insert(id.to_string(), keys); } - Ok(()) } pub fn reset(app: &mut SolveApp, id: Option<&str>) { @@ -481,10 +549,12 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) { } Recording::Complete(name) => { app.keymap.capturing = None; - match bind(app, &id, &name, false) { + let slot = app.keymap.slot; + match bind_at(app, &id, Some(slot), &name, false) { Ok(()) => app.keymap.message = None, Err(e) if e.contains("already used") => { - app.keymap.conflict = Some((id.clone(), name.clone(), commands_for(app, &name).iter().map(|s| s.to_string()).collect())); + app.keymap.conflict = + Some((id.clone(), name.clone(), slot, commands_for(app, &name).iter().map(|s| s.to_string()).collect())); app.keymap.message = Some(e); } Err(e) => app.keymap.message = Some(e), @@ -535,12 +605,12 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) { if let Some(m) = &app.keymap.message { ui_kit::text(ui, m, ui_kit::Text::Report("keymap_message", true)); } - if let Some((id, key, _)) = app.keymap.conflict.clone() { + if let Some((_, key, _, _)) = app.keymap.conflict.clone() { ui.horizontal_wrapped(|ui| { let replace = ui_kit::button(ui, crate::i18n::format("keymap.use_anyway", &[("key", &display(&key))]), ui_kit::Button::Normal); crate::scenario::publish_target("keymap:replace", replace.rect); if replace.clicked() { - action = Some((format!("{id}\n{key}"), "replace")); + action = Some((String::new(), "replace")); } if ui_kit::button(ui, app.tr_label("Cancel"), ui_kit::Button::Normal).clicked() { action = Some((String::new(), "cancel")); @@ -560,14 +630,14 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) { let commands: Vec<_> = command_specs() .into_iter() .filter_map(|c| { - let key = effective_for_spec(app, c).unwrap_or_default(); + let keys = keys_for_spec(app, c); let label = app.tr_label(c.label); let hit = if filtering { - crate::prefs_search::matches_text(&q, &[c.label, c.id, key, label]) + crate::prefs_search::matches_text(&q, &[c.label, c.id, label].into_iter().chain(keys.iter().copied()).collect::>()) } else { - q.is_empty() || [c.label, c.id, key, label].iter().any(|s| s.to_lowercase().contains(&q)) + q.is_empty() || [c.label, c.id, label].iter().chain(&keys).any(|s| s.to_lowercase().contains(&q)) }; - hit.then_some((c, key, label)) + hit.then_some((c, keys, label)) }) .collect(); if filtering && commands.is_empty() { @@ -577,9 +647,10 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) { let shortcut_title = app.tr("prefs.shortcuts").to_string(); let paint = |ui: &mut egui::Ui| { let t = crate::theme::Tokens::get(); + let spacing = ui.spacing().item_spacing.x; let key_width = commands .iter() - .map(|(_, key, _)| ui_kit::ContentWidth::button(ui, &display(key))) + .map(|(_, keys, _)| keys.iter().map(|key| ui_kit::ContentWidth::button(ui, &display(key)) + spacing).sum::() + t.control_height) .chain(app.keymap.recorder.preview().filter(|_| app.keymap.capturing.is_some()).map(|text| ui_kit::ContentWidth::button(ui, &text))) .fold(ui_kit::ContentWidth::button(ui, app.tr_label("press a key…")), f32::max) .max(ui_kit::ContentWidth::label(ui, app.tr_label("Keyboard Shortcuts")) + t.space_8); @@ -595,7 +666,7 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) { ui_kit::Column::new("", 0.0).icon_only().min_content_width(action_width), ]; ui_kit::table(ui, "keymap", &columns, crate::i18n::tr("keymap.empty"), |ui, table| { - for (c, key, translated_label) in commands { + for (c, keys, translated_label) in commands { table.row_visible(ui, c.id, app.keymap.capturing.as_deref() == Some(c.id), false, |row| { row.cell(|ui| { ui_kit::text(ui, translated_label, ui_kit::Text::Cell); @@ -605,37 +676,45 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) { }); let capturing = app.keymap.capturing.as_deref() == Some(c.id); let changed = app.keymap.custom.contains_key(c.id); - let text = if capturing { - app.keymap.recorder.preview().unwrap_or_else(|| app.tr_label("press a key…").to_string()) - } else if key.is_empty() { - "—".to_string() - } else { - display(key) - }; row.cell(|ui| { if app.keymap.read_only { - ui_kit::text(ui, &text, ui_kit::Text::Cell); - } else { - let capture = if key.is_empty() && !capturing { - let (rect, _) = ui.allocate_exact_size(egui::vec2(t.control_height, t.control_height), egui::Sense::hover()); - ui_kit::quiet_icon_button_at(ui, rect, "plus", app.tr_label("Click, then press the new key")) + let text = if keys.is_empty() { + "—".to_string() } else { - ui_kit::button(ui, &text, ui_kit::Button::Normal).on_hover_text(app.tr_label("Click, then press the new key")) + keys.iter().map(|key| display(key)).collect::>().join(", ") }; - crate::scenario::publish_target(&format!("keymap:capture:{}", c.id), capture.rect); - if ui.is_rect_visible(capture.rect) { - crate::scenario::publish_handle(&format!("shortcut:{}", c.id), capture.rect.center()); - } - if capture.clicked() { - capture.surrender_focus(); - action = Some((c.id.to_string(), "capture")); - } + ui_kit::text(ui, &text, ui_kit::Text::Cell); + return; } + let tip = app.tr_label("Click, then press the new key"); + ui.horizontal(|ui| { + // Each key replaces itself when clicked; the last slot adds one. + for slot in 0..=keys.len() { + let capture = if capturing && app.keymap.slot == slot { + let text = app.keymap.recorder.preview().unwrap_or_else(|| app.tr_label("press a key…").to_string()); + ui_kit::button(ui, &text, ui_kit::Button::Normal).on_hover_text(tip) + } else if let Some(key) = keys.get(slot) { + ui_kit::button(ui, display(key), ui_kit::Button::Normal).on_hover_text(tip) + } else { + let (rect, _) = ui.allocate_exact_size(egui::vec2(t.control_height, t.control_height), egui::Sense::hover()); + ui_kit::quiet_icon_button_at(ui, rect, "plus", tip) + }; + let name = if slot == 0 { c.id.to_string() } else { format!("{}:{slot}", c.id) }; + crate::scenario::publish_target(&format!("keymap:capture:{name}"), capture.rect); + if ui.is_rect_visible(capture.rect) { + crate::scenario::publish_handle(&format!("shortcut:{name}"), capture.rect.center()); + } + if capture.clicked() { + capture.surrender_focus(); + action = Some((format!("{}\n{slot}", c.id), "capture")); + } + } + }); }); row.cell(|ui| { if !app.keymap.read_only { ui.horizontal(|ui| { - let clear = ui_kit::button(ui, app.tr_label("Clear"), ui_kit::Button::Enabled(!key.is_empty())); + let clear = ui_kit::button(ui, app.tr_label("Clear"), ui_kit::Button::Enabled(!keys.is_empty())); crate::scenario::publish_target(&format!("keymap:clear:{}", c.id), clear.rect); if clear.clicked() { action = Some((c.id.to_string(), "clear")); @@ -664,8 +743,10 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) { app.keymap.recorder = Recorder::default(); } match action { - Some((id, "capture")) => { - app.keymap.capturing = Some(id); + Some((pair, "capture")) => { + let (id, slot) = pair.split_once('\n').unwrap_or((&pair, "0")); + app.keymap.slot = slot.parse().unwrap_or(0); + app.keymap.capturing = Some(id.to_string()); app.keymap.recorder = Recorder::default(); app.keymap.conflict = None; app.keymap.message = None; @@ -693,9 +774,9 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) { app.keymap.message = r.err().map(|e| format!("import: {e}")); }); } - Some((pair, "replace")) => { - if let Some((id, key)) = pair.split_once('\n') { - let _ = bind(app, id, key, true); + Some((_, "replace")) => { + if let Some((id, key, slot, _)) = app.keymap.conflict.take() { + let _ = bind_at(app, &id, Some(slot), &key, true); } app.keymap.conflict = None; app.keymap.message = None; @@ -909,7 +990,7 @@ mod tests { recorder_frame(&mut a, &ctx, 0.0, vec![event(egui::Key::M, true, egui::Modifiers::NONE), event(egui::Key::M, false, egui::Modifiers::NONE)]); assert!(a.keymap.conflict.is_none()); recorder_frame(&mut a, &ctx, 1.1, vec![]); - assert_eq!(a.keymap.conflict.as_ref().map(|(_, key, _)| key.as_str()), Some("M")); + assert_eq!(a.keymap.conflict.as_ref().map(|(_, key, _, _)| key.as_str()), Some("M")); assert_eq!(effective(&a, "solid.move").as_deref(), Some("M")); assert_eq!(effective(&a, "solid.chamfer"), None); stop_capture(&mut a); @@ -1052,6 +1133,68 @@ mod tests { assert_eq!(key_name(egui::Key::K, egui::Modifiers { ctrl: true, shift: true, ..Default::default() }), "Ctrl+Shift+K"); } + /// A command can run from several keys: the first is the one menus show, a key another + /// command takes over leaves its other keys, and one key is saved as before. + #[test] + fn a_command_runs_from_several_keys() { + let mut a = app(); + bind_at(&mut a, "solid.extrude", Some(1), "Shift+J", false).unwrap(); + assert_eq!(keys(&a, "solid.extrude"), ["E", "Shift+J"]); + assert_eq!(effective(&a, "solid.extrude").as_deref(), Some("E"), "the first key is shown"); + assert_eq!(commands_for(&a, "E"), vec!["solid.extrude"]); + assert_eq!(commands_for(&a, "Shift+J"), vec!["solid.extrude"]); + bind_at(&mut a, "solid.extrude", Some(5), "Shift+J", false).unwrap(); + assert_eq!(keys(&a, "solid.extrude"), ["E", "Shift+J"], "a key is kept once"); + assert!(bind_at(&mut a, "solid.extrude", Some(2), "M", false).is_err(), "Move/Copy's key"); + // Taking a key over leaves the other command its other keys. + bind_at(&mut a, "solid.revolve", None, "Shift+J", true).unwrap(); + assert_eq!(keys(&a, "solid.extrude"), ["E"]); + assert!(!a.keymap.custom.contains_key("solid.extrude"), "back to its default"); + // Saved as a list, and one key as a string. + bind_at(&mut a, "solid.extrude", Some(1), "Shift+K", false).unwrap(); + let saved = a.keymap.prefs(); + assert_eq!(saved["solid.extrude"], json!(["E", "Shift+K"])); + assert_eq!(saved["solid.revolve"], json!("Shift+J")); + let mut b = app(); + b.keymap.load(&saved); + assert_eq!(keys(&b, "solid.extrude"), ["E", "Shift+K"]); + // A legacy modifier name in a list is renamed, as in a single key (#4582). + let mut c = app(); + c.keymap.load(&json!({"solid.extrude": ["E", "Ctrl+ShiftLeft"]})); + assert_eq!(keys(&c, "solid.extrude"), ["E", "Ctrl+Shift"]); + // `""` at a slot removes that key; without one it clears them all. + bind_at(&mut b, "solid.extrude", Some(0), "", false).unwrap(); + assert_eq!(keys(&b, "solid.extrude"), ["Shift+K"]); + bind(&mut b, "solid.extrude", "", false).unwrap(); + assert!(keys(&b, "solid.extrude").is_empty()); + assert_eq!(b.keymap.prefs()["solid.extrude"], json!("")); + // A hostile settings file can't give one command endless keys. + let many: Vec = (0..50).map(|n| format!("Ctrl+Alt+F{n}")).collect(); + b.keymap.load(&json!({"solid.extrude": many})); + assert_eq!(keys(&b, "solid.extrude").len(), MAX_KEYS); + assert!(bind_at(&mut b, "solid.extrude", Some(MAX_KEYS), "Shift+L", false).is_err()); + } + + /// On the page: the + after a command's key records one more, and both keys run it. + #[test] + fn the_shortcuts_page_adds_a_second_key() { + let mut h = crate::scenario::Harness::new(); + h.app.home.open = false; + h.call("ui.prefs", json!({"open":"Keyboard Shortcuts"})); + h.step(&json!({"click":{"handle":"shortcut:filter"}})).unwrap(); + h.call("ui.text", json!({"text":"solid.extrude"})); + h.frames(2); + h.step(&json!({"click":{"handle":"shortcut:solid.extrude:1"}})).unwrap(); + assert_eq!(h.app.keymap.capturing.as_deref(), Some("solid.extrude")); + h.call("ui.key", json!({"key":"J","pressed":true,"shift":true})); + h.call("ui.key", json!({"key":"J","pressed":false})); + h.frames(65); + assert_eq!(keys(&h.app, "solid.extrude"), ["E", "Shift+J"]); + assert!(h.widget("E").is_some() && h.widget("Shift+J").is_some(), "both keys are listed"); + let got = h.call("ui.shortcut", json!({"command":"solid.extrude"})); + assert_eq!(got["result"]["keys"], json!(["E", "Shift+J"]), "{got}"); + } + /// #4163: one key for a model command and a sketch tool. Binding it to both is allowed (a /// second model command still clashes); outside a sketch it runs the model command, in a /// sketch the tool. diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index 92769b364..c3b3e51a3 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -1361,7 +1361,7 @@ struct Snapshot { agent: crate::agent_cursor::Settings, autosave: f64, auto_project: bool, - keys: std::collections::BTreeMap, + keys: std::collections::BTreeMap>, } impl Snapshot { @@ -6074,7 +6074,7 @@ mod tests { assert!(app.prefs_window.open && app.prefs_window.section == 0); control(&mut app, &json!({"theme": "light", "ui_scale": 1.25, "zoom_to_cursor": false})).unwrap(); assert!(!app.ui.dark, "light applies at once"); - app.keymap.custom.insert("solid.extrude".into(), "Shift+E".into()); + app.keymap.custom.insert("solid.extrude".into(), vec!["Shift+E".into()]); let v = control(&mut app, &json!({"button": "cancel"})).unwrap(); assert_eq!(v["dialog"], serde_json::Value::Null); assert!(app.ui.dark && app.preferences.theme == "dark" && app.preferences.ui_scale == 1.0 && app.preferences.zoom_to_cursor); @@ -6154,7 +6154,7 @@ mod tests { // update bookkeeping (not a setting, and Cancel keeps it) does not. app.preferences.update.last_check += 1.0; assert_eq!(draw(&mut app, vec![]), Some(0.0), "update bookkeeping is not a change"); - app.keymap.custom.insert("solid.extrude".into(), "Shift+E".into()); + app.keymap.custom.insert("solid.extrude".into(), vec!["Shift+E".into()]); assert_eq!(draw(&mut app, vec![]), Some(1.0), "a rebinding is a change"); let v = control(&mut app, &json!({"button": "apply"})).unwrap(); assert_eq!(v["apply_enabled"], false); diff --git a/docs/book/src/guide/shortcuts.md b/docs/book/src/guide/shortcuts.md index 996e1ab51..752c04542 100644 --- a/docs/book/src/guide/shortcuts.md +++ b/docs/book/src/guide/shortcuts.md @@ -1,6 +1,8 @@ # Keyboard shortcuts -Command shortcuts can be changed in File › Keyboard Shortcuts; these are the defaults. +Command shortcuts can be changed in File › Keyboard Shortcuts; these are the defaults. Click a +key to replace it, or the **+** after it to give the command another key: every key it has +runs it, and menus and tooltips show the first one. Click a binding to record a new shortcut. A shortcut can contain Shift, Ctrl/Cmd and Alt/Option modifiers plus exactly one other key. Hold the modifiers, then press the final diff --git a/docs/control-protocol.md b/docs/control-protocol.md index d64f438c0..08c2fa635 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -317,7 +317,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox. | `ui.documents` | `action?`: `new`, `switch`, `close`, `quit`; `index?`; `force?` (close without asking); `answer?`: `save`, `dont_save`, `cancel` (answers "save changes?"); `open_elsewhere?`: `read_only`, `anyway`, `cancel` (answers "open elsewhere" for the first Open waiting); `changed_on_disk?`: `save_copy`, `overwrite`, `cancel` (answers "changed on disk" before a Save) | the open designs (tabs): names, unsaved flags, the active one, a pending "save changes?" prompt, whether a quit is asking, whether the active design is `read_only`, the Opens waiting for "open elsewhere" (`open_elsewhere`) and a waiting "changed on disk" (`changed_on_disk`) | | `ui.file` | `path`; `insert?`: bool | starts an interactive background Open or Insert; poll `ui.inspect.file_busy` for completion; the window stays responsive | | `ui.home` | `open?`: bool; `sample?`: index | the start page: show or hide it, open a built-in sample (once built); returns `open` and the recent designs | -| `ui.shortcut` | `command`, `key?`, `replace?` | a command's key, or rebinds it (`""` clears; a key another command uses is refused unless `replace`) | +| `ui.shortcut` | `command`, `key?`, `slot?`, `replace?` | a command's keys (`key`: the first, shown in menus; `keys`: all), or rebinds it: `key` becomes its only key, or with `slot` replaces its key there (one past the last adds a key, `""` there removes that key); `""` without `slot` clears them; a key another command uses is refused unless `replace` | | `ui.help` | `item?`: `about`, `shortcuts` (read only), `report` (opens a report draft for review), `crashes` (the Crash Reports window) | the version, commit, build date and diagnostic text | | `ui.prefs` | any of the [`ui.prefs` settings](#uiprefs-settings) below; also `open`, `button` and `stand_up` (listed there) | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `apply_enabled` (whether the dialog's Apply has a change to keep), `dark`, `viewport_dark` (whether the 3D view is dark), `stand_up_offer` (the offered bodies, or null), `stand_up_note` (whether that offer is the note), `theme_followed` and `theme_follow_error` | | `ui.capture` | `action?`: `capture`, `revert`, `cancel` | answers the Capture Position question (asked when a command starts or the design is saved while components were moved without capturing); without `action`, what waits |