mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-30 03:20:37 +01:00
Check to see if the timeline already has the expected representedObjects when the sidebar selection (apparently) has changed. If so, then don’t set the representedObjects again, and don’t knock the user out of search mode if searching.
This commit is contained in:
parent
2441de960f
commit
887f8e0b53
@ -381,9 +381,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
extension MainWindowController: SidebarDelegate {
|
||||
|
||||
func sidebarSelectionDidChange(_: SidebarViewController, selectedObjects: [AnyObject]?) {
|
||||
// TODO: if searching, cancel search
|
||||
timelineContainerViewController?.setRepresentedObjects(selectedObjects, mode: .regular)
|
||||
forceSearchToEnd()
|
||||
// Don’t update the timeline if it already has those objects.
|
||||
let representedObjectsAreTheSame = timelineContainerViewController?.regularTimelineViewControllerHasRepresentedObjects(selectedObjects) ?? false
|
||||
if !representedObjectsAreTheSame {
|
||||
timelineContainerViewController?.setRepresentedObjects(selectedObjects, mode: .regular)
|
||||
forceSearchToEnd()
|
||||
}
|
||||
updateWindowTitle()
|
||||
NotificationCenter.default.post(name: .InspectableObjectsDidChange, object: nil)
|
||||
}
|
||||
|
@ -54,6 +54,31 @@ final class TimelineContainerViewController: NSViewController {
|
||||
func showTimeline(for mode: TimelineSourceMode) {
|
||||
currentTimelineViewController = timelineViewController(for: mode)
|
||||
}
|
||||
|
||||
func regularTimelineViewControllerHasRepresentedObjects(_ representedObjects: [AnyObject]?) -> Bool {
|
||||
// Use this to find out if the regular timeline view already has the specified representedObjects.
|
||||
// This is used in determining whether a search should end.
|
||||
// The sidebar may think that the selection has changed, and therefore search should end —
|
||||
// but it could be that the regular timeline already has these representedObjects,
|
||||
// and therefore the selection hasn’t actually changed,
|
||||
// and therefore search shouldn’t end.
|
||||
// https://github.com/brentsimmons/NetNewsWire/issues/791
|
||||
if representedObjects == nil && regularTimelineViewController.representedObjects == nil {
|
||||
return true
|
||||
}
|
||||
guard let currentObjects = regularTimelineViewController.representedObjects, let representedObjects = representedObjects else {
|
||||
return false
|
||||
}
|
||||
if currentObjects.count != representedObjects.count {
|
||||
return false
|
||||
}
|
||||
for object in representedObjects {
|
||||
guard let _ = currentObjects.firstIndex(where: { $0 === object } ) else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension TimelineContainerViewController: TimelineDelegate {
|
||||
|
Loading…
Reference in New Issue
Block a user