Skip to content

Conversation

juzu-o
Copy link
Contributor

@juzu-o juzu-o commented Jun 27, 2025

Fix: Preserve EntryView Scroll and Selection State in Search Mode

Description

This pull request fixes a long-standing issue where the entry list scroll position and selection jump to the wrong location when switching between open databases in search mode, especially if sorting is set to anything other than "Group." The bug is described in detail in #12001.

Problem

When switching between databases with search active, the entry view always resets sort order to "Group" and selects the first entry, ignoring the user's prior sort and selection. This causes the scroll position to jump unexpectedly, breaking user workflow and expectations.

Solution

  • The entry view now preserves the user's chosen sort column and order in search mode when switching between databases.
  • The previously selected entry is restored by UUID after updating the entry list, if possible.
  • If the previous selection cannot be restored, the first entry is selected as a fallback.
  • The code no longer forcibly resets sorting to "Group" when displaying search results.

This change ensures consistent and expected navigation when using multiple databases, search mode, and custom sort orders.

Steps to Reproduce (Before Fix)

See #12001 for detailed steps and screenshots.

Testing strategy

  1. Open two or more databases.
  2. In each, use search mode and set a sort order other than "Group."
  3. Select an entry in one database and switch between databases.
  4. Observe that the scroll position and selected entry remain consistent and as expected.

Type of change

  • ✅ Bug fix (non-breaking change that fixes an issue)

Additional Notes

AI Assistance Disclosure

Parts of this contribution were generated or reviewed using GitHub Copilot (OpenAI GPT-4o), an AI service, to assist with code search, patch suggestion, and documentation refinement. All code was written and fully reviewed by the contributor before submission, in accordance with KeePassXC's contributing guidelines.

  • AI Service Used: GitHub Copilot
  • Model: OpenAI GPT-4o

@Copilot Copilot AI review requested due to automatic review settings June 27, 2025 05:42
@juzu-o juzu-o changed the title Preserve EntryView scroll and selection state when switching databases in search mode #12001 Preserve EntryView scroll and selection state when switching databases in search mode Jun 27, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue with the EntryView in search mode by preserving the user's sort order and selected entry across database switches, rather than resetting them to default values.

  • The view state (sort order and selected entry) is saved before updating the entry list.
  • The state is restored after updating the entries, avoiding unexpected scroll and selection changes.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/gui/entry/EntryView.h Added declarations and member variables for state preservation.
src/gui/entry/EntryView.cpp Implemented save/restore functionality in displaySearch().
Comments suppressed due to low confidence (1)

src/gui/entry/EntryView.cpp:611

  • Ensure that unit tests using QTest scaffolding cover the new view state preservation functionality, including restoration of sort order and selection by UUID across database switches in search mode.
void EntryView::restoreViewState(const QList<Entry*>& entries)

Seem to be redundant call. Removing it doesn't seem to affect functionality. 
According to Copilot, sortByColumn() already calls m_sortModel->sort() and updates the UI.
Calling both is typically unnecessary and could be safely reduced to one call.

Co-authored-by: Copilot <[email protected]>
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.

Scroll jumps to wrong position when switching between databases

1 participant