Skip to content

[audit] multi-cursor: vertical arrow keys use document-order traversal instead of visual movement #312

@claude

Description

@claude

Problem

In src/plugins/multiCursor/inputHandling.ts (lines 194–226), the ArrowUp/ArrowDown handler for multi-cursor mode uses Selection.findFrom($head, dir, true) to find the target position. This is a document-order operation that searches for the nearest valid text selection position, not a visual/coordinate-based vertical movement.

For single-line paragraphs, this works fine (it jumps to the adjacent block). But for long paragraphs with soft line wrapping, ArrowDown will not move to the line below visually — it will either find nothing or jump to the next textblock boundary.

In contrast, the addCursorAbove/addCursorBelow commands in commands.ts correctly use view.coordsAtPos/view.posAtCoords for coordinate-based vertical placement. The difference is that handleMultiCursorArrow only receives state (not view), so it cannot use coordinate-based movement.

Impact

ArrowUp/ArrowDown in multi-cursor mode behaves incorrectly in wrapped text — cursors jump between textblocks rather than moving visually up/down within a wrapped paragraph. This is inconsistent with normal ProseMirror vertical arrow behavior, which delegates to the browser's native caret movement.

Suggested fix

Either:

  1. Pass EditorView through to handleMultiCursorArrow so it can use coordinate-based movement (like addCursorVertical does), or
  2. Handle vertical arrow keys at the view level (in handleKeyDown plugin) where the view is available, rather than routing through the state-only handleMultiCursorArrow

File: src/plugins/multiCursor/inputHandling.ts:194-226

Metadata

Metadata

Assignees

No one assigned

    Labels

    auditCodebase audit findingbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions