Skip to content

Anchor drawings - #262

Merged
panglesd merged 21 commits into
mainfrom
anchor-drawings
Jul 31, 2026
Merged

Anchor drawings#262
panglesd merged 21 commits into
mainfrom
anchor-drawings

Conversation

@panglesd

Copy link
Copy Markdown
Owner

This way, when you add text before, this moves the drawing down, and the drawing stays synchronized with the text.

This changes a bit the workflow for starting drawings: You need first to decide a drawing by including a .draw file, then do the drawing and save it.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7601f1b4-3b77-4eea-84b4-aa1085f237d7

📥 Commits

Reviewing files that changed from the base of the PR and between 44d6d84 and a7e0b04.

📒 Files selected for processing (2)
  • src/engine/runtime/drawing/drawing_controller/preview.mli
  • src/engine/runtime/universe/window.mli

📝 Walkthrough

Walkthrough

The runtime now passes Universe.Window.t through drawing, erasing, editing, preview, and action setup paths. Recordings store element anchors and reactive anchored/unanchored state. JSON serialization includes an anchored marker and supports legacy unmarked recordings. The Translation module transforms stroke and eraser coordinates using window and element scales. Anchored recordings render through reactive live_svg previews. Drawing area excludes anchored recordings. Reactive DOM mounting uses new Elwd helpers to observe and update elements without manual animation-frame sampling. Window scale functions compute ancestor scale recursion. Drawing draggers receive window context, and editing shortcuts require anchored recording state. Drawing setup actions deserialize recordings with element anchors and mount live SVG. CSS styles updated overflow behavior and added hand-drawn positioning.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Anchor drawings' directly describes the main change: drawings are now anchored to .draw files to maintain synchronization with surrounding text.
Description check ✅ Passed The description explains the motivation (drawings stay synchronized when text is added before them) and the workflow change (include .draw file first, then draw).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/engine/runtime/drawing/drawing_controller/tools.ml (1)

165-181: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Include the anchor scale in the eraser proximity calculation.

Line 167 converts c1 to anchor-local coordinates. The stroke paths use the same coordinate space. However, Line 181 passes only the universe scale to close_enough_poly2.

When the anchor scale differs from 1.0, the eraser hit radius is incorrect. Use the same combined scale that Draw_stroke.start stores for anchored strokes.

Proposed fix
             let { Universe.Coordinates.scale; _ } =
               Universe.State.get_coord ()
             in
-            Drawing_state.Path_editing.close_enough_poly2 scale path c1
+            let scale = scale *. translation.scale in
+            Drawing_state.Path_editing.close_enough_poly2 scale path c1
src/engine/runtime/drawing/drawing_controller/setup.ml (1)

128-146: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Disable editor pointer handlers for unanchored recordings.

The UI displays only the upgrade panel for a non-empty unanchored recording. However, connect still mounts the active editing tool over #slipshow-main.

Selection.Preview.event and Move.Preview.event then interpret legacy universe-space paths as anchor-local paths. A pointer action can select or move the wrong strokes before the user upgrades the recording.

Read the recording anchor status reactively. Return Lwd_seq.empty while the status is Unanchored.

Proposed fix
     let handler =
       let$* status = Status.get
-      and$ current_tool = Lwd.get Drawing_state.editing_tool in
-      match status with
-      | Editing -> (
-          let$ replaying_state = Lwd.get current_replaying_state in
-          match replaying_state with
-          | None -> Lwd_seq.empty
-          | Some replaying_state -> (
+      and$ current_tool = Lwd.get Drawing_state.editing_tool
+      and$ replaying_state = Lwd.get current_replaying_state in
+      match (status, replaying_state) with
+      | Editing, Some replaying_state ->
+          let$ anchored =
+            Lwd.get (snd replaying_state.recording.element_anchor)
+          in
+          if anchored = `Unanchored then Lwd_seq.empty
+          else
               match current_tool with
               | Move ->
                   Lwd_seq.element
                   @@ Editing_tools.Move.Preview.event window replaying_state
               | Select ->
                   Lwd_seq.element
                   @@ Editing_tools.Selection.Preview.event window
                        replaying_state
               | Rescale ->
                   Lwd_seq.element
-                  @@ Editing_tools.Scale.Preview.event replaying_state))
-      | _ -> Lwd.pure Lwd_seq.empty
+                  @@ Editing_tools.Scale.Preview.event replaying_state
+      | _ -> Lwd.pure Lwd_seq.empty

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 922808c5-bb72-40bc-9ac1-af3da3a68491

📥 Commits

Reviewing files that changed from the base of the PR and between ba21bfd and 62b74fd.

📒 Files selected for processing (22)
  • src/engine/runtime/controller.ml
  • src/engine/runtime/drawing/drawing_controller/editing_tools.ml
  • src/engine/runtime/drawing/drawing_controller/preview.ml
  • src/engine/runtime/drawing/drawing_controller/preview.mli
  • src/engine/runtime/drawing/drawing_controller/setup.ml
  • src/engine/runtime/drawing/drawing_controller/tools.ml
  • src/engine/runtime/drawing/drawing_controller/ui.ml
  • src/engine/runtime/drawing/drawing_state/dune
  • src/engine/runtime/drawing/drawing_state/json.ml
  • src/engine/runtime/drawing/drawing_state/types.ml
  • src/engine/runtime/main.ml
  • src/engine/runtime/rescale/rescale.css
  • src/engine/runtime/step/action_scheduler.ml
  • src/engine/runtime/step/actions.mli
  • src/engine/runtime/step/actions_.ml
  • src/engine/runtime/system.css
  • src/engine/runtime/universe/window.ml
  • src/engine/runtime/universe/window.mli
  • vendor/github.com/panglesd/brr/src/brr.ml
  • vendor/github.com/panglesd/brr/src/brr.mli
  • vendor/github.com/panglesd/lwd/lib/brr-lwd/elwd.ml
  • vendor/github.com/panglesd/lwd/lib/brr-lwd/elwd.mli

Comment thread src/engine/runtime/drawing/drawing_state/json.ml Outdated
Comment thread vendor/github.com/panglesd/lwd/lib/brr-lwd/elwd.ml
@panglesd
panglesd merged commit ccea527 into main Jul 31, 2026
5 of 8 checks passed
panglesd added a commit that referenced this pull request Jul 31, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant