Skip to content

Clear the region before snapping point to the live viewport - #701

Merged
dakra merged 1 commit into
mainfrom
fix/readonly-exit-deactivates-mark
Sep 18, 2026
Merged

dakra merged 1 commit into
mainfrom
fix/readonly-exit-deactivates-mark

Conversation

@dakra

@dakra dakra commented Sep 18, 2026

Copy link
Copy Markdown
Owner

Fixes #698.

The bug

Switching to a live input mode snaps point to the end of the buffer. Three
call sites do this, and none of them cleared an active region first, so the
selection stretched from its start to the prompt. Emacs then published that
grown span to the primary selection when the mark was finally deactivated,
via select-active-regions. The kill ring is untouched and the grown region
is never highlighted, which is why this stayed invisible.

The reporter hit it after leaving the buffer and returning, which silently
enters a read-only mode by two independent routes: the minibuffer-exit check
sees point off the live cursor, and a buffer switch finalizes the mark
activation. The next keystroke exits that mode and triggers the snap.

This is not specific to ghostel-mouse-drag-input-mode being nil. Under the
default settings a mouse drag already enters copy mode, so drag-then-type
reproduces it with a stock configuration and no buffer switch.

The fix

deactivate-mark immediately before the snap, at each of the three sites:
the read-only exit, ghostel-semi-char-mode, and ghostel-char-mode. The
last two are the shared root for every entry direction, including entering
char mode from semi-char and leaving line mode.

The custom exit branch is left alone. It keeps point where the user put it,
and the one implementation that exists deactivates the mark itself.

Verification

Reproduced live in a sandboxed Emacs running a real shell under ghostel,
both reported routes and the default-configuration route, before and after.

Two ERT tests record point from deactivate-mark-hook, which Emacs runs
from inside deactivate-mark after clearing mark-active, so a deactivation
that happened after the snap reports the wrong position. Both were confirmed
to fail against the unfixed source with the compiled files rebuilt between
runs.

make -j8 all passes.

Switching to a live input mode snaps point to the end of the buffer.
Three call sites do this and none cleared an active region first, so a
selection stretched from its start to the prompt, and Emacs handed that
grown span to the primary selection once the mark was deactivated.  The
kill ring is untouched and the grown region is never highlighted, which
is why it went unnoticed.

Leaving a terminal buffer and returning silently enters a read-only mode
by two routes: the minibuffer-exit check sees point off the live cursor,
and a buffer switch finalizes the mark activation.  The next keystroke
exits that mode and snaps.  Entering char mode and leaving line mode run
their own snap and were reached with the mark still active too.

Deactivate at each of the three snaps.  The custom exit branch keeps
point where the user left it and needs no guard.

The new tests read point from deactivate-mark-hook, which runs inside
deactivate-mark after mark-active is cleared, so a deactivation that
came after the snap reports the wrong position.  They bind
transient-mark-mode, which batch Emacs leaves nil.

Fixes #698.
@dakra
dakra force-pushed the fix/readonly-exit-deactivates-mark branch from c6dcbed to e61851d Compare September 18, 2026 07:47
@dakra
dakra merged commit e61851d into main Sep 18, 2026
26 of 27 checks passed
@dakra
dakra deleted the fix/readonly-exit-deactivates-mark branch September 18, 2026 07:51

This branch was successfully deployed

1 active deployment
github-pages — e61851d5 Deployed Sep 18, 2026 by dakra via deploy #198
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.

Mouse selection extended to prompt after temporarily leaving Ghostel buffer

1 participant