Repository navigation
Preserve cross-node text selection on drag (#278 part 1) - #2021
Conversation
The view-container click handler focused the node (swapping the div for a textarea) on every click, including the mouseup that ends a drag — collapsing any text selection before it could be copied. A page is ordinary DOM (only the focused node is a textarea), so native cross-node selection is structurally possible; the interaction just had to stop stealing it. Guard the handler: skip focusing when there is an active (non-collapsed) text selection, so a drag-select survives; a genuine click leaves a collapsed selection and still lands the caret on the clicked character (click-to-edit unchanged). Extract the decision into a tested isActiveTextSelection helper (reused by the copy handler in part 2). Also correct the view content's role="button" to role="textbox"/aria-multiline — it is selectable, editable prose, not a button. Part 1 of #278; the copy handler (assemble markdown source across the spanned nodes) follows in part 2. Co-Authored-By: Claude <[email protected]>
The view content isn't editable until focus swaps in the real textarea, so aria-readonly="true" makes the announced role match reality. Co-Authored-By: Claude <[email protected]>
Pragmatic Code Review + /address-reviewVerdict: APPROVE. Both load-bearing questions land favorably:
Guard placement (after 🟡 addressed: added 🟡 documented (intended behavior): shift/double/triple-click now leave the node unfocused (they produce non-collapsed ranges → treated as selection gestures, not edit gestures). Double-click-to-edit was already effectively unavailable via the collapsed path, so no real loss — noted so Part 2 treats it as known. Re-Review Decision: NO RE-REVIEW NEEDED — the only follow-up commit adds one ARIA attribute. |
Summary
Part 1 of #278. A page of nodes is ordinary DOM — only the focused node is a textarea, every other renders as a plain
<div>— so native cross-node text selection is structurally possible. The bug: the view-container click handler focused the node (swapping in a textarea) on every click, including the mouseup that ends a drag, collapsing the selection before it could be copied.Change
base-node.svelte: guard the view-containeronclick— skip focusing when there's an active (non-collapsed) text selection, so a drag-select survives. A genuine click leaves a collapsed selection and still lands the caret on the clicked character, so click-to-edit is unchanged (existingclick-to-cursortests still pass).$lib/utils/text-selection.ts→isActiveTextSelection(selection)(rangeCount > 0 && !isCollapsed), extracted + tested, and reused by the part-2 copy handler.role="button"→role="textbox"+aria-multiline.Scope
This delivers the issue's core "Section 1 — Preserve the selection on drag" (the literal reported symptom: selection collapses before copy). Part 2 — the
copyhandler that assembles markdown source across the spanned nodes (offset-clipping the first/last, indenting by hierarchy) — is a larger, delicate piece and remains open under #278; its full design is documented on the issue. Kept separate so the selection-preservation fix ships now without rushing the copy-assembly offset mapping.Tests
+4
text-selectionunit tests (null / collapsed / non-empty range / no-range).click-to-cursor(17) still green. Full frontend suite green (193 files / 4463 tests); eslint + svelte-check clean; pre-push gate passed.🤖 Generated with Claude Code