Repository navigation
Insert pasted text literally instead of as keystrokes - #6
Merged
Merged
Conversation
A paste reaches the editor as ordinary characters, so auto indent ran on every newline in it. Each pasted line already carries its own leading whitespace, and auto indent prepended the previous line's on top, so the indentation grew line by line into a staircase. Tabs in the pasted text were expanded to spaces for the same reason. Enable the terminal's bracketed paste mode, which wraps a paste in ESC[200~ and ESC[201~. Those markers have no terminfo entry, so they arrive as plain characters and are matched in get_input; anything that does not match is pushed back, leaving a lone ESC and every other escape sequence untouched. The payload is inserted with auto indent suppressed and one undo state for the whole paste rather than one per keystroke. The mode is turned off again on exit so the shell does not inherit it. Terminals that do not support bracketed paste ignore the enabling sequence and behave exactly as before.
This was referenced Sep 13, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pasting indented text produced a staircase — each line indented one level further than the last.
Cause
A paste arrives at the editor as ordinary keystrokes.
editor.pyauto-indents on every newline, prepending the current line's leading whitespace to the next line — which, in a paste, already carries its own indentation. Each line compounds the one before it.Reproduced by pasting an 11-line
.bashrcfragment, leading whitespace per line:The literal
[200~and[201~markers were also being typed into the buffer, since nothing recognised them.Fix
Enable bracketed paste mode (
ESC[?2004h), which makes the terminal wrap pastes inESC[200~…ESC[201~. Those have no terminfo entry, so curses hands them over as plain characters — verified — and they are matched inget_input. Non-matching characters are pushed back withunget_wch, so a lone ESC and every other escape sequence are untouched.The payload is then inserted with auto-indent suppressed, tabs kept literal, and a single undo state for the whole paste.
Verification
Pasting the fragment now produces a file byte-identical to the source (
diffreports no difference).ESC handling, the main regression risk since Suplemon binds ESC to single-cursor:
ABCABCABESCCDABCD— ESC consumed, next char not eatenABCABCXPASTEDYEdge cases: tabs stay literal tabs, mid-line paste, multi-line into an empty buffer, empty paste, and a paste ending in a newline all behave. The mode is disabled on exit, verified as the last sequence written, so the shell does not inherit it.
test.shpasses, flake8 clean.Not fixed here
Undoing a paste steps back one edit too far. That is pre-existing and unrelated: on master,
type KEEP, Enter, one undo also yieldsK.store_action_stateonly records continued same-action editing whencurrent_state < len(history)-1, so a typing run after the first character is never captured and the next action's undo point is stale. Worth its own change.