From ad6fe811e71bfd5e8c2f2b15071659dd01f31fbc Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sat, 13 Sep 2008 02:48:57 +0200 Subject: [PATCH] Check for Ctrl-C when gui_mch_update() is called Since gui_mch_update() is called so frequently we only check for interrupts at most once per second. --- src/MacVim/MMBackend.m | 30 ++++++++++++++++++------------ src/MacVim/gui_macvim.m | 17 +++++++++++++---- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 13ff066638..6ee4e4091c 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -466,6 +466,10 @@ static NSString *MMSymlinkWarningString = - (void)update { + // Keep running the run-loop until there is no more input to process. + while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) + == kCFRunLoopRunHandledSource) + ; } - (void)flushQueue:(BOOL)force @@ -1034,6 +1038,20 @@ static NSString *MMSymlinkWarningString = - (oneway void)processInput:(int)msgid data:(in bycopy NSData *)data { + // Look for Ctrl-C immediately instead of waiting until the input queue is + // processed since that only happens in waitForInput: (and Vim regularly + // checks for Ctrl-C in between waiting for input). + + if (InsertTextMsgID == msgid && data != nil && [data length] == 1) { + char_u *str = (char_u*)[data bytes]; + if ((str[0] == Ctrl_C && ctrl_c_interrupts) || + (str[0] == intr_char && intr_char != Ctrl_C)) { + got_int = TRUE; + [inputQueue removeAllObjects]; + return; + } + } + // Remove all previous instances of this message from the input queue, else // the input queue may fill up as a result of Vim not being able to keep up // with the speed at which new messages are received. This avoids annoying @@ -1737,12 +1755,6 @@ static NSString *MMSymlinkWarningString = } #endif - if (len == 1 && ((str[0] == Ctrl_C && ctrl_c_interrupts) - || (str[0] == intr_char && intr_char != Ctrl_C))) { - trash_input_buf(); - got_int = TRUE; - } - for (i = 0; i < len; ++i) { add_to_input_buf(str+i, 1); if (CSI == str[i]) { @@ -1831,12 +1843,6 @@ static NSString *MMSymlinkWarningString = //NSLog(@"non-special: %@ (hex=%x, mods=%d)", key, // [key characterAtIndex:0], mods); - if (length == 1 && ((c == Ctrl_C && ctrl_c_interrupts) - || (c == intr_char && intr_char != Ctrl_C))) { - trash_input_buf(); - got_int = TRUE; - } - // HACK! In most circumstances the Ctrl and Shift modifiers should be // cleared since they are already added to the key by the AppKit. // Unfortunately, the only way to deal with when to clear the modifiers diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 39880d83bb..1727e9752c 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -184,10 +184,19 @@ gui_mch_open(void) void gui_mch_update(void) { - // This function is called extremely often. By doing nothing here the - // frame-rate is increased dramatically in certain situations. However, - // the downside is that it is often not possible to interrupt Vim with - // Ctrl-C when it is busy processing. + // This function is called extremely often. It is tempting to do nothing + // here to avoid reduced frame-rates but then it would not be possible to + // interrupt Vim by presssing Ctrl-C during lengthy operations (e.g. after + // entering "10gs" it would not be possible to bring Vim out of the 10 s + // sleep prematurely). As a compromise we check for Ctrl-C only once per + // second. + static CFAbsoluteTime lastTime = 0; + + CFAbsoluteTime nowTime = CFAbsoluteTimeGetCurrent(); + if (nowTime - lastTime > 1.0) { + [[MMBackend sharedInstance] update]; + lastTime = nowTime; + } }