Fix selection crashes and scrollback handling (0.9.4)#4
Open
kdedev wants to merge 2 commits intomarchaesen:mainfrom
Open
Fix selection crashes and scrollback handling (0.9.4)#4kdedev wants to merge 2 commits intomarchaesen:mainfrom
kdedev wants to merge 2 commits intomarchaesen:mainfrom
Conversation
Instead of allocating all 10000 history lines upfront (~3.8 MB), allocate them lazily in pages of 256 lines as scrollback is used. A typical terminal session only scrolls back a few hundred lines, so most of the history buffer is never touched. This avoids wasting memory on unused allocations. Changes: - HISTSIZE increased from 2000 to 10000 (cheap with lazy alloc) - Added HIST_PAGESIZE (256) for batch allocation granularity - Added histensure() to allocate a page of history on first access - tnew initializes hist[] to NULL instead of xmalloc - tresize and clear/reset guard against NULL hist entries - Both st.c (non-reflow) and patch/reflow.c paths covered
696d2c4 to
dde512b
Compare
….9.5) Selection system overhaul: - Scroll-while-selecting: dragging past top/bottom edge auto-scrolls using nosel variants that preserve selection during scroll - Fix selection coordinate drift: keep coords screen-relative (removed erroneous + term.scr offset in selstart/selextend) - Fix selection clearing: only clear when both endpoints scroll fully off-screen in the same direction - Fix scrollback copy: getsel clamps to full TLINE range (0..term.row+term.scr-1), copies entire selected region - Fix selnormalize crash: nosel functions use direct MIN/MAX on nb/ne instead of calling selnormalize (selsnap unsafe with off-screen y) - Add DBGSEL macro for conditional debug logging (zero cost in release) Scroll behavior: - Mouse wheel: 3 lines per tick, natural scroll direction - Plain PageUp/PageDown passed to apps (micro, vim, etc.) - Shift+PageUp/Down for terminal scrollback - Bounds validation on all selection coordinates
dde512b to
8232a90
Compare
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.
This PR fixes several critical bugs in selection handling during scrollback:
Crashes fixed:
Selection improvements:
Other improvements:
Tested extensively with ASAN - no memory errors detected.