Skip to content

Only start a terminal highlight once a drag leaves the pressed cell - #126

Merged
ernestrc merged 4 commits into
unstablebuild:mainfrom
mvanhorn:fix/125-terminal-selection-clipboard
Sep 30, 2026
Merged

ernestrc merged 4 commits into
unstablebuild:mainfrom
mvanhorn:fix/125-terminal-selection-clipboard

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Clicking a terminal to focus it could replace the clipboard with a single character. The mouse SDK calls SetSelectionEnd for every held-button event, including pointer jitter inside the pressed cell, so a click with slight movement highlighted one cell and copied it. The terminal driver now waits until a drag reaches a different cell before it highlights and copies, which matches gnome-terminal.

The second part is the case @zhengqunkoo described with vim: when the running program tracks the mouse, the press goes to the program and no selection is anchored in the terminal, but the drag events that follow still painted a terminal highlight from a stale anchor and copied it. That highlight then stayed on its cell while vim scrolled. In that mode, clicks and drags now go to the program only.

Highlight-to-copy on real drags, double-click and triple-click works as before. The clipboard docs now describe both behaviors, since the issue noted they were undocumented.

Verification: new table tests in internal/term/vte/mouse_test.go cover a click, same-cell jitter, drags in each direction, dragging away and back, a mouse-tracking program, and word and line selection. The jitter and mouse-tracking cases fail on main and pass with this change. go test ./internal/term/..., go vet and golangci-lint pass.

Fixes #125

AI was used for assistance.

🤖 Generated with Claude Code

https://claude.ai/code/session_01A4fR1AynHqTUCqgzCsrRg3

@mvanhorn
mvanhorn force-pushed the fix/125-terminal-selection-clipboard branch from 03fc03b to c72b10d Compare September 23, 2026 21:20
@mvanhorn mvanhorn changed the title fix: keep terminal highlighting from overwriting the clipboard Only start a terminal highlight once a drag leaves the pressed cell Sep 23, 2026
@zhengqunkoo

zhengqunkoo commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

It now no longer highlights a cell at the slightest move, but when the mouse moves by a cell, only 2 cells get highlighted and further drags does not highlight anyting more.

So it seems like the underlying issue wasn't solved

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for testing @zhengqunkoo, that stall is a good clue. My best guess: every drag tick copied the selection to the clipboard, which starts a clipboard process synchronously, so the UI froze as soon as the drag left the first cell.

b1197e6 copies once on mouse release instead. The highlight should keep growing during the drag, and the clipboard fills when you let go. Programs that ask for button-motion events (1002/1003) now get the drag instead of it being swallowed. I can't reproduce the GUI side here, so could you give it another try?

mvanhorn and others added 4 commits September 30, 2026 23:50
The mouse SDK calls SetSelectionEnd for every held-button event, even while the
pointer stays in the pressed cell, so a click to focus the window highlighted one
cell and copied it over the clipboard. The SDK also auto-scrolls after each of
those events near the top or bottom edge, so a click in the top rows of a
scrolled-back terminal moved the view off the pressed cell and copied that way.
The terminal now neither highlights, scrolls nor copies until a drag reaches
another cell.

Highlight-to-copy on real drags, double-click and triple-click is unchanged. The
clipboard docs now describe it, and that a program tracking the mouse owns clicks
and drags.

Fixes unstablebuild#125

Signed-off-by: Matt Van Horn <[email protected]>
Copying on every drag tick runs the system clipboard command and waits for it on
the event loop, the suspected cause of a drag highlight that stopped growing after
two cells on Wayland. The highlight now follows the drag and is copied once, when
the gesture ends.

The gesture ends at the next mouse action rather than only at its release, so a
later right- or middle-click release does not copy the old highlight again, and
nothing is copied when Esc cleared the highlight during the drag.

Signed-off-by: Matt Van Horn <[email protected]>
The mouse SDK scrolls down while a drag is in the last rows of the pane, measured
against the delegate's Height. The terminal reported the whole buffer, scrollback
included, so once the history outgrew the screen the bottom zone fell below the
pane: dragging down neither scrolled nor extended the highlight past the last
visible row. Report the rows the window shows instead.

Co-Authored-By: Rune Agent (claude/claude-opus-5-5) <[email protected]>
Signed-off-by: ernestrc <[email protected]>
The mouse SDK auto-scrolled up whenever a drag was in the top rows, regardless of
direction, so pressing near the top and dragging down scrolled the view up and
grew the selection the wrong way. rune-go-sdk v0.7.1 only scrolls toward the edge
the selection grows to, tracking the pressed row as the view moves. That tracking
relies on ScrollUp and ScrollDown reporting whether the view moved, which the
terminal never did.

Co-Authored-By: Rune Agent (claude/claude-opus-5-5) <[email protected]>
Signed-off-by: ernestrc <[email protected]>
@ernestrc
ernestrc force-pushed the fix/125-terminal-selection-clipboard branch from b538256 to 779ad12 Compare September 30, 2026 21:54
@ernestrc
ernestrc enabled auto-merge (rebase) September 30, 2026 22:01
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/term/vte/mouse.go 90.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ernestrc
ernestrc merged commit 7275a87 into unstablebuild:main Sep 30, 2026
8 checks passed
@mvanhorn

mvanhorn commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

@ernestrc thanks! Clicking a terminal to focus it won't clobber the clipboard with a single character anymore.

@ernestrc

ernestrc commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

@ernestrc thanks! Clicking a terminal to focus it won't clobber the clipboard with a single character anymore.

Thank you for pitching in!

@zhengqunkoo zhengqunkoo mentioned this pull request Oct 3, 2026
2 tasks done
ernestrc pushed a commit that referenced this pull request Oct 5, 2026
Fixes #175.

The SDK reports held-button moves, including pointer jitter inside the
pressed cell, through `SetSelectionEnd`. The Vim mouse delegate selected
the cell and switched to visual mode in `SetSelectionStart`, before any
drag could be told apart from a click, so focusing the window with the
mouse left a one-cell highlight that survived scrolling and forced an
Esc to get back to normal mode — the same shape #126 fixed on the
terminal side.

Signed-off-by: Santhi Prakash <[email protected]>
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.

Highlight to copy to clipboard feature is inconsistent

4 participants