Merge branch 'mac-candidate'

This commit is contained in:
Brent Simmons 2019-07-28 16:01:12 -07:00
commit 34326863ea
2 changed files with 31 additions and 3 deletions

View File

@ -381,9 +381,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
extension MainWindowController: SidebarDelegate { extension MainWindowController: SidebarDelegate {
func sidebarSelectionDidChange(_: SidebarViewController, selectedObjects: [AnyObject]?) { func sidebarSelectionDidChange(_: SidebarViewController, selectedObjects: [AnyObject]?) {
// TODO: if searching, cancel search // Dont update the timeline if it already has those objects.
timelineContainerViewController?.setRepresentedObjects(selectedObjects, mode: .regular) let representedObjectsAreTheSame = timelineContainerViewController?.regularTimelineViewControllerHasRepresentedObjects(selectedObjects) ?? false
forceSearchToEnd() if !representedObjectsAreTheSame {
timelineContainerViewController?.setRepresentedObjects(selectedObjects, mode: .regular)
forceSearchToEnd()
}
updateWindowTitle() updateWindowTitle()
NotificationCenter.default.post(name: .InspectableObjectsDidChange, object: nil) NotificationCenter.default.post(name: .InspectableObjectsDidChange, object: nil)
} }

View File

@ -54,6 +54,31 @@ final class TimelineContainerViewController: NSViewController {
func showTimeline(for mode: TimelineSourceMode) { func showTimeline(for mode: TimelineSourceMode) {
currentTimelineViewController = timelineViewController(for: mode) 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 { extension TimelineContainerViewController: TimelineDelegate {