diff options
| author | Zack Drach <zackdrach@gmail.com> | 2026-05-26 03:40:29 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-26 13:40:29 +0300 |
| commit | 6c4a947244b7be05496f9d3bd5ad2d00a69cca03 (patch) | |
| tree | 421b4a009e2a201c9be65806fd0e13fe9899c73a /src/selection.rs | |
| parent | 33e71ed2f50e5ca8950029f89f41e0ec135b87c0 (diff) | |
Add tmux-style double-click word copy (#296)
* feat: add tmux-style double-click copy
Double-clicking terminal output now selects and copies the token under the cursor, similar to tmux. The copied token briefly stays highlighted as feedback, and token detection handles common shell output like paths, URLs, variables, CJK text, and surrounding punctuation.
Mouse events are still forwarded unchanged when the child terminal has mouse reporting enabled.
refs #142
* fix: tighten double-click copy
refs #142
---------
Co-authored-by: Can Celik <ogulcancelik@gmail.com>
Diffstat (limited to 'src/selection.rs')
| -rw-r--r-- | src/selection.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/selection.rs b/src/selection.rs index 016cf649..35e44c1d 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -7,6 +7,8 @@ //! MouseUp → Text extracted, copied via OSC 52, highlight stays //! Next click / key → Selection cleared //! +//! Double-click copy also briefly highlights the selected word. +//! //! Rows are stored in screen-buffer coordinates instead of viewport-relative //! coordinates. That keeps selection stable while the pane scrolls. @@ -59,6 +61,23 @@ impl Selection { } } + /// Create an active selection from an explicit viewport-row range. + pub(crate) fn range( + pane_id: PaneId, + viewport_row: u16, + start_col: u16, + end_col: u16, + metrics: Option<ScrollMetrics>, + ) -> Self { + let row = absolute_row_for_viewport_row(viewport_row, metrics); + Self { + pane_id, + anchor: (row, start_col), + cursor: (row, end_col), + phase: Phase::Dragging, + } + } + /// Convert the anchor's absolute row and pane-relative column back to /// screen coordinates. Adds the pane origin before clamping so the /// returned (screen_row, screen_col) can be compared directly against @@ -114,6 +133,11 @@ impl Selection { self.phase == Phase::Dragging || self.phase == Phase::Done } + /// Whether this selection was already finalized and copied. + pub fn is_done(&self) -> bool { + self.phase == Phase::Done + } + /// Whether the user just clicked without dragging (not a selection). pub fn was_just_click(&self) -> bool { self.phase == Phase::Anchored |
