mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-30 04:37:29 -06:00
Document: Cmd+Alt+Shift+U switches to the next unit of measurement
The reference app switches the units of measurement with Ctrl+Alt+Shift+U on Windows and Option+Shift+Command+U on macOS. VectorCraft could set the document's units with document.setUnits or a right-click on a ruler, but no command stepped through them and no key did it. document.switchUnits (Switch Units, default Cmd+Alt+Shift+U) sets the document's units to the next one in the order a right-click on a ruler lists them: Points, Picas, Inches, Millimeters, Centimeters, Pixels, Feet & Inches, Meters, Yards, Feet, and from Feet back to Points. Each press is one undo step, and the reply names the new units. Keyboard Shortcuts lists it under Document. The precise cursors shortcut-editor test used Cmd+Alt+Shift+U as a free key; it now uses Cmd+Alt+Shift+Q. Docs: docs/mcp.md, docs/ui-parity.md, docs/target-app-parity.md.
This commit is contained in:
@@ -42,6 +42,15 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
has_doc,
|
||||
set_units
|
||||
),
|
||||
cmd!(
|
||||
"document.switchUnits",
|
||||
"Switch Units",
|
||||
[],
|
||||
Some("Cmd+Alt+Shift+U"),
|
||||
"{} the document's units become the next of Points, Picas, Inches, Millimeters, Centimeters, Pixels, Feet & Inches, Meters, Yards and Feet (the order a right-click on a ruler lists them), Feet going back to Points; one undo step → {units}",
|
||||
has_doc,
|
||||
switch_units
|
||||
),
|
||||
cmd!(
|
||||
query "document.rulerOrigin",
|
||||
"Ruler Origin",
|
||||
@@ -332,6 +341,14 @@ fn set_units(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
ok()
|
||||
}
|
||||
|
||||
/// Switch Units: the unit after the document's in [`Unit::ALL`], wrapping around.
|
||||
fn switch_units(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
let now = s.doc()?.doc.units;
|
||||
let next = Unit::ALL.iter().position(|u| *u == now).and_then(|i| Unit::ALL.get((i + 1) % Unit::ALL.len())).copied().unwrap_or_default();
|
||||
s.set_document_units(next)?;
|
||||
Ok(json!({ "units": next.label() }))
|
||||
}
|
||||
|
||||
/// The `artboard` param of the ruler origin commands: an artboard index, 0 when not given.
|
||||
fn artboard_param(s: &Session, p: &Value, c: &str) -> Result<usize> {
|
||||
let index = match p.get("artboard") {
|
||||
|
||||
@@ -130,6 +130,28 @@ fn set_units_is_an_alias() {
|
||||
assert!(s.execute("document.setUnits", &json!({"units": "parsecs"})).is_err());
|
||||
}
|
||||
|
||||
/// Switch Units (Cmd+Alt+Shift+U) steps the document's units through every unit in the order a
|
||||
/// right-click on a ruler lists them, Feet going back to Points, one undo step each.
|
||||
#[test]
|
||||
fn switch_units_steps_through_the_units_and_wraps() {
|
||||
let spec = command_specs().iter().find(|c| c.id == "document.switchUnits").expect("registered");
|
||||
assert_eq!((spec.label, spec.shortcut), ("Switch Units", Some("Cmd+Alt+Shift+U")));
|
||||
assert!(Session::new().execute("document.switchUnits", &json!({})).is_err(), "no document");
|
||||
let mut s = session();
|
||||
assert_eq!(s.doc().unwrap().doc.units, Unit::Points);
|
||||
let order = ["Picas", "Inches", "Millimeters", "Centimeters", "Pixels", "Feet & Inches", "Meters", "Yards", "Feet", "Points"];
|
||||
for (i, label) in order.iter().enumerate() {
|
||||
assert_eq!(s.execute("document.switchUnits", &json!({})).unwrap(), json!({"units": label}));
|
||||
assert_eq!(s.doc().unwrap().doc.units.label(), *label);
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), i + 1, "one undo step each");
|
||||
}
|
||||
s.execute("document.setUnits", &json!({"units": "Feet"})).unwrap();
|
||||
s.execute("document.switchUnits", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.units, Unit::Points, "after Feet comes Points");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.units, Unit::Feet);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn language_picks_its_quotes_unless_quotes_are_given() {
|
||||
let mut s = session();
|
||||
|
||||
Reference in New Issue
Block a user