Skip to content

stroke: a hand-drawn stroke keeps its first-touch order - #68

Draft
foxnne wants to merge 2 commits into
mainfrom
feat/stroke-order
Draft

foxnne wants to merge 2 commits into
mainfrom
feat/stroke-order

Conversation

@foxnne

@foxnne foxnne commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Made by: claude

Part of fizzyedit/plans#65 (step A)

A pencil stroke was stored as a hash map, so its step was a sorted pixel set and a tape lost the order it was drawn in. Now:

  • Buffers.Stroke.order records each pixel index when first touched (append, appendAssumeCapacity); cleared in toChange and clearAndFree.
  • strokeUndoCommit sets history.showing_order/showing_marks (one pen mark)/showing_ms around the append, as commands.zig does, so motionOf emits Step.motion. A stroke flushed from the deferred snapshot is found by row scan, so it gets no motion.
  • motionOf's index-to-position mapping moved to steps.positionsOf so it is testable.

Not in this PR: overdraw and per-sample timing (step B, a format change). Step format 2 is unchanged; steps without motion decode and apply as before.

Ran: zig build test (new tests: out-of-order hand stroke exports in drawn order, repeats rejected by decodeMotion, step without motion still applies) and zig build, both pass locally. Not exercised: drawing by hand in the running app.

Fix (crash on first hand stroke): strokeUndoCommit zipped Stroke.order with a drawn buffer that was empty whenever the stroke was not "live" (the deferred-snapshot flush, or an allocation failure) while order was not, so Debug panicked on non-equal lengths. order is now converted by steps.orderOf (its own length, no zip), and only for a live stroke. Tests added: empty and one-pixel orders, and an order longer than the pixels returns no motion.

Not tested: strokeUndoCommit itself (it needs a File and dvui, outside zig build test) and I have not drawn in the running app, which is why the first version crashed. Please try one stroke before ready. Ran after the fix: zig build test, zig build.

🤖 Generated with Claude Code

t and others added 2 commits October 22, 2026 12:38
…ched

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@foxnne

foxnne commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T22:38:00.041781Z 1c8e38a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c8e38a610

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/internal/File.zig
Comment on lines +2341 to +2342
const live = !flushed and file.buffers.stroke.order.items.len == file.buffers.stroke.pixels.count();
const drawn: []u32 = if (live) (steps.orderOf(gpa, file.buffers.stroke.order.items) catch &.{}) else &.{};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Route live stroke releases through the motion-aware commit

When a stroke uses the live buffer—for example, after its deferred snapshot exceeds the size cap—normal pointer release still calls drawPoint/drawLine with to_change = true, which reaches File.commitStroke. Its non-deferred branch calls toChange and history.append directly, bypassing this new metadata setup and clearing the recorded order. Consequently, these live hand-drawn strokes still export without motion; the new path is only reached when such a stroke is cancelled by cancelActiveDrawing. Route the non-deferred release path through the motion-aware commit as well.

Useful? React with 👍 / 👎.

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