mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-02 22:19:00 +00:00
Nudge: Ctrl/Cmd+arrow moves Direct Selection's frame anchors and mesh points by a tenth too
Direct Selection nudges selected area-type frame anchors and gradient-mesh points itself (ToolContext::arrow_nudge), before object.nudge sees the key, and that step ignored Ctrl/Cmd. nudge_step moves into vectorcraft-tools, the engine re-exports it, and arrow_nudge uses it, so every arrow nudge takes the same step: x10 with Shift, /10 with Ctrl/Cmd, one increment with both.
This commit is contained in:
@@ -301,17 +301,7 @@ pub(crate) fn along_constrain_angle(dx: f64, dy: f64, deg: f64) -> (f64, f64) {
|
||||
(v.x, v.y)
|
||||
}
|
||||
|
||||
/// The arrow keys' step: the keyboard increment, ×10 with Shift (`big`) and ÷10 with Ctrl/Cmd
|
||||
/// (`fine`), so Shift+Ctrl+arrow moves by one increment. Divided, not multiplied by 0.1, so a tenth
|
||||
/// of a 1 pt increment is the nearest `f64` to 0.1.
|
||||
pub(crate) fn nudge_step(increment: f64, big: bool, fine: bool) -> f64 {
|
||||
match (big, fine) {
|
||||
(true, true) => increment,
|
||||
(true, false) => increment * 10.0,
|
||||
(false, true) => increment / 10.0,
|
||||
(false, false) => increment,
|
||||
}
|
||||
}
|
||||
pub(crate) use vectorcraft_tools::nudge_step;
|
||||
|
||||
/// `object.nudge`, the arrow keys: the selected anchors, else the selected objects (and the guides
|
||||
/// that move with them), else the selected ruler guides move by [`nudge_step`] in the arrow's
|
||||
|
||||
@@ -319,11 +319,12 @@ impl ToolContext<'_> {
|
||||
pub fn star_radii_label(&self, outer: f64, inner: f64) -> String {
|
||||
format!("R1: {}\nR2: {}", self.len(outer), self.len(inner))
|
||||
}
|
||||
/// The move an arrow key nudges by: General › Keyboard Increment (ten times with Shift),
|
||||
/// along General › Constrain Angle's axes; `None` for other keys.
|
||||
/// The move an arrow key nudges by: General › Keyboard Increment, ten times with Shift and a
|
||||
/// tenth with Ctrl/Cmd ([`nudge_step`]), along General › Constrain Angle's axes; `None` for
|
||||
/// other keys.
|
||||
pub fn arrow_nudge(&self, key: crate::ToolKey, mods: crate::Mods) -> Option<Vec2> {
|
||||
use crate::ToolKey;
|
||||
let step = self.keyboard_increment * if mods.shift { 10.0 } else { 1.0 };
|
||||
let step = nudge_step(self.keyboard_increment, mods.shift, mods.cmd);
|
||||
let d = match key {
|
||||
ToolKey::Left => Point::new(-step, 0.0),
|
||||
ToolKey::Right => Point::new(step, 0.0),
|
||||
@@ -380,3 +381,15 @@ impl ToolContext<'_> {
|
||||
vectorcraft_doc::hit::HitOptions { clip_outlines: true, ..self.hit_options() }
|
||||
}
|
||||
}
|
||||
|
||||
/// The arrow keys' step: the keyboard increment, ×10 with Shift (`big`) and ÷10 with Ctrl/Cmd
|
||||
/// (`fine`), so Shift+Ctrl+arrow moves by one increment. Divided, not multiplied by 0.1, so a tenth
|
||||
/// of a 1 pt increment is the nearest `f64` to 0.1.
|
||||
pub fn nudge_step(increment: f64, big: bool, fine: bool) -> f64 {
|
||||
match (big, fine) {
|
||||
(true, true) => increment,
|
||||
(true, false) => increment * 10.0,
|
||||
(false, true) => increment / 10.0,
|
||||
(false, false) => increment,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,7 +415,8 @@ fn a_marquee_selects_frame_anchors_of_area_type() {
|
||||
assert_eq!(a[0], Action::Begin("Reshape Type Area".into()));
|
||||
assert_eq!(a[1], Action::Preview("text.reshapeArea".into(), json!({"id": text.0, "anchors": [[0, 1], [0, 2]], "dx": 20.0, "dy": 20.0})));
|
||||
assert_eq!(t.pointer(&cx2, &ev(PointerKind::Up, 440.0, 360.0)), vec![Action::Commit, Action::Notify(FRAME_PICKED.into())]);
|
||||
// The arrow keys nudge them by the keyboard increment, ten times that with Shift.
|
||||
// The arrow keys nudge them by the keyboard increment, ten times that with Shift, a tenth with
|
||||
// Ctrl/Cmd and one increment with both (#5258).
|
||||
let nudged = |anchors: Value, dx: f64, dy: f64| {
|
||||
vec![
|
||||
Action::Exec("text.reshapeArea".into(), json!({"id": text.0, "anchors": anchors, "dx": dx, "dy": dy})),
|
||||
@@ -425,6 +426,8 @@ fn a_marquee_selects_frame_anchors_of_area_type() {
|
||||
assert!(t.claims_key(&cx2, ToolKey::Right) && !t.claims_key(&cx2, ToolKey::Enter));
|
||||
assert_eq!(t.key(&cx2, ToolKey::Right, Mods::default()), nudged(json!([[0, 1], [0, 2]]), 1.0, 0.0));
|
||||
assert_eq!(t.key(&cx2, ToolKey::Up, Mods { shift: true, ..Mods::default() }), nudged(json!([[0, 1], [0, 2]]), 0.0, -10.0));
|
||||
assert_eq!(t.key(&cx2, ToolKey::Left, Mods { cmd: true, ..Mods::default() }), nudged(json!([[0, 1], [0, 2]]), -0.1, 0.0));
|
||||
assert_eq!(t.key(&cx2, ToolKey::Down, Mods { shift: true, cmd: true, ..Mods::default() }), nudged(json!([[0, 1], [0, 2]]), 0.0, 1.0));
|
||||
// Any other change of the document or the selection (Deselect, then the same type selected
|
||||
// again) leaves the type selected whole: the arrow keys are no longer the tool's.
|
||||
let mut later = cx(&d, &s, &p);
|
||||
|
||||
@@ -57,7 +57,7 @@ mod context;
|
||||
mod cursor;
|
||||
mod input;
|
||||
|
||||
pub use context::{GlyphSnap, MarqueeMode, PaintDefaults, ScreenFrame, ToolContext};
|
||||
pub use context::{GlyphSnap, MarqueeMode, PaintDefaults, ScreenFrame, ToolContext, nudge_step};
|
||||
pub use cursor::Cursor;
|
||||
pub use input::{Action, Mods, PenPose, PointerEvent, PointerKind, ToolKey};
|
||||
|
||||
|
||||
@@ -2095,7 +2095,6 @@ fn selected_vertical_area_and_path_type_use_vertical_spacing_chords() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #3786: Alt+arrows step a selected text object's spacing instead of copying and nudging it.
|
||||
/// #5258: Ctrl/Cmd+arrow nudges the selection by a tenth of the keyboard increment, and
|
||||
/// Shift+Ctrl/Cmd+arrow by one increment, one undo step each.
|
||||
#[test]
|
||||
@@ -2118,6 +2117,7 @@ fn command_arrows_nudge_by_a_tenth_of_the_keyboard_increment() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #3786: Alt+arrows step a selected text object's spacing instead of copying and nudging it.
|
||||
#[test]
|
||||
fn alt_arrows_step_selected_type_object() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
|
||||
Reference in New Issue
Block a user