Skip to content

Make text layers easier to drag - #14

Merged
dariomory merged 2 commits into
masterfrom
fix/2-text-layer-drag
Sep 3, 2026
Merged

dariomory merged 2 commits into
masterfrom
fix/2-text-layer-drag

Conversation

@dariomory

Copy link
Copy Markdown
Member

Fixes #2

hitTestLayer rejected any pixel with alpha below 10. A text raster is mostly transparent between the glyphs, so unless you grabbed a letter stroke exactly, the layer slipped out from under the cursor. Text layers are now picked by their bounding box instead.

+    // Text rasters are mostly transparent between glyphs, so a per-pixel alpha
+    // test makes them slip out from under the cursor. Their bounding box is the
+    // grabbable area instead.
+    if (layer.kind === "text" || layer.role === "text") return layer;

Image and paint layers keep the per-pixel test, so clicking through the transparent part of a photo layer still behaves as before.

Trade-off worth knowing: a text layer now captures clicks across its whole box, gaps included. Picking a layer underneath means clicking outside the text bounds. That is the usual bargain for making text grabbable, and it is the behaviour the issue asks for.

Verification

Driven in a browser against the running editor: place a text layer, switch to Move, drag starting from a gap between two letters, then sample the canvas. The origin reads white and the drop point reads dark, so the layer followed the drag. Before the change that same drag did nothing.

pnpm test (21) and pnpm exec tsc --noEmit are clean.

Branched off master and independent of #13, so the two can merge in either order.

hitTestLayer rejected any pixel with alpha below 10, and a text raster
is mostly transparent between glyphs, so the layer slipped out from
under the cursor unless you grabbed a stroke exactly. Text layers are
now picked by their bounding box.

The trade-off is that a text layer captures clicks across its whole box,
including the gaps; picking a layer underneath means clicking outside
the text bounds.

Fixes #2
Adds a little slop around the text bounds so a near miss at the edge
still grabs the layer, and documents that the same box drives both
dragging and click-to-edit - which is the behaviour being asked for:
click anywhere in the text rectangle rather than hunting for a glyph.

Verified by measuring the rendered text box and probing a grid inside
it: all fifteen points grab the layer, gaps between letters included,
and clicking a gap with the Text tool reopens the text for editing.

Fixes #2
@dariomory
dariomory merged commit 300341c into master Sep 3, 2026
1 check passed
@dariomory
dariomory deleted the fix/2-text-layer-drag branch September 3, 2026 09:31
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.

bug: make text layers easier to drag

1 participant