diff --git a/ChangeLog b/ChangeLog index 5dfa6a0eb..4bf985c49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-12-23 Wolfgang Lux + + * Source/NSUndoManager.m (_canCoalesceUndoWithTarget:selector:object): + Auxiliary method to support coalescing undo operations in + NSTextView. + 2009-12-22 17:15-EST Gregory John Casamento * Source/NSObject.m: Conditionally compile weak attribute for diff --git a/Source/NSUndoManager.m b/Source/NSUndoManager.m index 2c9436a1e..154d1f06e 100644 --- a/Source/NSUndoManager.m +++ b/Source/NSUndoManager.m @@ -1067,3 +1067,39 @@ @end +/* + * Category with auxiliary method to support coalescing undo actions + * for typing events in NSTextView. However, the implementation is + * not restricted to that purpose. + */ +@interface NSUndoManager(UndoCoalescing) +- (BOOL) _canCoalesceUndoWithTarget: (id)target + selector: (SEL)aSelector + object: (id)anObject; +@end + +@implementation NSUndoManager(UndoCoalescing) +- (BOOL) _canCoalesceUndoWithTarget: (id)target + selector: (SEL)aSelector + object: (id)anObject +{ + if (_isUndoing == NO && _isRedoing == NO && [_undoStack count] > 0) + { + int i; + NSArray *a = [[_undoStack lastObject] actions]; + + for (i = 0; i < [a count]; i++) + { + NSInvocation *inv = [a objectAtIndex: i]; + if ([inv target] == target && [inv selector] == aSelector) + { + id object; + [inv getArgument: &object atIndex: 2]; + if (object == anObject) + return YES; + } + } + } + return NO; +} +@end