Skip to content

feat: character-level chat selection that persists after mouse release - #236

Draft
wowi42 wants to merge 2 commits into
gi-dellav:mainfrom
wowi42:feat/char-level-selection
Draft

feat: character-level chat selection that persists after mouse release#236
wowi42 wants to merge 2 commits into
gi-dellav:mainfrom
wowi42:feat/char-level-selection

Conversation

@wowi42

@wowi42 wowi42 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements item 4 of the "Input and pickers" section of #186 ("Support character-level selection: mouse drag and y copy currently select whole visual rows only") and fixes a UX bug where the selection disappeared the moment the mouse button was released.

Changes

Character-level selection

  • Selection endpoints are now (visual_line, display_col) points instead of whole-row LineEntry indices; MouseDrag honors the column it previously ignored.
  • The viewport renders the selection as a partial-line reversed segment: first/last lines sliced to their columns, middle lines fully covered. Slicing is display-column based and CJK-aware (wide chars straddling a boundary are excluded), via new byte_index_at_display_col / display_col_slice helpers in ui::utils.
  • selected_text() (and therefore y copy) extracts exactly the highlighted range, normalizing reversed/upward drags.

Selection persists after mouse release, and is copied on release

  • Previously MouseUp copied to clipboard and immediately cleared the selection, so the highlight vanished on release. Now the drag ends (selection_dragging tracks the button state separately from selection_active) but the highlight stays: y copies again, Esc clears, the next click starts a new selection.
  • The selection is also copied to the system clipboard on release via copy_to_clipboard (pbcopy/wl-copy/xclip/clip.exe): while mouse capture is enabled the terminal emulator has no native selection, so Cmd+C (macOS) / Ctrl+Shift+C (Linux) has nothing to grab — the app must write the pasteboard itself.

Verification

  • cargo test (720 passed), cargo test --no-default-features (605), cargo clippy --all-features and --no-default-features with -D warnings — all clean.
  • New unit tests: display-column helpers (incl. CJK), char-level selected_text (first/last line slicing, reversed drag, empty point selection).
  • Smoke-tested on a pty with synthetic SGR mouse events: partial-line reverse highlight renders, selection survives release, y copies it.

Refs #186

wowi42 added 2 commits July 27, 2026 22:23
Two related fixes (item from gi-dellav#186):

- Selection endpoints are now (visual_line, display_col) points instead
  of whole-row indices. Mouse drag honors the column, the highlight
  renders as a partial-line reversed segment (CJK-aware slicing via new
  ui::utils display-column helpers), and selected_text()/y copy extract
  exactly the highlighted range: first/last lines sliced, middle lines
  whole.
- Bug: mouse release used to copy and immediately clear the selection,
  so the highlight vanished the moment the button was let go. The
  selection now stays visible after release; y copies it, Esc clears
  it, and the next click starts a new one.
While mouse capture is enabled the terminal emulator has no native
selection, so Cmd+C (macOS) / Ctrl+Shift+C (Linux) has nothing to copy
— the app must write the pasteboard itself. Mouse release now copies
the selection via copy_to_clipboard (pbcopy/wl-copy/xclip/clip.exe)
with a "copied selection" confirmation, and the highlight still
persists for y/Esc.
@wowi42

wowi42 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up (0fa1d4d): selection is now also copied to the system clipboard on mouse release — with mouse capture enabled the terminal emulator has no native selection, so Cmd+C/Ctrl+Shift+C has nothing to copy and the app must write the pasteboard itself. The highlight still persists for y/Esc. Verified on macOS: pbpaste contains the selected text after release.

@wowi42
wowi42 marked this pull request as draft July 28, 2026 05:27
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