From 623ad2b1dcbadb664015e5bf597b476091fe0490 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Tue, 12 Nov 2019 14:02:35 +0100 Subject: [PATCH] Fixed: Previoulsly, clearsFilterPredicateOnInsertion was applied (removes filter predicate) when setting content or on content binding. (#2860) With Tests: Foundation unit test. Solves #2791 --- AppKit/CPArrayController.j | 11 +---------- Tests/AppKit/CPArrayControllerTest.j | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/AppKit/CPArrayController.j b/AppKit/CPArrayController.j index f4c676a9c..0201dcd0d 100644 --- a/AppKit/CPArrayController.j +++ b/AppKit/CPArrayController.j @@ -297,27 +297,18 @@ class. */ - if (_clearsFilterPredicateOnInsertion) - [self willChangeValueForKey:@"filterPredicate"]; - // Don't use [super setContent:] as that would fire the contentObject change. // We need to be in control of when notifications fire. // Note that if we have a contentArray binding, setting the content does /not/ // cause a reverse binding set. _contentObject = value; - if (_clearsFilterPredicateOnInsertion && _filterPredicate != nil) - [self __setFilterPredicate:nil]; // Causes a _rearrangeObjects. - else - [self _rearrangeObjects]; + [self _rearrangeObjects]; if ([self preservesSelection]) [self __setSelectedObjects:oldSelectedObjects]; else [self __setSelectionIndexes:oldSelectionIndexes]; - - if (_clearsFilterPredicateOnInsertion) - [self didChangeValueForKey:@"filterPredicate"]; } /*! diff --git a/Tests/AppKit/CPArrayControllerTest.j b/Tests/AppKit/CPArrayControllerTest.j index ca33da5b8..902863dfd 100644 --- a/Tests/AppKit/CPArrayControllerTest.j +++ b/Tests/AppKit/CPArrayControllerTest.j @@ -1020,6 +1020,26 @@ [self assertTrue:[[arrayController arrangedObjects] count] > 0]; } +- (void)testArrangedObjectsWhenSetContentAndClearsFilterOnInsertionIsTrue +{ + var arrayController = [[CPArrayController alloc] init]; + [arrayController setClearsFilterPredicateOnInsertion:YES]; + [arrayController setFilterPredicate:[CPPredicate predicateWithValue:NO]]; + [arrayController setContent:[CPArray arrayWithObject:@"a"]]; + + [self assertTrue:[[arrayController arrangedObjects] count] == 0]; +} + +- (void)testArrangedObjectsWhenBindingAndClearsFilterOnInsertionIsTrue +{ + var arrayController = [[CPArrayController alloc] init]; + [arrayController setClearsFilterPredicateOnInsertion:YES]; + [arrayController setFilterPredicate:[CPPredicate predicateWithValue:NO]]; + [arrayController bind:@"contentArray" toObject:self withKeyPath:@"_contentArray" options:nil]; + + [self assertTrue:[[arrayController arrangedObjects] count] == 0]; +} + - (void)testArrangedObjectsWithPredicateFilteringAfterContentArrayBinding { _contentArray = [self makeTestArray];