修订版 | 203 (tree) |
---|---|
时间 | 2022-07-23 20:26:39 |
作者 | toshinagata1964 |
Selection is restored after undoing insert/delete
@@ -706,6 +706,13 @@ | ||
706 | 706 | selectionQueue = nil; |
707 | 707 | } |
708 | 708 | |
709 | +/* Register undo for restoring current selection */ | |
710 | +- (void)registerUndoForRestoringCurrentSelectionInTrack: (int32_t)trackNo | |
711 | +{ | |
712 | + MDSelectionObject *oldSel = (MDSelectionObject *)[[[selections objectAtIndex: trackNo] retain] autorelease]; | |
713 | + [[[self undoManager] prepareWithInvocationTarget: self] | |
714 | + setSelection: oldSel inTrack: trackNo sender: self]; | |
715 | +} | |
709 | 716 | |
710 | 717 | #pragma mark ====== Posting notifications ====== |
711 | 718 |
@@ -1302,8 +1309,10 @@ | ||
1302 | 1309 | IntGroupClear(temp1); |
1303 | 1310 | sts = IntGroupConvolute([(MDSelectionObject *)[selections objectAtIndex: trackNo] pointSet], temp2, temp1); |
1304 | 1311 | } |
1305 | - if (sts == kMDNoError) | |
1312 | + if (sts == kMDNoError) { | |
1313 | + [self registerUndoForRestoringCurrentSelectionInTrack: trackNo]; | |
1306 | 1314 | [self setSelection: [[[MDSelectionObject allocWithZone: [self zone]] initWithMDPointSet: temp1] autorelease] inTrack: trackNo sender: self]; |
1315 | + } | |
1307 | 1316 | IntGroupRelease(temp1); |
1308 | 1317 | IntGroupRelease(temp2); |
1309 | 1318 |
@@ -1351,8 +1360,10 @@ | ||
1351 | 1360 | IntGroupClear(temp1); |
1352 | 1361 | sts = IntGroupDeconvolute([(MDSelectionObject *)[selections objectAtIndex: trackNo] pointSet], temp2, temp1); |
1353 | 1362 | } |
1354 | - if (sts == kMDNoError) | |
1363 | + if (sts == kMDNoError) { | |
1364 | + [self registerUndoForRestoringCurrentSelectionInTrack: trackNo]; | |
1355 | 1365 | [self setSelection: [[[MDSelectionObject allocWithZone: [self zone]] initWithMDPointSet: temp1] autorelease] inTrack: trackNo sender: self]; |
1366 | + } | |
1356 | 1367 | IntGroupRelease(temp1); |
1357 | 1368 | IntGroupRelease(temp2); |
1358 | 1369 |
@@ -1410,8 +1421,10 @@ | ||
1410 | 1421 | IntGroupClear(temp2); |
1411 | 1422 | sts = IntGroupConvolute(temp1, temp3, temp2); |
1412 | 1423 | } |
1413 | - if (sts == kMDNoError) | |
1424 | + if (sts == kMDNoError) { | |
1425 | + [self registerUndoForRestoringCurrentSelectionInTrack: trackNo]; | |
1414 | 1426 | [self setSelection: [[[MDSelectionObject allocWithZone: [self zone]] initWithMDPointSet: temp2] autorelease] inTrack: trackNo sender: self]; |
1427 | + } | |
1415 | 1428 | IntGroupRelease(temp1); |
1416 | 1429 | IntGroupRelease(temp2); |
1417 | 1430 | IntGroupRelease(temp3); |
@@ -1453,6 +1466,7 @@ | ||
1453 | 1466 | if (outPtr != NULL) |
1454 | 1467 | *outPtr = pset; |
1455 | 1468 | /* Update selection */ |
1469 | + [self registerUndoForRestoringCurrentSelectionInTrack: trackNo]; | |
1456 | 1470 | if (flag) { |
1457 | 1471 | [self setSelection: [[[MDSelectionObject allocWithZone: [self zone]] initWithMDPointSet: pset] autorelease] inTrack: trackNo sender: self]; |
1458 | 1472 | } else { |
@@ -1512,8 +1526,10 @@ | ||
1512 | 1526 | if (sts == kMDNoError) |
1513 | 1527 | sts = IntGroupDeconvolute([(MDSelectionObject *)[selections objectAtIndex: trackNo] pointSet], temp, newSelection); |
1514 | 1528 | } */ |
1515 | - if (sts == kMDNoError) | |
1529 | + if (sts == kMDNoError) { | |
1530 | + [self registerUndoForRestoringCurrentSelectionInTrack: trackNo]; | |
1516 | 1531 | [self setSelection: [[[MDSelectionObject allocWithZone: [self zone]] initWithMDPointSet: newSelection] autorelease] inTrack: trackNo sender: self]; |
1532 | + } | |
1517 | 1533 | trackObj = [[[MDTrackObject allocWithZone: [self zone]] initWithMDTrack: newTrack] autorelease]; |
1518 | 1534 | /* Register undo action for change of track duration (if necessary) */ |
1519 | 1535 | [self registerUndoChangeTrackDuration: oduration ofTrack: trackNo]; |
@@ -1792,6 +1808,7 @@ | ||
1792 | 1808 | |
1793 | 1809 | /* Set selection */ |
1794 | 1810 | if (setSelection) { |
1811 | + [doc registerUndoForRestoringCurrentSelectionInTrack: trackNo]; | |
1795 | 1812 | [doc setSelection: newDestPointSet inTrack: trackNo sender: doc]; |
1796 | 1813 | } |
1797 | 1814 |
@@ -2234,6 +2251,34 @@ | ||
2234 | 2251 | if (sts == kMDNoError) { |
2235 | 2252 | /* The position of the event after moving */ |
2236 | 2253 | npos = MDPointerGetPosition(pt1); |
2254 | + /* The selection after moving the event */ | |
2255 | + if (npos != position) { | |
2256 | + MDSelectionObject *newSet = [[[MDSelectionObject allocWithZone: [self zone]] init] autorelease]; | |
2257 | + MDSelectionObject *oldSet = (MDSelectionObject *)[[[selections objectAtIndex: trackNo] retain] autorelease]; | |
2258 | + IntGroup *newpset = [newSet pointSet]; | |
2259 | + IntGroup *oldpset = [oldSet pointSet]; | |
2260 | + IntGroupIterator iter; | |
2261 | + IntGroupIteratorInit(oldpset, &iter); | |
2262 | + int32_t pos; | |
2263 | + /* For each point in oldSet, add the new position */ | |
2264 | + while ((pos = IntGroupIteratorNext(&iter)) >= 0) { | |
2265 | + if (pos == position) | |
2266 | + IntGroupAdd(newpset, npos, 1); /* Add the new position */ | |
2267 | + else { | |
2268 | + if (position < npos) { | |
2269 | + if (pos > position && pos <= npos) | |
2270 | + pos--; /* Move one event backward */ | |
2271 | + } else { | |
2272 | + if (pos >= npos && pos < position) | |
2273 | + pos++; /* Move one event forward */ | |
2274 | + } | |
2275 | + IntGroupAdd(newpset, pos, 1); | |
2276 | + } | |
2277 | + } | |
2278 | + [[[self undoManager] prepareWithInvocationTarget: self] | |
2279 | + setSelection: oldSet inTrack: trackNo sender: self]; | |
2280 | + [self setSelection: newSet inTrack: trackNo sender: self]; | |
2281 | + } | |
2237 | 2282 | /* Register undo action with the current values */ |
2238 | 2283 | duration = MDTrackGetDuration(track); |
2239 | 2284 | if (oduration != duration) |