Skip to content

feat(input): double-click selects the word under the cursor#59

Merged
roramirez merged 2 commits into
mainfrom
feature/double-click-word-select
Jul 5, 2026
Merged

feat(input): double-click selects the word under the cursor#59
roramirez merged 2 commits into
mainfrom
feature/double-click-word-select

Conversation

@roramirez

@roramirez roramirez commented Jul 4, 2026

Copy link
Copy Markdown
Owner

What it does

A left double-click selects the word under the pointer, leaves it highlighted in anchored Visual mode (so you can see exactly what was picked), and copies it to the clipboard. Esc or a click returns to Insert.

A double-click is registered when the second press happens within ~400 ms and less than ~4 px of the previous one. Word boundaries reuse the existing is_word logic (alphanumerics and _). Double-clicking a blank cell selects nothing.

Changes

  • src/input/motion.rs: new word_bounds helper (+ 4 tests).
  • src/input/mouse_ops.rs: new select_word_at method — sets anchored Visual selection over the word and copies it; empty/blank cells select nothing.
  • src/app_event.rs: is_double_click + wiring in handle_selection_click.
  • src/app_state.rs: new field last_click: Option<(Instant, f64, f64)>.
  • CHANGELOG.md.

How to test manually

  1. In this worktree: cargo run.
  2. Produce some text: echo hola-mundo foo_bar baz.
  3. Double-click on foo_bar → the whole word stays highlighted (_ included) and is copied to the clipboard.
  4. Paste (Ctrl+Shift+V or middle-click) at the prompt → foo_bar appears.
  5. Press Esc (or click elsewhere) → the highlight clears and you are back in Insert.
  6. Double-click on blank space → nothing is selected/highlighted and it does not crash.
  7. Regression:
    • Click-and-drag still selects a free range and copies it on release.
    • A single click still moves focus / opens a URL under the cursor as before.
    • Two slow clicks (>400 ms) or far apart (>4 px) behave as two single clicks, not a double-click.

Tests

cargo test — full suite green. word_bounds covered by 4 tests (word_bounds_spans_whole_word_from_middle, _spans_first_word_from_edge, _on_space_selects_single_cell, _treats_underscore_as_word). The timing detection (is_double_click) and the on-screen highlight are validated manually (they depend on real winit/rendering).

roramirez added 2 commits July 4, 2026 17:07
A left double-click (within ~400 ms and ~4 px of the previous press)
selects the whole word under the pointer via a new motion::word_bounds
helper, copies it to the clipboard, and returns to Insert mode —
consistent with drag-selection. Word boundaries reuse the existing
is_word logic (alphanumerics and underscore).
Double-click now leaves the selected word highlighted in anchored Visual
mode (in addition to copying it) so the user can see what was picked,
instead of silently returning to Insert with no visible feedback. A
blank cell selects nothing; Esc or a click returns to Insert.
@roramirez roramirez merged commit 03f3c40 into main Jul 5, 2026
2 checks passed
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