Repository navigation
Fixed(terminal-emulator): Keep cell styles when inserting characters (CSI @) - #5424
Open
kukirin-ui wants to merge 2 commits into
Open
kukirin-ui wants to merge 2 commits into
kukirin-ui wants to merge 2 commits into
Conversation
…(CSI @) TerminalRow.copyInterval() copied the source text when copying within the same row but read styles from the row being overwritten, so shifting cells right smeared the style of the insert position over the rest of the line. This made colored shell prompts lose their color after line editing. Closes termux#5415
|
The logic regarding state isolation for self-overlapping row copies in Since the terminal line width bounds are predictable, could we potentially optimize this pipeline by bypassing the full array duplication if the displacement shift intervals ( Either way, the current code accurately prevents the crash state. Good work on the test coverage. |
This was referenced Nov 9, 2026
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.
Fixes #5415
When bash redraws the line after the cursor ends up in the wrong place (typeahead like
^[[Bechoed before the prompt), typing a character sendsCSI 1 @(insert character). ICH shifts the rest of the row right withTerminalBuffer.blockCopy(), which ends up inTerminalRow.copyInterval()copying a row onto itself.copyInterval()already takes a copy ofmTextfor that case, but it still read styles withline.getStyle()from the live row. Copying left to right, every cell after the insert point picked up a style that had just been overwritten, so the style at the cursor got smeared over the rest of the line. That's why the green~turned default colored.The fix takes a copy of
mStyleas well when source and destination are the same row.Test: added
testInsertCharactersKeepsStyleOfShiftedCellstoControlSequenceIntroducerTest. It feeds the exact output bash 5.2 produced for the steps in the issue (captured in a pty) plus a simpler case. It fails before the change and passes after; the other terminal-emulator tests still pass (run with a local JUnit setup, not the Gradle build; not yet tried on a device).AI disclosure: I used an AI assistant to test the fix.