fix(scrollback-trim): keep the full tail when the cut lands on a line boundary#299
Open
dormouse-bot wants to merge 1 commit into
Open
fix(scrollback-trim): keep the full tail when the cut lands on a line boundary#299dormouse-bot wants to merge 1 commit into
dormouse-bot wants to merge 1 commit into
Conversation
Deploying mouseterm with
|
| Latest commit: |
01a2dc9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e9ffa68f.mouseterm.pages.dev |
| Branch Preview URL: | https://nightly-scrollback-trim-clea.mouseterm.pages.dev |
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.
Nightly survey finding on
lib/src/lib/scrollback-trim.ts.When persisted scrollback exceeds the cap,
trimPersistedScrollbackkeeps the lastmaxCharscharacters and then cuts forward to the next newline so replay never shows a torn partial first line. But when themaxChars-char tail already begins exactly on a line boundary (the character just before it is\n), there is no torn first line — the tail is already a clean set of whole lines that fills the cap exactly. The old code still searched for the next newline and dropped that first full line, trimming one line more than necessary.Example:
trimPersistedScrollback('aaaa\nbbbb\ncccc\n', 10)returned'cccc\n'even though the clean 10-char tail'bbbb\ncccc\n'fits within the cap. The fix returns the whole tail when it starts on a boundary.The output was always valid (trailing
\npreserved, no torn line), so this is a quality fix, not a crash — it just retains slightly more useful scrollback on restore, which matches the module's stated intent ("the top of the buffer is the least useful thing to keep when we have to drop something"). Never exceeds the cap, since the retained tail is exactlymaxChars.Behavior in the spec (
docs/specs/transport.md, "Persisted scrollback cap") is unchanged: still capped, still cut at a line boundary, still keeps the tail. Added a regression test (keeps the whole tail when the cut already lands on a line boundary) that fails on the old code and passes now.