• R/O
  • SSH
  • HTTPS

alchemusica: 提交


Commit MetaInfo

修订版203 (tree)
时间2022-07-23 20:26:39
作者toshinagata1964

Log Message

Selection is restored after undoing insert/delete

更改概述

差异

--- trunk/Classes/MyDocument.m (revision 202)
+++ trunk/Classes/MyDocument.m (revision 203)
@@ -706,6 +706,13 @@
706706 selectionQueue = nil;
707707 }
708708
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+}
709716
710717 #pragma mark ====== Posting notifications ======
711718
@@ -1302,8 +1309,10 @@
13021309 IntGroupClear(temp1);
13031310 sts = IntGroupConvolute([(MDSelectionObject *)[selections objectAtIndex: trackNo] pointSet], temp2, temp1);
13041311 }
1305- if (sts == kMDNoError)
1312+ if (sts == kMDNoError) {
1313+ [self registerUndoForRestoringCurrentSelectionInTrack: trackNo];
13061314 [self setSelection: [[[MDSelectionObject allocWithZone: [self zone]] initWithMDPointSet: temp1] autorelease] inTrack: trackNo sender: self];
1315+ }
13071316 IntGroupRelease(temp1);
13081317 IntGroupRelease(temp2);
13091318
@@ -1351,8 +1360,10 @@
13511360 IntGroupClear(temp1);
13521361 sts = IntGroupDeconvolute([(MDSelectionObject *)[selections objectAtIndex: trackNo] pointSet], temp2, temp1);
13531362 }
1354- if (sts == kMDNoError)
1363+ if (sts == kMDNoError) {
1364+ [self registerUndoForRestoringCurrentSelectionInTrack: trackNo];
13551365 [self setSelection: [[[MDSelectionObject allocWithZone: [self zone]] initWithMDPointSet: temp1] autorelease] inTrack: trackNo sender: self];
1366+ }
13561367 IntGroupRelease(temp1);
13571368 IntGroupRelease(temp2);
13581369
@@ -1410,8 +1421,10 @@
14101421 IntGroupClear(temp2);
14111422 sts = IntGroupConvolute(temp1, temp3, temp2);
14121423 }
1413- if (sts == kMDNoError)
1424+ if (sts == kMDNoError) {
1425+ [self registerUndoForRestoringCurrentSelectionInTrack: trackNo];
14141426 [self setSelection: [[[MDSelectionObject allocWithZone: [self zone]] initWithMDPointSet: temp2] autorelease] inTrack: trackNo sender: self];
1427+ }
14151428 IntGroupRelease(temp1);
14161429 IntGroupRelease(temp2);
14171430 IntGroupRelease(temp3);
@@ -1453,6 +1466,7 @@
14531466 if (outPtr != NULL)
14541467 *outPtr = pset;
14551468 /* Update selection */
1469+ [self registerUndoForRestoringCurrentSelectionInTrack: trackNo];
14561470 if (flag) {
14571471 [self setSelection: [[[MDSelectionObject allocWithZone: [self zone]] initWithMDPointSet: pset] autorelease] inTrack: trackNo sender: self];
14581472 } else {
@@ -1512,8 +1526,10 @@
15121526 if (sts == kMDNoError)
15131527 sts = IntGroupDeconvolute([(MDSelectionObject *)[selections objectAtIndex: trackNo] pointSet], temp, newSelection);
15141528 } */
1515- if (sts == kMDNoError)
1529+ if (sts == kMDNoError) {
1530+ [self registerUndoForRestoringCurrentSelectionInTrack: trackNo];
15161531 [self setSelection: [[[MDSelectionObject allocWithZone: [self zone]] initWithMDPointSet: newSelection] autorelease] inTrack: trackNo sender: self];
1532+ }
15171533 trackObj = [[[MDTrackObject allocWithZone: [self zone]] initWithMDTrack: newTrack] autorelease];
15181534 /* Register undo action for change of track duration (if necessary) */
15191535 [self registerUndoChangeTrackDuration: oduration ofTrack: trackNo];
@@ -1792,6 +1808,7 @@
17921808
17931809 /* Set selection */
17941810 if (setSelection) {
1811+ [doc registerUndoForRestoringCurrentSelectionInTrack: trackNo];
17951812 [doc setSelection: newDestPointSet inTrack: trackNo sender: doc];
17961813 }
17971814
@@ -2234,6 +2251,34 @@
22342251 if (sts == kMDNoError) {
22352252 /* The position of the event after moving */
22362253 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+ }
22372282 /* Register undo action with the current values */
22382283 duration = MDTrackGetDuration(track);
22392284 if (oduration != duration)
Show on old repository browser