From 3292e01a824d6a7d52c68ae5daf9101ef7d962ee Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Wed, 19 Mar 2008 19:56:19 +0100 Subject: [PATCH] Improve behaviour With this patch works as follows: - if in Ex-mode, exit by sending "^U:vi" - if the command-line window is open, close it using CTRL-\_CTRL-N - otherwise go to normal mode and add ":q" to the input buffer --- src/MacVim/MMBackend.m | 18 ++++++++++++++++++ src/MacVim/MMWindowController.m | 8 +++----- src/MacVim/MacVim.h | 1 + src/MacVim/MacVim.m | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 95165cd1f3..3f1fa06850 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1648,6 +1648,24 @@ static NSString *MMSymlinkWarningString = [self handleOdbEdit:data]; } else if (XcodeModMsgID == msgid) { [self handleXcodeMod:data]; + } else if (CloseMsgID == msgid) { + // If in Ex mode, then simply exit Ex mode (^U:vi). Otherwise + // try to close one (Vim-)window by going to Normal mode first + // (CTRL-\_CTRL-N) and then sending ":q", but only if the + // command-line window is not open. If the command-line window is open + // then we just go back to normal mode (since CTRL-\_CTRL-N closes the + // command-line window). + if (exmode_active) { + // Exit Ex mode + add_to_input_buf((char_u*)"\x15:vi\n", 5); + } else { + // Go to normal mode + add_to_input_buf((char_u*)"\x1c\xe", 2); + if (0 == cmdwin_type) { + // Command-line window was not open, so :q + add_to_input_buf((char_u*)":q\n", 3); + } + } } else { NSLog(@"WARNING: Unknown message received (msgid=%d)", msgid); } diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index 88b966894b..3451b67e70 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -593,11 +593,9 @@ - (IBAction)performClose:(id)sender { - // NOTE: File->Close is bound to this action message instead binding it - // directly to the below vim input so that File->Close also works for - // auxiliary windows such as the About dialog. (If we were to bind the - // below, then will not close e.g. the About dialog.) - [vimController addVimInput:@":conf q"]; + // NOTE: File->Close is bound to this action message so that File->Close + // also works for auxiliary windows such as the About dialog. + [vimController sendMessage:CloseMsgID data:nil]; } - (IBAction)findNext:(id)sender diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index d85e66b9ff..f824014f3a 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -162,6 +162,7 @@ enum { LiveResizeMsgID, EnableAntialiasMsgID, DisableAntialiasMsgID, + CloseMsgID, }; diff --git a/src/MacVim/MacVim.m b/src/MacVim/MacVim.m index c7ce9687f9..a2edd6cf0d 100644 --- a/src/MacVim/MacVim.m +++ b/src/MacVim/MacVim.m @@ -75,6 +75,7 @@ char *MessageStrings[] = "LiveResizeMsgID", "EnableAntialiasMsgID", "DisableAntialiasMsgID", + "CloseMsgID", };