Ivan Vučica avatar Ivan Vučica committed 6690587

Fixes for undoing indentation operations.

Comments (0)

Files changed (1)

OPML/OPMLDocument.m

 
 - (void)undoableRemovalOfNode:(OPMLOutlineXMLElement*)node
 {
+    NSLog(@"Undoable removal");
     [[self undoManager] beginUndoGrouping];
     //    [[[self undoManager] prepareWithInvocationTarget:[node parent]] insertChild:node atIndex:[node index]];
     [[[self undoManager] prepareWithInvocationTarget:self] undoableInsertionOfNode:node intoParent:(OPMLOutlineXMLElement*)[node parent] atIndex:[node index]];
 }
 - (void)undoableInsertionOfNode:(OPMLOutlineXMLElement*)node intoParent:(OPMLOutlineXMLElement*)parent atIndex:(NSInteger)index
 {
+    NSLog(@"Undoable insertion");
     [[self undoManager] beginUndoGrouping];
     [[[self undoManager] prepareWithInvocationTarget:self] undoableRemovalOfNode:node];
     [[[self undoManager] prepareWithInvocationTarget:self] setSelectedElement:[self selectedElement]];
 {
     OPMLOutlineXMLElement * selectedElement = [self selectedElement];
     OPMLOutlineXMLElement * parentElement = (OPMLOutlineXMLElement*)[selectedElement parent];
-    OPMLOutlineXMLElement * newParentElement = (OPMLOutlineXMLElement*)[parentElement childAtIndex:[selectedElement index]-1];
+    OPMLOutlineXMLElement * newParentElement = ([selectedElement index] > 0 && [selectedElement index] < [parentElement childCount]) ? (OPMLOutlineXMLElement*)[parentElement childAtIndex:[selectedElement index]-1] : nil;
     if(!selectedElement || !parentElement || !newParentElement)
     {
         NSBeep();
     
     [[self undoManager] beginUndoGrouping];
     [[self undoManager] setActionName:@"Increase Indent"];
-    [[[self undoManager] prepareWithInvocationTarget:selectedElement] retain];
-    [[[self undoManager] prepareWithInvocationTarget:parentElement] insertChild:selectedElement atIndex:originalIndex];
-    [[[self undoManager] prepareWithInvocationTarget:selectedElement] removeFromSupernode];
-    [[[self undoManager] prepareWithInvocationTarget:selectedElement] release];
     [[[self undoManager] prepareWithInvocationTarget:_outlineView] reloadData];
+    [[[self undoManager] prepareWithInvocationTarget:_outlineView] selectRowIndexes:[_outlineView selectedRowIndexes] byExtendingSelection:NO];
+    //[[[self undoManager] prepareWithInvocationTarget:parentElement] insertChild:selectedElement atIndex:originalIndex];
+    [[[self undoManager] prepareWithInvocationTarget:self] undoableInsertionOfNode:selectedElement intoParent:parentElement atIndex:originalIndex];
+    //[[[self undoManager] prepareWithInvocationTarget:selectedElement] removeFromSupernode];
+    [[[self undoManager] prepareWithInvocationTarget:self] undoableRemovalOfNode:selectedElement];
     [[self undoManager] endUndoGrouping];
     
     [selectedElement release];
     
-    NSIndexSet * selectedRowIndexes = [_outlineView selectedRowIndexes];
     [self applyCurrentExpansionState];
     [_outlineView reloadData];
     [self expandUsingExpansionState];
     [_outlineView expandItem:newParentElement];
+    
+    NSIndexSet * selectedRowIndexes =  [NSIndexSet indexSetWithIndex:[_outlineView rowForItem:selectedElement]];
     [_outlineView selectRowIndexes:selectedRowIndexes byExtendingSelection:NO];
 } // increaseIndent
 
     
     [[self undoManager] beginUndoGrouping];
     [[self undoManager] setActionName:@"Decrease Indent"];
-    [[[self undoManager] prepareWithInvocationTarget:selectedElement] retain];
-    [[[self undoManager] prepareWithInvocationTarget:parentElement] insertChild:selectedElement atIndex:originalIndex];
-    [[[self undoManager] prepareWithInvocationTarget:selectedElement] removeFromSupernode];
-    [[[self undoManager] prepareWithInvocationTarget:selectedElement] release];
     [[[self undoManager] prepareWithInvocationTarget:_outlineView] reloadData];
+    [[[self undoManager] prepareWithInvocationTarget:_outlineView] selectRowIndexes:[_outlineView selectedRowIndexes] byExtendingSelection:NO];
+    //[[[self undoManager] prepareWithInvocationTarget:parentElement] insertChild:selectedElement atIndex:originalIndex];
+    [[[self undoManager] prepareWithInvocationTarget:self] undoableInsertionOfNode:selectedElement intoParent:parentElement atIndex:originalIndex];
+    //[[[self undoManager] prepareWithInvocationTarget:selectedElement] removeFromSupernode];
+    [[[self undoManager] prepareWithInvocationTarget:self] undoableRemovalOfNode:selectedElement];
     [[self undoManager] endUndoGrouping];
     
     [selectedElement release];
     
-    NSIndexSet * selectedRowIndexes = [_outlineView selectedRowIndexes];
     [self applyCurrentExpansionState];
     [_outlineView reloadData];
     [self expandUsingExpansionState];
     [_outlineView expandItem:newParentElement];
+    
+    NSIndexSet * selectedRowIndexes =  [NSIndexSet indexSetWithIndex:[_outlineView rowForItem:selectedElement]];
     [_outlineView selectRowIndexes:selectedRowIndexes byExtendingSelection:NO];
 } // decreaseIndent
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.