Merge pull request #8668 from storytold/train/carry7822

Support Backquote-arrow pattern-only nudging (#7822)
This commit is contained in:
BFlat
2026-11-19 15:22:29 +07:00
committed by GitHub
7 changed files with 369 additions and 7 deletions
+18 -2
View File
@@ -326,14 +326,15 @@ pub(super) fn nudge(s: &mut Session, p: &Value) -> Result<Value> {
// Guides keep to the page's axes; art and anchors move along the constrain angle's.
let (gx, gy) = (dx, dy);
let (dx, dy) = along_constrain_angle(dx, dy, s.prefs.constrain_angle);
if !s.doc()?.selection.anchors.is_empty() {
let objects = transforms_objects(p);
if objects && !s.doc()?.selection.anchors.is_empty() {
// When the anchors move by 0, the document and its undo history stay as they are.
if dx == 0.0 && dy == 0.0 {
return ok();
}
return crate::cmd::path::move_anchors(s, &json!({ "dx": dx, "dy": dy, "patterns": p.get("patterns"), "interpolate": p.get("interpolate") }));
}
if s.doc()?.selection.is_empty() {
if objects && s.doc()?.selection.is_empty() {
let copy = bool_or(p, "copy", false);
// When guides move by 0 without a copy, the document and its undo history stay as they are.
if gx == 0.0 && gy == 0.0 && !copy {
@@ -342,6 +343,21 @@ pub(super) fn nudge(s: &mut Session, p: &Value) -> Result<Value> {
return crate::cmd::docmenu::guide_move(s, &json!({ "dx": gx, "dy": gy, "copy": copy }));
}
let ids = selected_roots_to_transform(s)?;
if !objects && !bool_or(p, "copy", false) {
// Pattern-only nudges of art without a pattern change nothing, including undo history.
if !bool_or(p, "patterns", s.prefs.transform_pattern_tiles) {
return ok();
}
let st = s.doc()?;
let paths = st.doc.index_paths(ids.iter().copied());
let mut uses_patterns = false;
for node in ids.iter().filter_map(|id| paths.get(id)).filter_map(|path| st.doc.node_at(path)) {
node.walk(&mut |n| uses_patterns |= vectorcraft_doc::pattern::uses_pattern(n, None));
}
if !uses_patterns {
return ok();
}
}
apply_transform_moving_guides(s, "Move", ids, Affine::translate((dx, dy)), p, true, Some(Vec2::new(gx, gy)))
}
+20 -2
View File
@@ -765,6 +765,19 @@ fn press_modifiers(i: &egui::InputState, key: Key) -> Modifiers {
.unwrap_or(i.modifiers)
}
/// Backquote held when `key` last went down, before any later transitions in the frame.
fn backquote_at_press(i: &egui::InputState, key: Key) -> bool {
let mut held = i.key_down(Key::Backtick);
for event in i.events.iter().rev() {
match event {
egui::Event::Key { key: k, pressed: true, .. } if *k == key => return held,
egui::Event::Key { key: Key::Backtick, pressed, repeat: false, .. } => held = !*pressed,
_ => {}
}
}
i.key_down(Key::Backtick)
}
/// Apply arrow-key movement and clear selected art when no text editor owns input, unless a Layers
/// or Appearance row has Delete/Backspace (`rows_keys`).
fn nudge_and_clear(app: &mut VectorcraftApp, ctx: &egui::Context, rows_keys: bool) {
@@ -772,9 +785,14 @@ fn nudge_and_clear(app: &mut VectorcraftApp, ctx: &egui::Context, rows_keys: boo
let arrows = [(Key::ArrowLeft, -1.0, 0.0), (Key::ArrowRight, 1.0, 0.0), (Key::ArrowUp, 0.0, -1.0), (Key::ArrowDown, 0.0, 1.0)];
for (k, dx, dy) in arrows {
// The modifiers held when the key went down, as `claimed_tool_keys` reads them.
let m = ctx.input(|i| press_modifiers(i, k));
let (m, patterns_only) = ctx.input(|i| (press_modifiers(i, k), backquote_at_press(i, k)));
if ctx.input_mut(|i| i.consume_key(m, k)) && app.session.active().is_some_and(|d| d.selection.has_objects_or_guides()) {
let _ = app.run("object.nudge", json!({"dx": dx, "dy": dy, "big": m.shift, "copy": m.alt}));
let mut params = json!({"dx": dx, "dy": dy, "big": m.shift, "copy": m.alt});
if patterns_only {
params["objects"] = json!(false);
params["patterns"] = json!(true);
}
let _ = app.run("object.nudge", params);
}
}
// Delete / Backspace clear the selection.
+321
View File
@@ -0,0 +1,321 @@
//! Backtick arrow nudges use the real App input route and original generated pattern art.
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use egui::{Event, Key, Modifiers, Pos2, RawInput};
use serde_json::json;
use std::sync::Mutex;
use vectorcraft_color::Paint;
use vectorcraft_doc::{Node, NodeId};
use vectorcraft_engine::Session;
use vectorcraft_ui_egui::VectorcraftApp;
// Integration tests link the production global shortcut mirror; each App owns it until its case ends.
static INPUT: Mutex<()> = Mutex::new(());
struct Scene {
app: VectorcraftApp,
ctx: egui::Context,
time: f64,
fill: NodeId,
stroke: NodeId,
solid: NodeId,
other: NodeId,
}
fn key(key: Key, pressed: bool, modifiers: Modifiers) -> Event {
Event::Key { key, physical_key: Some(key), pressed, repeat: false, modifiers }
}
impl Scene {
fn new() -> Self {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
let rect = |app: &mut VectorcraftApp, x, y, width, height| {
NodeId(app.run("shape.rectangle", json!({"x": x, "y": y, "width": width, "height": height})).unwrap()["id"].as_u64().unwrap())
};
let seed = rect(&mut app, 0, 0, 10, 10);
app.run("paint.setFill", json!({"ids": [seed.0], "color": "#ff0000"})).unwrap();
app.run("paint.setStroke", json!({"ids": [seed.0], "none": true})).unwrap();
app.run("select.set", json!({"ids": [seed.0]})).unwrap();
app.run("object.pattern.make", json!({"name": "Dots", "width": 20, "height": 20})).unwrap();
app.run("object.pattern.done", json!({})).unwrap();
let fill = rect(&mut app, 80, 60, 80, 60);
let stroke = rect(&mut app, 200, 60, 80, 60);
let solid = rect(&mut app, 80, 170, 50, 40);
let other = rect(&mut app, 200, 170, 50, 40);
app.run("paint.setFill", json!({"ids": [fill.0, other.0], "swatch": "Dots"})).unwrap();
app.run("paint.setStroke", json!({"ids": [fill.0, stroke.0], "swatch": "Dots"})).unwrap();
app.run("paint.setFill", json!({"ids": [stroke.0], "none": true})).unwrap();
app.run("paint.setFill", json!({"ids": [solid.0], "color": "#0077cc"})).unwrap();
app.run("paint.setStroke", json!({"ids": [solid.0, other.0], "none": true})).unwrap();
app.run("prefs.set", json!({"values": {"keyboardIncrement": 2, "transformPatternTiles": false}})).unwrap();
app.run("select.set", json!({"ids": [fill.0, stroke.0, solid.0]})).unwrap();
app.select_tool("selection");
let ctx = egui::Context::default();
vectorcraft_ui_egui::theme::install_fonts(&ctx);
let mut scene = Self { app, ctx, time: 0.0, fill, stroke, solid, other };
for _ in 0..3 {
scene.frame(vec![]);
}
assert!(!scene.ctx.egui_wants_keyboard_input(), "the actual idle canvas must own arrow input");
scene
}
fn frame(&mut self, events: Vec<Event>) {
self.time += 1.0 / 30.0;
let mut raw = RawInput {
events,
time: Some(self.time),
screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, egui::vec2(1200.0, 800.0))),
..Default::default()
};
self.app.raw_input_hook(&self.ctx, &mut raw);
let mut out = self.ctx.run_ui(raw, |ui| self.app.ui(ui));
out.textures_delta.clear();
}
fn backtick(&mut self, pressed: bool) {
self.frame(vec![Event::ModifiersChanged(Modifiers::NONE), key(Key::Backtick, pressed, Modifiers::NONE)]);
}
fn arrow(&mut self, arrow: Key, modifiers: Modifiers) {
self.frame(vec![
Event::ModifiersChanged(modifiers),
key(arrow, true, modifiers),
key(arrow, false, modifiers),
Event::ModifiersChanged(Modifiers::NONE),
]);
}
fn node(&self, id: NodeId) -> Node {
self.app.session.active().unwrap().doc.node(id).unwrap().clone()
}
fn history(&self) -> usize {
self.app.session.active().unwrap().history.undo.len()
}
}
fn pattern_shift(before: &Paint, after: &Paint, dx: f64, dy: f64) {
let (Paint::Pattern { xf: a, pattern: name_a }, Paint::Pattern { xf: b, pattern: name_b }) = (before, after) else {
panic!("both paints must remain editable patterns");
};
assert_eq!(name_a, name_b);
let (a, b) = (a.as_coeffs(), b.as_coeffs());
assert_eq!(&a[..4], &b[..4], "translation must preserve the pattern basis");
assert!((b[4] - a[4] - dx).abs() < 1e-9 && (b[5] - a[5] - dy).abs() < 1e-9, "pattern placement {a:?} -> {b:?}, expected ({dx}, {dy})");
}
fn geometry_unchanged(before: &Node, after: &Node) {
let mut normalized = after.clone();
normalized.appearance = before.appearance.clone();
assert_eq!(&normalized, before, "pattern nudging must preserve every non-appearance object field");
}
#[test]
fn pattern_nudge_baseline_backtick_arrows_move_paints_not_mixed_art() {
let _input = INPUT.lock().unwrap();
let mut s = Scene::new();
let (fill, stroke, solid, other) = (s.node(s.fill), s.node(s.stroke), s.node(s.solid), s.node(s.other));
let selection = s.app.session.active().unwrap().selection.clone();
let definitions = s.app.session.active().unwrap().doc.patterns.clone();
let history = s.history();
s.backtick(true);
s.arrow(Key::ArrowRight, Modifiers::NONE);
s.backtick(false);
let (a, b) = (s.node(s.fill), s.node(s.stroke));
// Assert paint movement first: unchanged main follows ordinary geometry movement instead.
pattern_shift(&fill.appearance.fill_paint(), &a.appearance.fill_paint(), 2.0, 0.0);
pattern_shift(&fill.appearance.stroke_paint(), &a.appearance.stroke_paint(), 2.0, 0.0);
pattern_shift(&stroke.appearance.stroke_paint(), &b.appearance.stroke_paint(), 2.0, 0.0);
geometry_unchanged(&fill, &a);
geometry_unchanged(&stroke, &b);
assert_eq!(s.node(s.solid), solid);
assert_eq!(s.node(s.other), other, "unselected user of the same definition stays unchanged");
assert_eq!(s.app.session.active().unwrap().doc.patterns, definitions);
assert_eq!(s.app.session.active().unwrap().selection, selection);
assert_eq!(s.history(), history + 1);
s.app.run("edit.undo", json!({})).unwrap();
assert_eq!(s.node(s.fill), fill);
assert_eq!(s.node(s.stroke), stroke);
assert_eq!(s.node(s.solid), solid);
}
#[test]
fn pattern_nudge_baseline_ordinary_arrow_keeps_existing_geometry_behavior() {
let _input = INPUT.lock().unwrap();
let mut s = Scene::new();
let before = s.node(s.fill);
let pattern = before.appearance.fill_paint();
let other = s.node(s.other);
let history = s.history();
s.arrow(Key::ArrowRight, Modifiers::NONE);
let after = s.node(s.fill);
let (a, b) = (before.geometric_bounds().unwrap(), after.geometric_bounds().unwrap());
assert!((b.x0 - a.x0 - 2.0).abs() < 1e-9 && b.y0 == a.y0);
assert_eq!(after.appearance.fill_paint(), pattern, "ordinary nudge respects Transform Pattern Tiles off");
assert_eq!(s.node(s.other), other);
assert_eq!(s.history(), history + 1);
s.app.run("edit.undo", json!({})).unwrap();
assert_eq!(s.node(s.fill), before);
}
#[test]
fn pattern_nudge_partial_anchors_and_idle_shape_tool_preserve_owner_geometry() {
let _input = INPUT.lock().unwrap();
for tool in ["directSelection", "rectangle"] {
let mut s = Scene::new();
s.app.run("select.set", json!({"ids": [s.fill.0]})).unwrap();
s.app.select_tool(tool);
if tool == "directSelection" {
s.app.run("select.anchors", json!({"id": s.fill.0, "anchors": [[0, 0]], "mode": "set"})).unwrap();
}
s.frame(vec![]);
let before = s.node(s.fill);
let selection = s.app.session.active().unwrap().selection.clone();
let history = s.history();
s.backtick(true);
s.arrow(Key::ArrowDown, Modifiers::NONE);
s.backtick(false);
let after = s.node(s.fill);
pattern_shift(&before.appearance.fill_paint(), &after.appearance.fill_paint(), 0.0, 2.0);
geometry_unchanged(&before, &after);
assert_eq!(s.app.session.active().unwrap().selection, selection);
assert_eq!(s.history(), history + 1);
s.app.run("edit.undo", json!({})).unwrap();
assert_eq!(s.node(s.fill), before);
s.arrow(Key::ArrowDown, Modifiers::NONE);
let ordinary = s.node(s.fill);
assert_eq!(ordinary.appearance.fill_paint(), before.appearance.fill_paint());
if tool == "directSelection" {
let a: Vec<_> = before.path_data().unwrap().anchors().map(|(_, _, a)| a.p).collect();
let b: Vec<_> = ordinary.path_data().unwrap().anchors().map(|(_, _, a)| a.p).collect();
assert_eq!(a.len(), b.len());
assert_eq!(b[0], a[0] + vectorcraft_geom::Vec2::new(0.0, 2.0));
assert_eq!(&b[1..], &a[1..], "ordinary Direct Selection nudges only the selected anchor");
} else {
let (a, b) = (before.geometric_bounds().unwrap(), ordinary.geometric_bounds().unwrap());
assert!((b.y0 - a.y0 - 2.0).abs() < 1e-9 && b.x0 == a.x0);
}
}
}
#[test]
fn pattern_nudge_shift_constrain_release_and_undo_use_press_time_increment() {
let _input = INPUT.lock().unwrap();
let mut s = Scene::new();
s.app.run("prefs.set", json!({"values": {"keyboardIncrement": 3, "constrainAngle": 90}})).unwrap();
let before = s.node(s.fill);
let solid = s.node(s.solid);
let history = s.history();
s.backtick(true);
s.arrow(Key::ArrowRight, Modifiers::SHIFT);
let after = s.node(s.fill);
pattern_shift(&before.appearance.fill_paint(), &after.appearance.fill_paint(), 0.0, -30.0);
geometry_unchanged(&before, &after);
assert_eq!(s.node(s.solid), solid);
assert_eq!(s.history(), history + 1);
s.app.run("edit.undo", json!({})).unwrap();
assert_eq!(s.node(s.fill), before);
s.app.run("edit.redo", json!({})).unwrap();
assert_eq!(s.node(s.fill), after);
s.backtick(false);
s.arrow(Key::ArrowRight, Modifiers::NONE);
let ordinary = s.node(s.fill);
let (a, b) = (after.geometric_bounds().unwrap(), ordinary.geometric_bounds().unwrap());
assert!((b.y0 - a.y0 + 3.0).abs() < 1e-9 && b.x0 == a.x0);
assert_eq!(ordinary.appearance.fill_paint(), after.appearance.fill_paint());
s.app.run("edit.undo", json!({})).unwrap();
assert_eq!(s.node(s.fill), after);
}
#[test]
fn pattern_nudge_same_frame_event_order_uses_backtick_at_arrow_press() {
let _input = INPUT.lock().unwrap();
let mut s = Scene::new();
let before = s.node(s.fill);
s.backtick(true);
s.frame(vec![
key(Key::ArrowRight, true, Modifiers::NONE),
key(Key::Backtick, false, Modifiers::NONE),
key(Key::ArrowRight, false, Modifiers::NONE),
]);
let after = s.node(s.fill);
pattern_shift(&before.appearance.fill_paint(), &after.appearance.fill_paint(), 2.0, 0.0);
geometry_unchanged(&before, &after);
s.arrow(Key::ArrowRight, Modifiers::NONE);
let ordinary = s.node(s.fill);
assert!((ordinary.geometric_bounds().unwrap().x0 - after.geometric_bounds().unwrap().x0 - 2.0).abs() < 1e-9);
assert_eq!(ordinary.appearance.fill_paint(), after.appearance.fill_paint());
let mut s = Scene::new();
let before = s.node(s.fill);
s.frame(vec![
key(Key::ArrowRight, true, Modifiers::NONE),
key(Key::Backtick, true, Modifiers::NONE),
key(Key::ArrowRight, false, Modifiers::NONE),
]);
s.backtick(false);
let after = s.node(s.fill);
assert!((after.geometric_bounds().unwrap().x0 - before.geometric_bounds().unwrap().x0 - 2.0).abs() < 1e-9);
assert_eq!(after.appearance.fill_paint(), before.appearance.fill_paint(), "a later Backtick press cannot reinterpret an earlier arrow press");
}
#[test]
fn pattern_nudge_solid_and_guide_only_are_noops_but_ordinary_arrows_work() {
let _input = INPUT.lock().unwrap();
let mut s = Scene::new();
s.app.run("select.set", json!({"ids": [s.solid.0]})).unwrap();
let before = s.app.session.active().unwrap().doc.clone();
let selection = s.app.session.active().unwrap().selection.clone();
let history = s.history();
s.backtick(true);
s.arrow(Key::ArrowRight, Modifiers::NONE);
s.backtick(false);
assert_eq!(s.app.session.active().unwrap().doc, before);
assert_eq!(s.app.session.active().unwrap().selection, selection);
assert_eq!(s.history(), history);
let solid = s.node(s.solid);
s.arrow(Key::ArrowRight, Modifiers::NONE);
assert!((s.node(s.solid).geometric_bounds().unwrap().x0 - solid.geometric_bounds().unwrap().x0 - 2.0).abs() < 1e-9);
s.app.run("view.guides.lock", json!({"locked": false})).unwrap();
let index = s.app.run("guide.add", json!({"vertical": true, "pos": 40})).unwrap()["index"].as_u64().unwrap();
s.app.run("guide.select", json!({"indexes": [index]})).unwrap();
let before = s.app.session.active().unwrap().doc.clone();
let selection = s.app.session.active().unwrap().selection.clone();
let history = s.history();
let guides = s.app.run("guide.list", json!({})).unwrap();
s.backtick(true);
s.arrow(Key::ArrowRight, Modifiers::NONE);
s.backtick(false);
assert_eq!(s.app.session.active().unwrap().doc, before);
assert_eq!(s.app.session.active().unwrap().selection, selection);
assert_eq!(s.history(), history);
s.arrow(Key::ArrowRight, Modifiers::NONE);
let moved = s.app.run("guide.list", json!({})).unwrap();
assert_eq!(moved[index as usize]["pos"].as_f64().unwrap(), guides[index as usize]["pos"].as_f64().unwrap() + 2.0);
assert_eq!(s.history(), history + 1);
s.app.run("edit.undo", json!({})).unwrap();
assert_eq!(s.app.session.active().unwrap().doc, before);
}
#[test]
fn pattern_nudge_user_shortcut_precedes_global_arrow_dispatch() {
let _input = INPUT.lock().unwrap();
let mut s = Scene::new();
s.app.run("shortcuts.set", json!({"id": "select.none", "shortcut": "Right", "force": true})).unwrap();
let before = s.app.session.active().unwrap().doc.clone();
let history = s.history();
s.backtick(true);
s.arrow(Key::ArrowRight, Modifiers::NONE);
s.backtick(false);
let after = s.app.session.active().unwrap().doc.clone();
let empty = s.app.session.active().unwrap().selection.is_empty();
let after_history = s.history();
// Reset the global command map before assertions, including a failing ownership assertion.
s.app.run("shortcuts.set", json!({"id": "select.none", "shortcut": null})).unwrap();
assert!(empty, "the user's bound Select None command owns this arrow press");
assert_eq!(after, before);
assert_eq!(after_history, history);
}
+1
View File
@@ -954,6 +954,7 @@ trap, and the defaults (0.25 pt, 100%, 40%) are VectorCraft's own, the pages giv
| 2026-11-16 | minor | Recolor Artwork follow-up (#8031, remaining #4028): native Lab input, picker swatch libraries and Assign-row menus; UI interaction regression coverage; scores and estimates unchanged. |
| 2026-11-16 | minor | Eraser review (#6582): hidden Rasterize rows and hidden strokes with gradients along or across their paths do not block preserving visible fitted gradients. Visible unsupported paint branches retain existing fitting. Scores and estimates unchanged. |
| 2026-11-16 | minor | Eraser review (#6582): ordinary Group/Layer own paints and reproducible evaluated gradient placements are preserved as members are cut. Replacement-art effects, plug-ins/Rasterize, along/across-stroke gradients and placements that cannot reproduce the original appearance keep existing fitting. Scores and estimates unchanged. |
| 2026-11-14 | minor | #7717: Backquote/~ arrow nudges for selected pattern fills and strokes retain normal increment/Shift and idle-tool behavior. Scores and estimates unchanged. |
| 2026-11-14 | minor | Type: Middle Eastern & South Asian and Standard composers per paragraph (#4935): Paragraph panel menu, paragraph styles, `text.setFormat {composer}` and the native file; the Standard composers set Indic, Arabic and Hebrew type glyph by glyph. `.ai`, EPS and PDF files carry no composer. Scores and estimates unchanged. |
| 2026-11-14 | minor | Tech Circuit adds three original procedural brushes (Circuit Trace, Bus Lines, Terminal Nodes); ten built-in brush libraries. G5 remaining estimate 3–13 h (estimated); parity scores and headline totals unchanged. |
| 2026-11-14 | minor | Direct Selection: Space during an ordinary path's direction-handle drag moves its anchor and both handles; releasing Space resumes handle adjustment, and a Cmd/Ctrl loan preserves Pen continuation (#7237, request 3 only). Handle-hover labels remain open; scores and estimates unchanged. |
+2 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3 -1
View File
File diff suppressed because one or more lines are too long