From 04bad947e3815ed0f26244885f362304c0adfbe7 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Fri, 10 Jul 2026 16:14:29 +0200 Subject: [PATCH] fixed: CPRuleEditor: crash when dragging nested compound rows --- AppKit/CPRuleEditor/CPRuleEditor.j | 39 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/AppKit/CPRuleEditor/CPRuleEditor.j b/AppKit/CPRuleEditor/CPRuleEditor.j index b5e57c601..f3574db45 100644 --- a/AppKit/CPRuleEditor/CPRuleEditor.j +++ b/AppKit/CPRuleEditor/CPRuleEditor.j @@ -2342,33 +2342,41 @@ TODO: implement - (BOOL)performDragOperation:(id /*< CPDraggingInfo >*/)info { - var aboveInsertIndexCount = 0, - object, - removeIndex; + var object; var rowObjects = [_rowCache valueForKey:@"rowObject"], index = [_draggingRows lastIndex]; - var parentRowIndex = [self parentRowForRow:index], // first index of draggingrows + var firstDraggingIndex = [_draggingRows firstIndex], + parentRowIndex = [self parentRowForRow:firstDraggingIndex], parentRowObject = (parentRowIndex === -1) ? _boundArrayOwner : [[self _rowCacheForIndex:parentRowIndex] rowObject], insertIndex = _subviewIndexOfDropLine; while (index !== CPNotFound) { - if (index >= insertIndex) + // Identify if this row's parent is also inside the dragging set. + // If it is, we skip it because it will move automatically with its parent. + var parentOfCurrent = [self parentRowForRow:index]; + if (parentOfCurrent !== -1 && [_draggingRows containsIndex:parentOfCurrent]) { - removeIndex = index + aboveInsertIndexCount; - aboveInsertIndexCount += 1; - } - else - { - removeIndex = index; - insertIndex -= 1; + index = [_draggingRows indexLessThanIndex:index]; + continue; } - object = [rowObjects objectAtIndex:removeIndex]; - [self removeRowAtIndex:removeIndex]; - [[self _subrowObjectsOfObject:parentRowObject] insertObject:object atIndex:insertIndex - parentRowIndex - 1]; + object = [rowObjects objectAtIndex:index]; + + // Find the current live index of the object inside the editor + var cache = [self _searchCacheForRowObject:object]; + var liveIndex = [_rowCache indexOfObjectIdenticalTo:cache]; + + if (liveIndex !== CPNotFound) + { + if (liveIndex < insertIndex) + insertIndex -= 1; + + [self removeRowAtIndex:liveIndex]; + [[self _subrowObjectsOfObject:parentRowObject] insertObject:object atIndex:insertIndex - parentRowIndex - 1]; + } index = [_draggingRows indexLessThanIndex:index]; } @@ -2378,6 +2386,7 @@ TODO: implement return YES; } + - (CPIndexSet)_draggingTypes { return [CPIndexSet indexSetWithIndex:CPDragOperationMove];