Skip to content

fix(web): keep the dragged region when commenting on an SVG - #648

Merged
danyaberezun merged 2 commits into
mainfrom
fix-image-region-comment-coords
Oct 6, 2026
Merged

danyaberezun merged 2 commits into
mainfrom
fix-image-region-comment-coords

Conversation

@danyaberezun

@danyaberezun danyaberezun commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Dragging a region on an image and commenting on it sometimes reached the chat with the region's coordinates and sometimes as "the whole picture". It looked intermittent, but it was keyed on the file type: raster images (thinkrail/image) always sent a normalized region selector, while SVGs (thinkrail/svg, the "Vector" renderer that outranks the raster one for .svg) deliberately replaced the dragged rectangle with a whole-file draft (svgFileDraft → selectors: [], label file). The drag rectangle and the "+" icon still appeared, so nothing suggested the geometry was about to be dropped; the comment left as kind="file" / anchor-kind="file" with no locator, landed in "Comments not placed in Vector", and the agent was pointed at the whole file.

Local review stores and sent packages confirmed it: the one PNG comment carried region [0.523, 0.688, 0.138, 0.033]; both .svg comments carried no selectors.

Approach

Make SVG region authoring positional, the same way raster images already are. The SVG renderer already declares anchors: { view: ["region"], diff: ["region"] } and already places region threads through the same containedMediaRect math, and the host already narrows and keeps a region selector on a text side (no lineRange, so no derived quote; outdated on edit, like a PNG). So the fix is to stop overriding RegionReviewSurface's default regionDraft for SVG — no server storage change, no new abstraction. The original spec rationale (SVG source spans aren't mapped) still holds: the anchor is geometry, not a line range; the send package now tells the agent to map the 0..1 fractions onto the SVG's viewBox.

Alternatives considered: keeping whole-file and removing the selection rectangle (honest, but gives up the coordinates the user wanted).

Changes

  • apps/web/src/panels/resources/svg/View.tsx, Diff.tsx: use the default regionDraft; diff label mirrors raster ("image region"); svg-region-surface test id (mirrors image-region-surface).
  • apps/web/src/panels/resources/svg/svgDocument.ts: svgFileDraft removed (and its unit assertion).
  • packages/server/src/reviews/packageRender.ts: the <instructions> locator bullet names a position "by geometry or document node rather than by lines" and adds the SVG → viewBox mapping hint; pinned in packageRender.test.ts and mirrored in the web reviewPackage.test.ts fixture that embeds the full package text.
  • Specs: apps/web/src/panels/SPEC.md (thinkrail/svg authors positional regions; the whole-file draft is recorded as a retired decision and why), packages/server/src/reviews/SPEC.md (locator wording).
  • E2E: committed RENDERERS.svg fixture and a review.spec.ts test that drags 25%→75% on the SVG surface and asserts the persisted selector geometry.

Screenshots

Same scenario and viewport (1280×1000): open brand-mark.svg, drag over the button, comment, save.

Before (main) After (this branch)
Composer after the drag composer before composer after
Saved draft saved before saved after

Before: the rectangle is drawn but the draft is labelled file, and the saved comment lands in "Comments not placed in Vector". After: the draft is labelled region, and the saved comment is a numbered marker on the picture with the Review panel listing it as region.

Related issues

None.

Checklist

  • Fast gates pass: bun run lint, bun run typecheck, bun run test
  • E2E suite passes for app-affecting changes (bun run e2e, or bun run e2e:full when touching agent behavior)
  • Before/after screenshots are included for frontend changes, or marked not applicable
  • Relevant SPEC.md / top-level specs updated to reflect any boundary, contract, or behavior change
  • I have read the Contributing guide and agree to the Code of Conduct

Testing

Run on the final tree (a6ffe506, rebased onto 1f8c01f5) after resolving the panels/SPEC.md conflict with #638 and applying the review fix:

  • bun run lint → clean (1349 files)
  • bun run typecheck → 20/21 turbo tasks green (turbo run typecheck --filter='!@thinkrail/desktop'). The @thinkrail/desktop task could not complete locally because electrobun prepare hangs while a local electrobun dev is running (environmental, unrelated); CI's Lint & Typecheck job covers it.
  • bun run test → 21/21 turbo tasks green
  • bun run check:deps / check:boundaries / check:seams / check:spec-surface, plus the typography/colors/spacing/provider-glyph usage gates → OK
  • bun run e2e → all 8 shards passed (479 tests, 169s), including the new SVG region test

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved — ready to merge.

Comment thread packages/server/src/reviews/packageRender.ts Outdated
@danyaberezun
danyaberezun enabled auto-merge October 6, 2026 08:30
…nsform

The locator instruction implied a linear map from region fractions onto the
viewBox. The fractions are of the SVG's root viewport, so a viewBox whose
aspect differs from width/height is letterboxed by the default
preserveAspectRatio and the viewBox origin shifts the result; name the
transform to invert instead.
@danyaberezun
danyaberezun force-pushed the fix-image-region-comment-coords branch from c4a52d1 to a6ffe50 Compare October 6, 2026 08:41

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved — ready to merge.

@danyaberezun
danyaberezun added this pull request to the merge queue Oct 6, 2026
Merged via the queue into main with commit 68fe681 Oct 6, 2026
17 checks passed
@danyaberezun
danyaberezun deleted the fix-image-region-comment-coords branch October 6, 2026 09:01
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.

2 participants