From 9e1264455e80eb223f21c2fe97b14da2ae480c9f Mon Sep 17 00:00:00 2001 From: Kaede Akino Date: Wed, 2 Sep 2026 09:57:52 +0800 Subject: [PATCH] refactor --- Memory/REFACTOR.md | 33 +++++++++++++++++++ .../HostChooser/HostChooserView.swift | 7 ++-- .../Features/Keychain/KeychainPageView.swift | 9 ++--- .../Features/Snippets/SnippetsPageView.swift | 7 ++-- Termind/UI/Components/ManagedChooser.swift | 9 +++++ 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/Memory/REFACTOR.md b/Memory/REFACTOR.md index a3ef1f46..6cfada4c 100644 --- a/Memory/REFACTOR.md +++ b/Memory/REFACTOR.md @@ -784,3 +784,36 @@ behavior, and would conflict with this backlog's net-reduction and boundary-pres Final verification compiled the app and test targets with warnings as errors. All 63 focused tests passed across SFTP Feature/Session, Architecture Boundary, and Snippet Feature suites. The Simplified Chinese localization check and `git diff --check` also passed. + +## Re-verification Pass — 2026-09-02 + +An independent re-scan (fresh exact-fragment scan, dead-code scan, spot checks of completed items, and inspection of +every file touched since the Completion Audit) corroborated it: no dead code, no revived duplicates, and the +search-field-chrome/error-label claims held up on inspection. One item below the prior scan's granularity survived +independent review. + +### 45. Share the "select/deselect all visible" helper pair for `ManagedChooserState` — Low priority + +**Status:** Completed on 2026-09-02; build, `git diff --check`, and the Simplified Chinese localization check passed. + +**Evidence:** `SnippetsPageView.allResultsChecked`/`toggleAllResults()`, `HostChooserView.allResultsChecked`/ +`toggleAllResults()`, and `KeychainPageView.allEligibleChecked`/`toggleAllEligible()` each independently repeated +`!items.isEmpty && items.allSatisfy { chooser.selected.contains($0.id) }` and +`let ids = items.map(\.id); chooser.toggleAll(visible: ids, enabled: Set(ids))` — the common case where every visible +id is also enabled. The Completion Audit's note that "Host Chooser and Candidate Picker pass different enabled sets" +addressed a different, genuinely non-reusable case (`ModelListEditor`, which restricts `enabled` to a subset) and did +not cover this identical-enabled-set trio. + +**Recommended action:** Add `ManagedChooserState.allChecked(in:)` and `.toggleAll(in:)` convenience members beside the +existing general-purpose `toggleAll(visible:enabled:)`, and reuse them from all three call sites. Leave +`ModelListEditor`'s restricted-`enabled` call untouched. + +**Estimated net reduction:** Approximately 6–10 production lines. + +**Verification:** Added the two convenience members and reused them from Snippets, Host Chooser, and Keychain. +Production Swift changed by +15/−17 lines, for a net reduction of 2 lines; the estimate did not account for the +shared helper's own line cost. The macOS Debug build passed with warnings as errors, and `git diff --check` and the +Simplified Chinese localization check passed. + +No other new exact-duplicate or dead-code candidate meeting this backlog's net-reduction and boundary-preservation +bar was found in this pass. diff --git a/Termind/Features/HostChooser/HostChooserView.swift b/Termind/Features/HostChooser/HostChooserView.swift index beded63a..a47548a4 100644 --- a/Termind/Features/HostChooser/HostChooserView.swift +++ b/Termind/Features/HostChooser/HostChooserView.swift @@ -436,13 +436,10 @@ struct HostChooserView: View { // MARK: - Checking - private var allResultsChecked: Bool { - !results.isEmpty && results.allSatisfy { chooser.selected.contains($0.id) } - } + private var allResultsChecked: Bool { chooser.allChecked(in: results.map(\.id)) } private func toggleAllResults() { - let ids = results.map(\.id) - chooser.toggleAll(visible: ids, enabled: Set(ids)) + chooser.toggleAll(in: results.map(\.id)) } // MARK: - Opening diff --git a/Termind/Features/Keychain/KeychainPageView.swift b/Termind/Features/Keychain/KeychainPageView.swift index 8b67f922..1bb3e6d3 100644 --- a/Termind/Features/Keychain/KeychainPageView.swift +++ b/Termind/Features/Keychain/KeychainPageView.swift @@ -1332,11 +1332,7 @@ struct ExportKeyToHostsSheet: View { } } - private var allEligibleChecked: Bool { - !eligibleHosts.isEmpty && eligibleHosts.allSatisfy { - chooser.selected.contains($0.id) - } - } + private var allEligibleChecked: Bool { chooser.allChecked(in: eligibleHosts.map(\.id)) } private var keySummary: String { if keys.count == 1 { @@ -1359,8 +1355,7 @@ struct ExportKeyToHostsSheet: View { /// Select All follows the visible, filtered list, matching the host chooser: /// a filter must never cause an invisible machine to be modified. private func toggleAllEligible() { - let ids = eligibleHosts.map(\.id) - chooser.toggleAll(visible: ids, enabled: Set(ids)) + chooser.toggleAll(in: eligibleHosts.map(\.id)) } private func moveCursor(_ delta: Int) -> KeyPress.Result { diff --git a/Termind/Features/Snippets/SnippetsPageView.swift b/Termind/Features/Snippets/SnippetsPageView.swift index 3a13ed35..9f4d303c 100644 --- a/Termind/Features/Snippets/SnippetsPageView.swift +++ b/Termind/Features/Snippets/SnippetsPageView.swift @@ -859,13 +859,10 @@ private struct SnippetTargetPickerSheet: View { private var results: [Host] { app.snippets.searchHosts(query) } - private var allResultsChecked: Bool { - !results.isEmpty && results.allSatisfy { chooser.selected.contains($0.id) } - } + private var allResultsChecked: Bool { chooser.allChecked(in: results.map(\.id)) } private func toggleAllResults() { - let ids = results.map(\.id) - chooser.toggleAll(visible: ids, enabled: Set(ids)) + chooser.toggleAll(in: results.map(\.id)) } private func moveCursor(_ delta: Int) -> KeyPress.Result { diff --git a/Termind/UI/Components/ManagedChooser.swift b/Termind/UI/Components/ManagedChooser.swift index d0c85f92..dd955f0e 100644 --- a/Termind/UI/Components/ManagedChooser.swift +++ b/Termind/UI/Components/ManagedChooser.swift @@ -63,6 +63,15 @@ final class ManagedChooserState { } } + /// Convenience for the common case where every visible id is also enabled. + func allChecked(in ids: [ID]) -> Bool { + !ids.isEmpty && ids.allSatisfy(selected.contains) + } + + func toggleAll(in ids: [ID]) { + toggleAll(visible: ids, enabled: Set(ids)) + } + } struct SelectionMark: View {