File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import SwiftUI
1111internal struct FavoritesTabView : View {
1212 @State private var viewModel : FavoritesSidebarViewModel
1313 @State private var selectedFavoriteIds : Set < String > = [ ]
14+ @State private var lastInsertedFavoriteId : String ?
1415 @State private var folderToDelete : SQLFavoriteFolder ?
1516 @State private var showDeleteFolderAlert = false
1617 @FocusState private var isRenameFocused : Bool
@@ -79,6 +80,24 @@ internal struct FavoritesTabView: View {
7980 . onDeleteCommand {
8081 deleteSelectedFavorites ( )
8182 }
83+ . onChange ( of: selectedFavoriteIds) { oldIds, newIds in
84+ if newIds. isEmpty {
85+ lastInsertedFavoriteId = nil
86+ return
87+ }
88+
89+ let added = newIds. subtracting ( oldIds)
90+ guard added. count == 1 ,
91+ newIds. count == 1 ,
92+ let selectedId = added. first,
93+ selectedId != lastInsertedFavoriteId else { return }
94+
95+ let allFavorites = collectFavorites ( from: viewModel. filteredItems ( searchText: searchText) )
96+ if let favorite = allFavorites. first ( where: { " fav- \( $0. id) " == selectedId } ) {
97+ coordinator? . insertFavorite ( favorite)
98+ lastInsertedFavoriteId = selectedId
99+ }
100+ }
82101 }
83102
84103 /// Renders tree items with DisclosureGroup for folders.
You can’t perform that action at this time.
0 commit comments