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:
Brent Simmons 2019-07-28 16:00:43 -07:00
parent 2441de960f
commit 887f8e0b53
2 changed files with 31 additions and 3 deletions

View File

@ -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()
// Dont 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)
}

View File

@ -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 hasnt actually changed,
// and therefore search shouldnt 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 {