Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Alt+arrow type spacing: reuse the Type tool's step_key, check Alt before the selection walk

bflatastic50c801b36fb7
diff --git a/crates/tools/src/text.rs b/crates/tools/src/text.rs
index a6b1f3d0c..894f087c3 100644
--- a/crates/tools/src/text.rs
+++ b/crates/tools/src/text.rs
@@ -427,7 +427,7 @@ pub fn overflow_markers(marks: &mut OverflowMarks, cx: &ToolContext) -> Vec<Over
/// `None` when `r` runs past the end of `s` or backwards.
/// The `type.step` an Alt+arrow asks for, by one step: ←/→ kerning at a `caret`, else tracking;
/// ↑/↓ leading (down opens it up); Shift+↑/↓ baseline shift.
-fn step_key(key: ToolKey, shift: bool, caret: bool) -> Option<(&'static str, f64)> {
+pub fn step_key(key: ToolKey, shift: bool, caret: bool) -> Option<(&'static str, f64)> {
let sign = |up: bool| if up { 1.0 } else { -1.0 };
Some(match (key, shift) {
(ToolKey::Left | ToolKey::Right, false) => (if caret { "kerning" } else { "tracking" }, sign(key == ToolKey::Right)),
diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs
index 7493f362e..47450aef5 100644
--- a/crates/ui-egui/src/shortcuts.rs
+++ b/crates/ui-egui/src/shortcuts.rs
@@ -628,31 +628,24 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) {
}
return;
}
- // Alt+arrows on selected type objects use the same spacing increments as the Type tool:
- // ←/→ tracking, ↑/↓ leading, Shift+↑/↓ baseline shift; Cmd/Ctrl multiplies by five. Keep
- // Alt+arrow's normal copy-and-nudge behaviour for every other kind of selection.
- let selected_type = app.session.active().is_some_and(|st| {
- st.selection.guides.is_empty()
- && !st.selection.objects.is_empty()
- && st.selection.objects.iter().all(|id| matches!(st.doc.node(*id).map(|n| &n.kind), Some(vectorcraft_doc::NodeKind::Text(_))))
- });
- if selected_type {
- let m = ctx.input(|i| i.modifiers);
- if m.alt {
- let steps = [
- (Key::ArrowLeft, (!m.shift).then_some(("tracking", -1.0))),
- (Key::ArrowRight, (!m.shift).then_some(("tracking", 1.0))),
- (Key::ArrowUp, Some((if m.shift { "baselineShift" } else { "leading" }, if m.shift { 1.0 } else { -1.0 }))),
- (Key::ArrowDown, Some((if m.shift { "baselineShift" } else { "leading" }, if m.shift { -1.0 } else { 1.0 }))),
- ];
- for (key, step) in steps {
- if ctx.input_mut(|i| i.consume_key(m, key)) {
- if let Some((attribute, by)) = step {
- let by = if m.command { by * 5.0 } else { by };
- let _ = app.run("type.step", json!({"attribute": attribute, "by": by}));
- }
- return;
+ // Alt+arrows on selected type objects step their spacing as the Type tool does (Cmd/Ctrl:
+ // five steps); Alt+arrow copies and nudges every other selection.
+ let m = ctx.input(|i| i.modifiers);
+ if m.alt
+ && app.session.active().is_some_and(|st| {
+ st.selection.guides.is_empty()
+ && !st.selection.objects.is_empty()
+ && st.selection.objects.iter().all(|id| matches!(st.doc.node(*id).map(|n| &n.kind), Some(vectorcraft_doc::NodeKind::Text(_))))
+ })
+ {
+ let keys = [(Key::ArrowLeft, ToolKey::Left), (Key::ArrowRight, ToolKey::Right), (Key::ArrowUp, ToolKey::Up), (Key::ArrowDown, ToolKey::Down)];
+ for (key, tool_key) in keys {
+ if ctx.input_mut(|i| i.consume_key(m, key)) {
+ if let Some((attribute, by)) = vectorcraft_tools::text::step_key(tool_key, m.shift, false) {
+ let by = if m.command { by * 5.0 } else { by };
+ let _ = app.run("type.step", json!({"attribute": attribute, "by": by}));
}
+ return;
}
}
}