Skip to content

Restore bracketed paste mode instead of forcing it off - #4891

Merged
junegunn merged 2 commits into
masterfrom
devel
Aug 10, 2026
Merged

Restore bracketed paste mode instead of forcing it off#4891
junegunn merged 2 commits into
masterfrom
devel

Conversation

@junegunn

Copy link
Copy Markdown
Owner

Contribution Policy

We do not accept pull requests generated primarily by AI without genuine understanding or real-world usage context.

All contributions are expected to demonstrate:

  • A clear understanding of the codebase
  • Alignment with product direction
  • Thoughtful reasoning behind changes
  • Evidence of real-world usage or hands-on experience with the problem

If these expectations are not met, we would prefer to implement the changes ourselves rather than spend time reviewing low-effort submissions.


Acknowledgement

  • I confirm that this PR meets the above expectations and reflects my own understanding and real-world context.

@junegunn
junegunn requested a lite review from Copilot August 10, 2026 11:15
@junegunn junegunn self-assigned this Aug 10, 2026
@junegunn junegunn added the bug Something isn't working label Aug 10, 2026
@github-actions github-actions Bot added docs Documentation go Go code test Tests labels Aug 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the TUI startup/teardown behavior to (1) restore bracketed paste mode to its prior state instead of always disabling it on exit, and (2) avoid blocking at startup on terminals that never answer escape-sequence queries, while also doing some related comment/test cleanups.

Changes:

  • Add a startup query round-trip to detect whether bracketed paste mode was already enabled, and restore it accordingly on exit.
  • Add a bounded wait before the first read for terminal query replies to prevent startup hangs on non-responding terminals.
  • Update comments/tests and document the behavioral changes in the changelog.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/tui/light.go Adds startup query plumbing, bracketed paste state tracking, and restores paste mode on exit.
src/tui/light_unix.go Implements query batching + timeout-bounded read for terminal replies; parses cursor/paste replies.
src/tui/light_windows.go Adds a Windows stub for the new startup query API (cursor offset only).
src/util/chars.go Comment wording adjustments around foldable rune range rationale.
src/util/chars_test.go Removes a verbose/unclear tab wrap block; tightens comment wording.
src/algo/runeprefilter_test.go Comment wording adjustments (“pins” → “verifies/checks”, clarity tweaks).
src/algo/fastpath_equiv_test.go Comment wording (“oracle” → “reference”).
src/algo/algo.go Comment wording adjustment.
CHANGELOG.md Documents bracketed paste restoration and the startup hang fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/tui/light_unix.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/tui/light_unix.go:126

  • waitReadable returns true on unix.Select error, which can reintroduce the startup hang this code is trying to avoid (a subsequent blocking read may wait for user input). It's safer to treat select errors as "not readable" and let the caller stop waiting / fall back.
		if err != nil {
			// Fall through to the read and let it report the failure
			return true
		}

src/tui/light_unix.go:150

  • queryTerminal calls getBytesInternal with nonblock=true on retries (tries > 0). If there's no data available, getBytesInternal can still append byte(c) (often 0x00) to the buffer even when the nonblocking read fails, which can corrupt the buffered terminal reply and prevent the regex from ever matching. Guard retries with waitReadable and skip the read when nothing is ready.
		buffer, _, err = r.getBytesInternal(false, buffer, tries > 0)

src/tui/light.go:41

  • pasteModeRegexp allows an optional leading NUL ("\x00?") but pasteModeRegexpBegin does not. If the terminal includes that NUL in the DECRPM reply, escSequence won't recognize it as a terminal reply and may emit a CtrlSpace (0x00) event before the escape sequence, corrupting input.
var pasteModeRegexpBegin = regexp.MustCompile("^\x1b\\[\\?2004;[0-4]\\$y")

Ask the terminal whether the mode is already on (DECRQM) and put it back
that way on exit. Forcing it off broke pasting in shells that run fzf
from a line editor widget, which enable the mode only when the editor
starts. Terminals that do not answer fall back to disabling it.

- Startup queries go out in one write, cursor position last. Every
  terminal answers DSR, so its reply bounds the wait: a paste reply
  still missing by then means the terminal does not know the query.
- Bound the first read with select(2). Terminals that never answer
  escape sequences, such as FreeBSD virtual terminals, blocked startup
  until a key was pressed, and that keystroke was then discarded.

Fix #4887
Fix #2860
Fix #976

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@junegunn
junegunn merged commit dab626b into master Aug 10, 2026
9 checks passed
@junegunn
junegunn deleted the devel branch August 10, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working docs Documentation go Go code test Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants