Skip to content

Keep search selection followed on confirm#2003

Merged
BenBE merged 1 commit into
htop-dev:mainfrom
Komzpa:fix/search-enter-preserve-selection
May 19, 2026
Merged

Keep search selection followed on confirm#2003
BenBE merged 1 commit into
htop-dev:mainfrom
Komzpa:fix/search-enter-preserve-selection

Conversation

@Komzpa
Copy link
Copy Markdown
Contributor

@Komzpa Komzpa commented May 18, 2026

Summary

When confirming an active incremental search, keep the selected process as the table's followed row before refreshing the main panel.

This preserves the searched/selected row across the refresh that happens when leaving search mode, including sorted tree view setups where a rebuild can otherwise move the cursor to an unexpected row.

Testing

  • ./autogen.sh && ./configure
  • make -j32
  • make check
  • git diff --check

AI disclosure

This patch was prepared with assistance from OpenAI Codex and reviewed before submission.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 377d2549-e5ec-4bb1-b657-55340bb557fb

📥 Commits

Reviewing files that changed from the base of the PR and between c971ad5 and 7d7baeb.

📒 Files selected for processing (1)
  • MainPanel.c

📝 Walkthrough

Keep search selection followed on confirm

Changes: Update to MainPanel_eventHandler (MainPanel.c) to preserve the selected process row when confirming an incremental (non-filter) search.

Implementation: Snapshot pre-call state and compute two conditions around IncSet_handleKey:

  • wasSearch — whether a non-filter search was active before the key
  • activeSearchMatch — search remains active and non-filter after the key
  • confirmedSearch — Enter/KEY_ENTER cleared the search (confirm edge)

When either activeSearchMatch or confirmedSearch is true, the handler:

  • sets host->activeTable->following to the selected row ID
  • sets selection color to PANEL_SELECTION_FOLLOW
  • ORs HTOP_KEEP_FOLLOWING
    Additionally, on the confirmedSearch path it also ORs HTOP_REFRESH so the UI refreshes after leaving search mode.

Problem solved: Prevents losing the searched/selected row when exiting incremental search (which could move the cursor during table rebuilds, notably in sorted tree views).

Quality: Single, focused and localized change with clear variable naming and minimal surface area. No API changes. Commit appears logically scoped and in‑line with existing state-machine handling.

Lines changed: +8/-1

Walkthrough

This PR updates MainPanel_eventHandler to snapshot whether the pre-key state was a non-filter incremental search, call IncSet_handleKey, then distinguish a continued active-search match from an Enter-confirmed search exit. If either condition holds it sets host->activeTable->following to the selected row, changes selection color to PANEL_SELECTION_FOLLOW, and sets HTOP_KEEP_FOLLOWING. If the transition is the Enter-confirmed exit it also sets HTOP_REFRESH.

Poem

A query ends with Enter's sigh,
The cursor finds the chosen line,
The selection turns to follow,
Flags set true and intent's not hollow,
The panel readies for a fresh align.


Comment @coderabbitai help to get the list of available commands and usage tips.

@BenBE BenBE added the enhancement Extension or improvement to existing feature label May 18, 2026
Copy link
Copy Markdown
Member

@BenBE BenBE left a comment

Choose a reason for hiding this comment

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

One minor idea to avoid a bit of code duplication; no need to implement, but open to hear opinions. Apart from that LGTM.

Comment thread MainPanel.c Outdated
@Komzpa Komzpa force-pushed the fix/search-enter-preserve-selection branch 2 times, most recently from e67b881 to 91a8641 Compare May 18, 2026 20:35
Comment thread MainPanel.c Outdated
Comment thread MainPanel.c Outdated
@Komzpa Komzpa force-pushed the fix/search-enter-preserve-selection branch from 91a8641 to 3b4eb98 Compare May 19, 2026 08:46
@BenBE BenBE force-pushed the fix/search-enter-preserve-selection branch from 3b4eb98 to ba9964f Compare May 19, 2026 20:42
@BenBE BenBE added this to the 3.6.0 milestone May 19, 2026
@BenBE BenBE force-pushed the fix/search-enter-preserve-selection branch from ba9964f to c971ad5 Compare May 19, 2026 20:44
@BenBE BenBE force-pushed the fix/search-enter-preserve-selection branch from c971ad5 to 7d7baeb Compare May 19, 2026 20:48
@BenBE BenBE merged commit 991ab83 into htop-dev:main May 19, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Extension or improvement to existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants