Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #736: When selecting a tab, deselect other ones. (#4432)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub authored Nov 2, 2021
1 parent 4451fa2 commit af10b16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Client/Frontend/Browser/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ class TabManager: NSObject {
log.error("Expected tab (\(String(describing: tab?.url))) is not selected. Selected index: \(selectedIndex)")
return
}

if let tabId = tab?.id {
TabMO.selectTabAndDeselectOthers(selectedTabId: tabId)
}

UIImpactFeedbackGenerator(style: .light).bzzt()
selectedTab?.createWebview()
Expand Down
14 changes: 14 additions & 0 deletions Data/models/TabMO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ public final class TabMO: NSManagedObject, CRUD {
}

}

public class func selectTabAndDeselectOthers(selectedTabId: String) {
DataController.perform { context in
guard let tabToUpdate = getInternal(fromId: selectedTabId, context: context) else { return }

let predicate = NSPredicate(format: "isSelected == true")
all(where: predicate, context: context)?
.forEach {
$0.isSelected = false
}

tabToUpdate.isSelected = true
}
}

// Deletes the Tab History by removing items except the last one from historysnapshot and setting current index
public class func removeHistory(with tabID: String) {
Expand Down

0 comments on commit af10b16

Please sign in to comment.