aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFieldEditorController.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-08-14 16:04:24 +0000
committerBibiko <bibiko@eva.mpg.de>2009-08-14 16:04:24 +0000
commit8f2a7c3ba9db6481e36f69f66e542842aba9f02a (patch)
tree348a3f8a7f7132a5c44f9fed6aeb9f0f36a98314 /Source/SPFieldEditorController.m
parentdb7399d810986569ba54ff5c83ea9c066112a33d (diff)
downloadsequelpro-8f2a7c3ba9db6481e36f69f66e542842aba9f02a.tar.gz
sequelpro-8f2a7c3ba9db6481e36f69f66e542842aba9f02a.tar.bz2
sequelpro-8f2a7c3ba9db6481e36f69f66e542842aba9f02a.zip
• further improvement to SPFieldEditor's undo manager
- try to trap the speed of typing better to create larger undo groups
Diffstat (limited to 'Source/SPFieldEditorController.m')
-rw-r--r--Source/SPFieldEditorController.m54
1 files changed, 31 insertions, 23 deletions
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