← Back to Pull requests

M8: a drag that only moves the selection shifts what was worked out at its start #1640

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 30, 2026 07:56 UTC
Author

What

This is the third part of #1571. During a drag, the first frame after each move holds a new document. With a large selection, that frame rebuilt everything #1611 keeps between frames:

  • the selection's outlines on screen, its box and size;

  • the slots shown;

  • the selection spacing (about 1 ms on those frames);

  • the Design panel's values, including the Export section's.
  • Most drags only move the selected layers: every one moves by the same offset from where the drag started. None of those values change in such a move except where things are on the screen. So now:

  • Engine: it notes when a drag has done only that (Interaction::moved_by, the offset in page units). It doesn't note it for:

  • - a layer in an auto layout flow (the layout places it, or closes the gap it leaves);
    - a copy dragged out with Alt;
    - anything other than a move.
  • Canvas: while such a drag goes on, it works the outlines, box and slots out once from the document the drag started from, and shifts the outlines and box by the move.

  • Selection spacing: gaps between layers moved together don't change, so they come from the start document.

  • Design panel: it shows the start document's values. The Position fields are the exception: they read the current document, so X and Y follow the move.

  • Export section: its values (shared settings, the layers an export writes, the button's label) are now kept between frames like the other sections'.
  • Nothing looks different. A test compares what the canvas draws during a move with what a fresh canvas draws for the moved document.

    How

  • crates/engine/src/doc_state.rs: Interaction::moved_by: Option<(f64, f64)>. It lives and goes with the gesture.

  • crates/engine/src/canvas/tools/drag.rs: the free-move branch of a Move drag sets it after each preview when:

  • - it isn't a copy;
    - the layers didn't take a slot in an auto layout frame;
    - only_shifted holds: no moved layer is in an auto layout flow or inside another moved layer.

    Otherwise it is None.

  • crates/ui-egui/src/selection_cache.rs: moved(ds) gives the start document and the offset while the selection is the gesture's.

  • Users of moved:

  • - canvas/overlays.rs: shown_geometry uses the start document's cached geometry and translates the outline shapes and the box.
    - canvas/outline.rs: the slots are kept against the start document.
    - canvas/selection_spacing.rs: the spacing layout is kept against it too.
    - panels/right.rs: design passes the start document to every section but Position's values. Position reads the instance facts from the start document too, so that cache isn't made again every frame.
  • panels/export_panel.rs: the section's values are computed once per document and selection (Exports), through selection_cache::cached.
  • The canvas texture is still uploaded whole after each render. A partial upload would need:

  • the retained renderer to report the rectangles it patched (Work::Partial carries only a pixel count);

  • the canvas to know the texture still holds the exact image the patch was made on, not a coarse preview that came between.
  • That is a bigger change than this one, so it is left as a next step.

    Measurements

    Same synthetic file and script as #1601 and #1611:

  • about 1,900 layers; 300 control-driven moves at 60 a second;

  • release build; the machine was not throttled this time (3 frames per move).
  • I measured the same build with the reuse switched off and on, via a temporary switch now removed, two rounds each. The "UI ms" column is the UI pass per frame, mean.

    | Case | Before: CPU / UI ms | After: CPU / UI ms |
    |---|---|---|
    | Hover over the canvas (control) | 33% / 0.62 | 30% / 0.58 |
    | Drag one auto layout frame | 47% / 0.78 | 42% / 0.68 |
    | Drag everything selected (648 layers) | 135% / 2.10 (max 7.8) | 117% / 1.44 (max 4.6) |

    In "drag everything", per frame, from temporary probes:

  • the Design panel went from 0.90 to 0.51 ms;

  • the canvas overlays went from 0.50 to 0.30 ms.
  • A first try got the panel slower: the Position section and the layout section asked the instance cache about different documents, so it was made again every frame. The probes caught it before these runs.

    Tests

  • crates/engine/src/moved_by_tests.rs:

  • - a plain move of two layers reports its offset, and each layer moved by exactly that much;
    - the note is gone after the release;
    - a layer selected with its frame moves once, with it;
    - a layer in an auto layout flow and an Alt copy report nothing.
  • crates/ui-egui/src/canvas/selection_cache_tests.rs:

  • - during a move, the geometry made from the drag's start document is kept across moves;
    - every shape the overlays draw sits where a fresh canvas showing the moved document draws it, to 0.01 pt;
    - the start document stands in only while the selection is the gesture's own.
  • The engine and UI suites pass. cargo xtask ci passes.
  • Parity notes

    None: no behaviour or visual change.

    Not verified / what remains for #1571

  • Engine preview per move (now the largest cost): every move copies the document from the drag's start and normalises it (about 2 ms with 648 layers moved, measured in #1601). Moving only the selected layers' transforms in place would be the next step.

  • Canvas texture: still uploaded whole after each render; see How.

  • Other drags: resizes, rotations, and moves within auto layout still rebuild everything on the frame of each move.

  • Not run on macOS or Linux.
  • Dragging 648 layers is better, but not clearly smooth end to end yet.

    Part of #1571

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Performance
    Dragging eligible large selections is more responsive. Selection outlines, the selection box, slot indicators, spacing, and Design panel values stay updated during movement without being fully recalculated on every drag update.
    * This optimization applies to straightforward moves; auto-layout-managed moves and Alt-drag copies continue to use the existing behavior.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: coderabbitai[bot] Review duration: 9m
    All Vouch review confidence checks passed
    Residual risk 0.35 = Change Risk (0.52) × (1 − Review Confidence (0.32)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 59% · Reviewer familiarity: 35%
    32%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1640"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 32.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 32.1% · Lower = rushed or shallow review
    32.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 35.3% · Moderate risk
    35.3%