Skip to content

Fix mouse-2 paste and RET in copy mode#254

Merged
dakra merged 1 commit into
mainfrom
fix-251-mouse-copy-mode
May 10, 2026
Merged

Fix mouse-2 paste and RET in copy mode#254
dakra merged 1 commit into
mainfrom
fix-251-mouse-copy-mode

Conversation

@dakra
Copy link
Copy Markdown
Owner

@dakra dakra commented May 10, 2026

Summary

Fixes #251.

  • Middle-click (<mouse-2>) now pastes the X primary selection at the live prompt via bracketed paste, even when no DEC mouse-tracking mode (1000/1002/1003) is active. Selects the click's window first so middle-clicking an unfocused ghostel window pastes into that terminal, not whichever buffer happened to be current. In copy/Emacs mode with ghostel-readonly-fast-exit on, the wrapper exits to the prior input mode first so the paste lands at the prompt.
  • RET / <return> in ghostel-readonly-fast-exit-mode-map no longer feels stuck after Auto-enter copy mode on mouse-1 click when no app tracks the mouse #242 flipped the buffer into copy mode on a focus click. New ghostel-readonly-RET-or-exit-and-send opens a link at point if there is one, otherwise exits read-only and forwards a CR. Without fast-exit, the parent map's ghostel-open-link-at-point still wins.
  • Drive-by: rename C-c C-l to C-c M-l in the fast-exit map so the parent's ghostel-line-mode binding is no longer shadowed, and add C-c C-e for symmetry with semi-char mode.

Test plan

  • make -j6 all (78 evil + 161 native + 331 elisp tests, 0 unexpected, lint clean)
  • New tests cover: middle-click tracking on/off forwarding, empty primary no-op, fast-exit on/off auto-exit, the new select-window retarget regression, RET on/off a link, no-CR when returning to Emacs mode, fast-exit-only RET binding gating
  • Live (Linux): select text in browser → middle-click in a ghostel window → primary selection appears at prompt via bracketed paste
  • Live: RET in copy mode (with fast-exit) → exits to prior mode and prompt redraws
  • Live: tmux with set -g mouse on and htop still receive forwarded mouse events when tracking is active

Two issues from #251:

1. `<mouse-2>' in semi-char or copy mode silently dropped the click —
   the bound handler `ghostel--mouse-release' only emits bytes when a
   DEC mouse-tracking mode (1000/1002/1003) is on, so middle-click
   paste, the standard X primary-selection paste on Linux, did nothing
   when no app was tracking.

   New wrappers `ghostel-mouse-down-2-or-noop' and
   `ghostel-mouse-paste-primary-or-release' forward to libghostty when
   tracking is on (TUI behaviour preserved) and otherwise feed
   `gui-get-primary-selection' to `ghostel--paste-text', which uses
   bracketed paste at the live prompt.  In copy/Emacs mode with
   `ghostel-readonly-fast-exit' on, the wrapper exits to the prior
   input mode first so the paste lands at the prompt; with fast-exit
   off it pastes in place, mirroring `ghostel-yank' / C-y semantics.

2. RET in copy mode was eaten by `text-read-only' once
   `ghostel-mouse-press-or-copy-mode' (added in #242) flipped the
   buffer into copy mode on a focus click.  Users would press RET
   expecting a prompt redraw and see nothing happen.

   New helper `ghostel-readonly-RET-or-exit-and-send' is bound to RET
   and `<return>' in `ghostel-readonly-fast-exit-mode-map' only.  At a
   hyperlink it still calls `ghostel-open-link-at-point'; otherwise it
   exits read-only mode and forwards a CR via the encoder (skipped if
   we are returning to Emacs mode, which is also read-only).  Without
   fast-exit the parent map's `ghostel-open-link-at-point' wins, so
   users who explicitly opted out of fast-exit see no change.

Also: rename `C-c C-l' (exit-and-clear) to `C-c M-l' so the parent
map's `ghostel-line-mode' binding is no longer shadowed, and add
`C-c C-e' to the fast-exit map for symmetry with the semi-char-mode
binding.

Tests cover: tracking-on/off forwarding, empty primary, fast-exit
on/off auto-exit, RET on/off link, the no-CR-when-returning-to-emacs
path, and the keymap-binding gating.

Fixes #251.
@dakra dakra merged commit dcee642 into main May 10, 2026
22 checks passed
@dakra dakra deleted the fix-251-mouse-copy-mode branch May 22, 2026 08:53
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.

Copy mode on mouse-1

1 participant