aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPEditSheetTextView.m4
-rw-r--r--Source/SPFieldEditorController.h1
-rw-r--r--Source/SPFieldEditorController.m54
3 files changed, 36 insertions, 23 deletions
diff --git a/Source/SPEditSheetTextView.m b/Source/SPEditSheetTextView.m
index 0ca61dcd..de2d2052 100644
--- a/Source/SPEditSheetTextView.m
+++ b/Source/SPEditSheetTextView.m
@@ -36,6 +36,7 @@
// an action will be recoreded which actually didn't change the
// text buffer. That's why repeat undo.
if(!textWasChanged) [[self undoManager] undo];
+ if(!textWasChanged) [[self undoManager] undo];
}
- (IBAction)redo:(id)sender
@@ -46,16 +47,19 @@
// an action will be recoreded which actually didn't change the
// text buffer. That's why repeat redo.
if(!textWasChanged) [[self undoManager] redo];
+ if(!textWasChanged) [[self undoManager] redo];
}
- (IBAction)paste:(id)sender
{
+ // Try to create an undo group
[[self delegate] setWasCutPaste];
[super paste:sender];
}
- (IBAction)cut:(id)sender
{
+ // Try to create an undo group
[[self delegate] setWasCutPaste];
[super cut:sender];
}
diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h
index 31ec6f44..262066a6 100644
--- a/Source/SPFieldEditorController.h
+++ b/Source/SPFieldEditorController.h
@@ -53,6 +53,7 @@
BOOL editTextViewWasChanged;
BOOL allowUndo;
BOOL wasCutPaste;
+ BOOL selectionChanged;
NSUserDefaults *prefs;
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m
index 2c9359b7..61a6635f 100644
--- a/Source/SPFieldEditorController.m
+++ b/Source/SPFieldEditorController.m
@@ -52,6 +52,7 @@
[editSheetOkButton setKeyEquivalentModifierMask:NSCommandKeyMask];
allowUndo = NO;
+ selectionChanged = NO;
}
return self;
@@ -211,25 +212,9 @@
// wait for editSheet
NSModalSession session = [NSApp beginModalSessionForWindow:editSheet];
int cycleCounter = 0;
+ BOOL doGroupDueToChars = NO;
for (;;) {
- // cycleCounter++;
-
- // Allow undo grouping if user typed a ' ' (for word level undo)
- // or a RETURN
- // if([[NSApp currentEvent] type] == NSKeyDown
- // && (
- // [[[NSApp currentEvent] charactersIgnoringModifiers] isEqualToString:@" "]
- // || [[NSApp currentEvent] keyCode] == 36
- // // || [[NSApp currentEvent] modifierFlags] & (NSCommandKeyMask|NSControlKeyMask|NSAlternateKeyMask)
- // )
- // )
- // cycleCounter=100;
-
- // After 5 run loops (fast writing forms longer blocks)
- // or the user typed a ' ' or RETURN and the textView was changed (allowUndo)
- // form an undo group
-
// Break the run loop if editSheet was closed
if ([NSApp runModalSession:session] != NSRunContinuesResponse
|| ![editSheet isVisible])
@@ -239,20 +224,34 @@
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
- if( (wasCutPaste || allowUndo) && ![esUndoManager isUndoing] && ![esUndoManager isRedoing] ) {
+ // Allow undo grouping if user typed a ' ' (for word level undo)
+ // or a RETURN but not for each char due to writing speed
+ if([[NSApp currentEvent] type] == NSKeyDown
+ && (
+ [[[NSApp currentEvent] charactersIgnoringModifiers] isEqualToString:@" "]
+ || [[NSApp currentEvent] keyCode] == 36
+ || [[NSApp currentEvent] modifierFlags] & (NSCommandKeyMask|NSControlKeyMask|NSAlternateKeyMask)
+ )) {
+ doGroupDueToChars=YES;
+ }
- cycleCounter = 0;
+ // If conditions match create an undo group
+ if( ( wasCutPaste || allowUndo || doGroupDueToChars ) && ![esUndoManager isUndoing] && ![esUndoManager isRedoing] ) {
allowUndo = NO;
wasCutPaste = NO;
+ doGroupDueToChars = NO;
+ selectionChanged = NO;
+
+ cycleCounter = 0;
while([esUndoManager groupingLevel] > 0) {
[esUndoManager endUndoGrouping];
cycleCounter++;
}
while([esUndoManager groupingLevel] < cycleCounter)
[esUndoManager beginUndoGrouping];
+
cycleCounter = 0;
-
}
}
@@ -768,8 +767,11 @@
{
// Do nothing if user really didn't changed text (e.g. for font size changing return)
- if(!editTextViewWasChanged && (editSheetWillBeInitialized || ([[[notification object] textStorage] changeInLength]==0)))
+ if(!editTextViewWasChanged && (editSheetWillBeInitialized || ([[[notification object] textStorage] changeInLength]==0))) {
+ // Inform the undo-grouping about the caret movement
+ selectionChanged = YES;
return;
+ }
// clear the image and hex (since i doubt someone can "type" a gif)
[editImage setImage:nil];
@@ -804,12 +806,18 @@
return NO;
}
-- (void)textDidChange:(NSNotification *)aNotification
+- (void)setAllowedUndo
{
- // Allow undo grouping only if the text buffer was really changed
allowUndo = YES;
}
+- (void)textDidChange:(NSNotification *)aNotification
+{
+ // Allow undo grouping only if the text buffer was really changed. Inform
+ // the run loop delayed for larger undo groups.
+ [self performSelector:@selector(setAllowedUndo) withObject:nil afterDelay:0.2];
+}
+
@end