From f4674b3f74d01ac18cf3a6d388788d68e05bd582 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 25 Jul 2026 15:24:28 -0700 Subject: [PATCH] Select new account in accounts list on adding an account. --- .../AccountsPreferencesViewController.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift index be35e7006..569beeaaf 100644 --- a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift +++ b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift @@ -94,7 +94,11 @@ final class AccountsPreferencesViewController: NSViewController { } @objc func accountsDidChange(_ note: Notification) { - reloadTablePreservingSelection() + if note.name == .UserDidAddAccount, let addedAccount = note.userInfo?[Account.UserInfoKey.account] as? Account { + reloadTable(selecting: addedAccount) + } else { + reloadTablePreservingSelection() + } } @objc func handleAccountRefreshStateChanged(_ note: Notification) { @@ -236,10 +240,13 @@ private extension AccountsPreferencesViewController { } func reloadTablePreservingSelection() { - let selectedAccountBeforeReload = selectedAccount + reloadTable(selecting: selectedAccount) + } + + func reloadTable(selecting accountToSelect: Account?) { updateSortedAccounts() tableView.reloadData() - if let selectedAccountBeforeReload, let row = sortedAccounts.firstIndex(of: selectedAccountBeforeReload) { + if let accountToSelect, let row = sortedAccounts.firstIndex(of: accountToSelect) { tableView.selectRowIndexes(IndexSet(integer: row), byExtendingSelection: false) } updateDeleteButtonState()