[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>
This commit is contained in:
parent
8d231d34d4
commit
13fb6bb141
1 changed files with 17 additions and 0 deletions
|
@ -847,6 +847,23 @@ static void *playlistControllerContext = &playlistControllerContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)insertObjects:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes {
|
- (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]
|
[[[self undoManager] prepareWithInvocationTarget:self]
|
||||||
removeObjectsAtIndexes:[self disarrangeIndexes:indexes]];
|
removeObjectsAtIndexes:[self disarrangeIndexes:indexes]];
|
||||||
NSString *actionName =
|
NSString *actionName =
|
||||||
|
|
Loading…
Reference in a new issue