diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fe3650bc..ab92e0924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- The sidebar filter no longer clears when you open a table from the filtered list. It only clears when you empty the field. (#1690) - Redis entries no longer disappear after the connection sits idle. The health check was running `SELECT 1`, which on Redis switches the active database, so a later refresh scanned the wrong database. (#1701) - Redis key browsing now lists every key in a database or namespace and pages through them correctly. It was reading only the first SCAN batch, so large keyspaces showed a partial, fixed set of keys. (#1701) - A dropped Redis connection now reconnects on the next command and replays auth and the selected database, instead of failing until the next health check. (#1701) diff --git a/TablePro/Core/Services/Infrastructure/SidebarContainerViewController.swift b/TablePro/Core/Services/Infrastructure/SidebarContainerViewController.swift index c87ab23ab..a011f88df 100644 --- a/TablePro/Core/Services/Infrastructure/SidebarContainerViewController.swift +++ b/TablePro/Core/Services/Infrastructure/SidebarContainerViewController.swift @@ -131,9 +131,14 @@ extension SidebarContainerViewController: NSSearchFieldDelegate { } func searchFieldDidEndSearching(_ sender: NSSearchField) { + guard Self.shouldClearOnEndSearching(fieldValue: sender.stringValue) else { return } writeSearchText("") } + nonisolated static func shouldClearOnEndSearching(fieldValue: String) -> Bool { + fieldValue.isEmpty + } + func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool { guard commandSelector == #selector(NSResponder.moveDown(_:)) else { return false } view.window?.makeFirstResponder(hostingController.view) diff --git a/TableProTests/Views/SidebarSearchPersistenceTests.swift b/TableProTests/Views/SidebarSearchPersistenceTests.swift new file mode 100644 index 000000000..38e77803c --- /dev/null +++ b/TableProTests/Views/SidebarSearchPersistenceTests.swift @@ -0,0 +1,27 @@ +// +// SidebarSearchPersistenceTests.swift +// TableProTests +// +// Regression guard for #1690 where opening a table from a filtered sidebar +// cleared the active filter. searchFieldDidEndSearching fired on focus loss +// and wrote "" back over the persisted filter text. The filter must only be +// cleared when the field is actually empty (cancel button / explicit clear). +// + +import Foundation +import Testing + +@testable import TablePro + +@Suite("Sidebar search persistence on end editing") +struct SidebarSearchPersistenceTests { + @Test("keeps the filter when the field still has text and focus is lost") + func keepsFilterWhenFieldHasText() { + #expect(!SidebarContainerViewController.shouldClearOnEndSearching(fieldValue: "dp_")) + } + + @Test("clears the filter when the field is empty") + func clearsFilterWhenFieldEmpty() { + #expect(SidebarContainerViewController.shouldClearOnEndSearching(fieldValue: "")) + } +}