diff --git a/modules/gui/macosx/library/VLCLibraryWindowNavigationSidebarViewController.m b/modules/gui/macosx/library/VLCLibraryWindowNavigationSidebarViewController.m index 972b78ba76..666aea0972 100644 --- a/modules/gui/macosx/library/VLCLibraryWindowNavigationSidebarViewController.m +++ b/modules/gui/macosx/library/VLCLibraryWindowNavigationSidebarViewController.m @@ -403,4 +403,20 @@ static NSString * const VLCLibrarySegmentCellIdentifier = @"VLCLibrarySegmentCel return segment.segmentType == VLCLibraryHeaderSegmentType; } +- (BOOL)outlineView:(nonnull NSOutlineView *)outlineView shouldCollapseItem:(nonnull id)item +{ + NSAssert(outlineView == _outlineView, @"VLCLibraryWindowNavigationSidebarController should only be a delegate for the libraryWindow nav sidebar outline view!"); + + // Don't allow collapsing the parent segment of the selected segment, if selection is a child + NSTreeNode * const treeNode = (NSTreeNode *)item; + VLCLibrarySegment * const segment = (VLCLibrarySegment *)treeNode.representedObject; + NSTreeNode * const selectedSegmentItem = (NSTreeNode *)[self.outlineView itemAtRow:self.outlineView.selectedRow]; + VLCLibrarySegment * const selectedSegment = (VLCLibrarySegment *)selectedSegmentItem.representedObject; + const NSInteger childNodeIndex = [segment.childNodes indexOfObjectPassingTest:^BOOL(NSTreeNode * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + VLCLibrarySegment * const childSegment = (VLCLibrarySegment *)obj; + return childSegment.segmentType == selectedSegment.segmentType; + }]; + return childNodeIndex == NSNotFound; +} + @end