mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-30 12:47:13 -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") {
|
||||
|
||||
Reference in New Issue
Block a user