Skip to content

fix(muya): stop drag-selection from expanding to whole blocks - #4477

Merged
Jocs merged 2 commits into
developfrom
fix/text-selection-no-block-expand
Jun 13, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/text-selection-no-block-expand

Conversation

@Jocs

@Jocs Jocs commented Jun 13, 2026

Copy link
Copy Markdown
Member

What

Text drag-selection no longer auto-expands to whole structural blocks. Previously, when a selection's anchor or focus landed inside a code block, list item, or table cell, TextSelection.handleMousemoveOrClick grew the selection to cover the entire enclosing block — snapping the anchor offset to 0 and the focus offset to text.length. The result was that landing in a list item selected the whole item, landing in a code block selected the whole code block, and landing in a table cell selected the whole table.

Expectation (and new behavior): the selection ends exactly where the pointer lands — interior offsets stay interior.

How

  • Removed the four expansion branches in TextSelection.handleMousemoveOrClick (and the now-unused direction destructure + Parent / ListItem / TaskListItem imports).
  • The isSelectionInSameBlock early return is unchanged.
  • This is isolated to the TextSelection text-drag path. It does not affect:
    • TableRectSelection — rectangular cross-cell drag selection (collapses the native range before this code runs, so the same-block early return fires).
    • selectAll() — the Cmd+A escalation lives in a separate facade method.

Testing

  • New Chromium e2e regression test (editing/text-selection-no-expand.spec.ts): drags between two list items at interior char offsets and asserts the offsets stay interior (the old expansion forced 0 / text.length). Confirmed red before the fix, green after.
  • pnpm -C packages/muya lint:types clean, ESLint clean.
  • Full unit suite: 733 passed; check-circular clean.
  • Related e2e (editing/ + typing/lists): 21 passed, including table-cell-selection (rectangle selection intact) and selection.spec.ts (Cmd+A across blocks).

🤖 Generated with Claude Code

Jocs and others added 2 commits June 13, 2026 09:46
TextSelection.handleMousemoveOrClick grew any cross-block text selection
to cover the entire enclosing block: a focus landing in a code block,
list item, or table cell snapped the anchor offset to 0 and the focus
offset to text.length, selecting the whole code block / list item /
table. Remove the four expansion branches so the selection ends exactly
where the pointer lands. The same-block early return is unchanged, and
this does not touch TableRectSelection (rectangular cell drag) or the
Cmd+A selectAll escalation, which are separate paths.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add a Chromium e2e regression test that drags between two list items
(interior char offsets) and asserts the resulting anchor/focus offsets
stay interior, rather than snapping to whole-item bounds.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Jocs
Jocs merged commit 12d1415 into develop Jun 13, 2026
7 checks passed
@Jocs
Jocs deleted the fix/text-selection-no-block-expand branch June 13, 2026 03:01
@jyte jyte mentioned this pull request Jun 29, 2026
3 of 6 tasks
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