[Playlist Insert] Add a special case for filtered
Insertions which occur when the playlist is filtered can try to add past the end of the playlist. Let's try to dodge that. Signed-off-by: Christopher Snowhill <kode54@gmail.com>xcode15
parent
8c0abf5fab
commit
5238965534
|
@ -847,6 +847,23 @@ static void *playlistControllerContext = &playlistControllerContext;
|
|||
}
|
||||
|
||||
- (void)insertObjects:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes {
|
||||
// Special case, somehow someone is undoing while a search filter is in place
|
||||
__block NSUInteger index = NSNotFound;
|
||||
[indexes enumerateRangesUsingBlock:^(NSRange range, BOOL * _Nonnull stop) {
|
||||
if(range.location < index) {
|
||||
index = range.location;
|
||||
}
|
||||
}];
|
||||
NSUInteger count = [[self content] count];
|
||||
if(index > count) {
|
||||
// Ah, oops, bodge fix
|
||||
__block NSMutableIndexSet *replacementIndexes = [[NSMutableIndexSet alloc] init];
|
||||
[indexes enumerateRangesUsingBlock:^(NSRange range, BOOL * _Nonnull stop) {
|
||||
[replacementIndexes addIndexesInRange:NSMakeRange(range.location - index + count, range.length)];
|
||||
}];
|
||||
indexes = replacementIndexes;
|
||||
}
|
||||
|
||||
[[[self undoManager] prepareWithInvocationTarget:self]
|
||||
removeObjectsAtIndexes:[self disarrangeIndexes:indexes]];
|
||||
NSString *actionName =
|
||||
|
|
Loading…
Reference in New Issue