Text fields: a drag from right to left only moves the caret #236

Closed
opened 2026-09-26 15:15:54 +02:00 by meleki · 1 comment
Owner

Selecting text in a field with the mouse works from left to right. From right to left the selection does not grow: the caret just follows the mouse to the left.

Cause

TextField keeps the selection as anchor (selStart) and focus (selEnd) and pushes it into the hidden <input> of the KeyboardBridge. The bridge set the range ordered (lo, hi) and without a direction. The browser answers with a selectionchange, and the bridge reported selectionStart/selectionEnd back, again ordered. After the first move of a backward drag the anchor was therefore the left end, i.e. where the mouse just was. Every further move selected only between two neighbouring positions.

Fix

  • The bridge takes and reports anchor and focus. It sets the range with selectionDirection: 'backward' when focus < anchor, and reads the direction back in sync.
  • TextField passes selStart/selEnd through unchanged.

Shift+Arrow to the left goes through the same sync, so the drawn caret should now sit at the moving end there too. Not tested separately.

Test

e2e 2d-ii drags across the name field from right to left and reads the hidden input: 0..length, backward.

Selecting text in a field with the mouse works from left to right. From right to left the selection does not grow: the caret just follows the mouse to the left. ## Cause `TextField` keeps the selection as anchor (`selStart`) and focus (`selEnd`) and pushes it into the hidden `<input>` of the `KeyboardBridge`. The bridge set the range ordered (`lo, hi`) and without a direction. The browser answers with a `selectionchange`, and the bridge reported `selectionStart`/`selectionEnd` back, again ordered. After the first move of a backward drag the anchor was therefore the left end, i.e. where the mouse just was. Every further move selected only between two neighbouring positions. ## Fix - The bridge takes and reports anchor and focus. It sets the range with `selectionDirection: 'backward'` when focus < anchor, and reads the direction back in `sync`. - `TextField` passes `selStart`/`selEnd` through unchanged. Shift+Arrow to the left goes through the same `sync`, so the drawn caret should now sit at the moving end there too. Not tested separately. ## Test e2e 2d-ii drags across the name field from right to left and reads the hidden input: `0..length`, `backward`.
Author
Owner

Fixed in 1b3cb62.

Cause: Canvas text fields mirror their selection into a hidden <input> (src/ui/KeyboardBridge.ts). It always got the range sorted and without a direction, and its selectionchange echo handed back the sorted range. Dragging right to left therefore moved the anchor to the mouse on the first move, and every further move only selected between two neighbouring positions. It looked like the cursor just moving left.

Fix:

  • The bridge works with anchor and focus. It sets 'backward' as the direction when the focus lies before the anchor, and reads selectionDirection back.
  • TextField passes both through unchanged, its own sorting is gone.
  • Shift+Left runs through the same path. Not tested on its own.

Tests:

  • ./check.sh: 167 files, 2435 tests, CHECK EXIT 0
  • e2e 2: ALL PASSED, 25 checks. New check 2d-ii drags right to left in the name field with real mouse moves and reads {"start":0,"end":13,"direction":"backward"}.
  • Counter-check without the direction: 2d-ii fails with "end":2, the reported symptom.
  • e2e check total is now 1401 (README and wiki Development), computed, not yet confirmed by CI.
Fixed in 1b3cb62. **Cause:** Canvas text fields mirror their selection into a hidden `<input>` (`src/ui/KeyboardBridge.ts`). It always got the range sorted and without a direction, and its `selectionchange` echo handed back the sorted range. Dragging right to left therefore moved the anchor to the mouse on the first move, and every further move only selected between two neighbouring positions. It looked like the cursor just moving left. **Fix:** - The bridge works with anchor and focus. It sets `'backward'` as the direction when the focus lies before the anchor, and reads `selectionDirection` back. - `TextField` passes both through unchanged, its own sorting is gone. - Shift+Left runs through the same path. Not tested on its own. **Tests:** - `./check.sh`: 167 files, 2435 tests, CHECK EXIT 0 - e2e 2: ALL PASSED, 25 checks. New check 2d-ii drags right to left in the name field with real mouse moves and reads `{"start":0,"end":13,"direction":"backward"}`. - Counter-check without the direction: 2d-ii fails with `"end":2`, the reported symptom. - e2e check total is now 1401 (README and wiki *Development*), computed, not yet confirmed by CI.
admin added this to the Development project 2026-09-27 11:28:31 +02:00
admin moved this to Done in Development on 2026-09-27 11:29:05 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: meleki/feuerwerk#236