8000 Fix history scrolling and preserve selection after deletion by tomasmark79 · Pull Request #566 · dvorka/hstr · GitHub
[go: up one dir, main page]

Skip to content

Fix history scrolling and preserve selection after deletion - #566

Draft
tomasmark79 wants to merge 6 commits into
dvorka:masterfrom
tomasmark79:fix/history-scrolling
Draft

tomasmark79 wants to merge 6 commits into
dvorka:masterfrom
tomasmark79:fix/history-scrolling

Conversation

@tomasmark79
@tomasmark79 tomasmark79 commented Sep 23, 2026 •
Copy link
Copy Markdown

HSTR currently limits interactive matches to the terminal height, so moving past the last visible row wraps to the beginning instead of reaching older commands. This change keeps the complete match list and scrolls a viewport through it.

  • Arrow keys stop at the ends of the list; Page Up/Down move by one visible page.
  • Selection uses a match index independently of its screen row, including prompt-bottom layouts and terminal resizing.
  • Deleting an entry preserves the viewport and selected screen row, including repeated deletion and the final page. The next match takes its place; deleting the final match selects the preceding one.
  • Query/view changes reset the viewport. Matching is not repeated on each navigation key.
  • Selection buffers use the active view count, avoiding allocations sized for larger inactive collections. View-switching tests cover empty favorites and favorites larger than history.

Includes man-page documentation and PTY integration tests (python3 test/src/test_scroll.py /path/to/hstr, requires pyte). Tests use temporary history files and cover paging, boundaries, resizing, deletion, filtering, regex, empty lists, and all four prompt/help layouts. History persistence is unchanged. Raw-history construction now initializes and compacts skipped entries, and both matching passes guard null or empty commands. Three Unity regressions cover empty entries with and without timestamps, empty parsed zsh commands, and histories with no valid commands.

Validation: built on NixOS; terminal regression suite passed; Unity suite reported 15 tests, 0 failures, 2 ignored. All three new history regressions fail before the fix and pass after it; a focused Valgrind run reports zero errors and zero lost bytes. The scrolling and deletion behavior was also verified interactively by the contributor.

Memory-check caveat: Valgrind reports existing leaks in history deletion and uninitialized-value diagnostics in regex matching. Both were reproduced against unpatched 520e79a with the same input, so this PR does not claim a clean Valgrind run or attempt unrelated memory-management fixes.

Fixes #92. Fixes #456. Fixes #561.

@dvorka
dvorka requested review from dvorka and a lite review from Copilot September 23, 2026 06:40
@dvorka
dvorka commented Sep 23, 2026
Copy link
Copy Markdown
Owner

This is really great! Thank you 🙏

Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate issues remain in history traversal, memory use, deletion behavior, and notification rendering.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Fixes history navigation by adding full-list scrolling, viewport-preserving selection, deletion handling, documentation, and PTY regression coverage.

Changes:

  • Adds indexed, non-wrapping navigation and page scrolling.
  • Preserves selection and viewport across deletion, filtering, and resizing.
  • Adds integration tests and man-page documentation.
File Summary and review findings
test/​src/​test_scroll.py Adds PTY regression coverage for scrolling, resizing, deletion, filtering, and layouts.
test/​README-scrolling.md Documents integration-test execution.
src/​hstr.c Implements scrolling and selection management. Findings: uninitialized raw-history slots may cause crashes or invalid rendering (critical, 1 vote); inactive-view allocations may use avoidable memory (moderate, 2 votes); final-match deletion can misplace the selection row (moderate, 1 vote); duplicate deletion can skip entries (moderate, 1 vote); deletion notifications can be erased by selection redraw (moderate, 1 vote).
man/​hstr.1 Documents navigation and deletion behavior.

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

Comment thread src/hstr.c
// keep all matches, not just the first terminal-sized page.
unsigned capacity=MAX(hstr->history->rawCount, hstr->history->count);
capacity=MAX(capacity, hstr->favorites->count);
hstr_make_selection(pattern, hstr->history, capacity);
Comment thread src/hstr.c Outdated
Comment on lines +1228 to +1229
unsigned capacity=MAX(hstr->history->rawCount, hstr->history->count);
capacity=MAX(capacity, hstr->favorites->count);
@dvorka
dvorka commented Nov 1, 2026
Copy link
Copy Markdown
Owner

@tomasmark79 I just want you let you know that I really appreciate your contribution - still 👁️ it to make sure it is safe. Please stay tuned! Thanks you!

@dvorka dvorka assigned dvorka and tomasmark79 and unassigned dvorka Nov 1, 2026
@dvorka
dvorka marked this pull request as draft November 1, 2026 20:40
@tomasmark79
Copy link
Copy Markdown
Author

Hi, I think it's fine. I'm using my own fork, so feel free to take your time with the installation process to ensure that it doesn't cause any problems. Personally, I use it and the project is very addictive overall, so the ability to move things around is something that makes it a must-have. Thank you for your hard work and for making this project a reality.

@tomasmark79
tomasmark79 force-pushed the fix/history-scrolling branch from 9d72658 to 0d53a5d Compare November 19, 2026 14:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hstr truncates shown history entries to amount of rows shown in terminal? Page support (or endless scrolling) Scrolling through history

3 participants

0