@@ -272,57 +272,68 @@ class LegacyBookmarkDetailPanel: SiteTableViewController, BookmarksRefactorFeatu
272
272
273
273
var bookmarkFolders : [ ( folder: BookmarkFolderData , indent: Int ) ] = [ ]
274
274
275
- func addFolderAndDescendants( _ folder: BookmarkFolderData , indent: Int = 0 ) {
276
- // Do not append itself and the top "root" folder to this list as
277
- // bookmarks cannot be stored directly within it.
278
- if folder. guid != BookmarkRoots . RootGUID && folder. guid != self . bookmarkNodeGUID {
279
- bookmarkFolders. append ( ( folder, indent) )
280
- }
281
-
282
- var folderChildren : [ BookmarkNodeData ] ?
283
- // Suitable to be appended
284
- if folder. guid != self . bookmarkNodeGUID {
285
- folderChildren = folder. children
286
- }
287
-
288
- func addFolder( childFolder: BookmarkFolderData ) {
289
- // Any "root" folders (i.e. "Mobile Bookmarks") should
290
- // have an indentation of 0.
291
- if childFolder. isRoot {
292
- addFolderAndDescendants ( childFolder)
293
- }
294
- // Otherwise, all non-root folder should increase the
295
- // indentation by 1.
296
- else {
297
- addFolderAndDescendants ( childFolder, indent: indent + 1 )
298
- }
299
- }
300
-
301
- for case let childFolder as BookmarkFolderData in folderChildren ?? [ ] {
302
- // Only append desktop folders if they already contain bookmarks
303
- if !BookmarkRoots. DesktopRoots. contains ( childFolder. guid) {
304
- addFolder ( childFolder: childFolder)
305
- } else {
306
- switch bookmarksCountResult {
307
- case . success( let bookmarkCount) :
308
- if ( bookmarkCount > 0 && BookmarkRoots . DesktopRoots. contains ( childFolder. guid) )
309
- || !self . isBookmarkRefactorEnabled {
310
- addFolder ( childFolder: childFolder)
311
- }
312
- case . failure( let error) :
313
- self . logger. log ( " Error counting bookmarks: \( error) " , level: . debug, category: . library)
314
- }
315
- }
316
- }
317
- }
318
- addFolderAndDescendants ( rootFolder)
275
+ self . addFolderAndDescendants ( rootFolder,
276
+ bookmarkFolders: & bookmarkFolders,
277
+ bookmarksCountResult: bookmarksCountResult)
319
278
self . bookmarkFolders = bookmarkFolders
320
279
self . tableView. reloadData ( )
321
280
}
322
281
}
323
282
}
324
283
}
325
284
285
+ private func addFolderAndDescendants( _ folder: BookmarkFolderData ,
286
+ bookmarkFolders: inout [ ( folder: BookmarkFolderData , indent: Int ) ] ,
287
+ bookmarksCountResult: Result < Int , any Error > ,
288
+ indent: Int = 0 ) {
289
+ // Do not append itself and the top "root" folder to this list as
290
+ // bookmarks cannot be stored directly within it.
291
+ if folder. guid != BookmarkRoots . RootGUID && folder. guid != self . bookmarkNodeGUID {
292
+ bookmarkFolders. append ( ( folder, indent) )
293
+ }
294
+
295
+ var folderChildren : [ BookmarkNodeData ] ?
296
+ // Suitable to be appended
297
+ if folder. guid != self . bookmarkNodeGUID {
298
+ folderChildren = folder. children
299
+ }
300
+
301
+ func addFolder( childFolder: BookmarkFolderData ) {
302
+ // Any "root" folders (i.e. "Mobile Bookmarks") should
303
+ // have an indentation of 0.
304
+ if childFolder. isRoot {
305
+ addFolderAndDescendants ( childFolder,
306
+ bookmarkFolders: & bookmarkFolders,
307
+ bookmarksCountResult: bookmarksCountResult)
308
+ }
309
+ // Otherwise, all non-root folder should increase the
310
+ // indentation by 1.
311
+ else {
312
+ addFolderAndDescendants ( childFolder,
313
+ bookmarkFolders: & bookmarkFolders,
314
+ bookmarksCountResult: bookmarksCountResult,
315
+ indent: indent + 1 )
316
+ }
317
+ }
318
+
319
+ for case let childFolder as BookmarkFolderData in folderChildren ?? [ ] {
320
+ // Only append desktop folders if they already contain bookmarks
321
+ if !BookmarkRoots. DesktopRoots. contains ( childFolder. guid) {
322
+ addFolder ( childFolder: childFolder)
323
+ } else {
324
+ switch bookmarksCountResult {
325
+ case . success( let bookmarkCount) :
326
+ if ( bookmarkCount > 0 && BookmarkRoots . DesktopRoots. contains ( childFolder. guid) )
327
+ || !self . isBookmarkRefactorEnabled {
328
+ addFolder ( childFolder: childFolder)
329
+ }
330
+ case . failure( let error) :
331
+ logger. log ( " Error counting bookmarks: \( error) " , level: . debug, category: . library)
332
+ }
333
+ }
334
+ }
335
+ }
336
+
326
337
func updateSaveButton( ) {
327
338
guard bookmarkNodeType == . bookmark else { return }
328
339
0 commit comments