From 6aeca470b5d4d375ef268c8233324a8919bb69e0 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sun, 9 Aug 2009 02:28:28 +0200 Subject: [PATCH] Don't remember IM source if ASCII This fixes a bug where the IM source would be forgotten whenever command line mode was entered (with 'noimd' set). --- src/MacVim/MMTextViewHelper.m | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index 4e1da99b93..f008dfc16e 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -47,6 +47,22 @@ static float MMDragAreaSize = 73.0f; + static BOOL +KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) +{ + // Define two sources to be equal iff both are non-NULL and they have + // identical source ID strings. + + if (!(a && b)) + return NO; + + NSString *as = TISGetInputSourceProperty(a, kTISPropertyInputSourceID); + NSString *bs = TISGetInputSourceProperty(b, kTISPropertyInputSourceID); + + return [as isEqualToString:bs]; +} + + @implementation MMTextViewHelper - (void)dealloc @@ -760,10 +776,21 @@ static float MMDragAreaSize = 73.0f; // IM was last off. ref = asciiImSource; - // Remember current input source so we can switch back to it when - // IM is once more enabled. - if (lastImSource) CFRelease(lastImSource); - lastImSource = TISCopyCurrentKeyboardInputSource(); + TISInputSourceRef cur = TISCopyCurrentKeyboardInputSource(); + if (!KeyboardInputSourcesEqual(asciiImSource, cur)) { + // Remember current input source so we can switch back to it + // when IM is once more enabled. Note that Vim will call this + // method with "enable=NO" even when the ASCII input source is + // in use which is why we only remember the current input + // source unless it is the ASCII source. + ASLogDebug(@"Remember last input source: %@", + TISGetInputSourceProperty(cur, kTISPropertyInputSourceID)); + if (lastImSource) CFRelease(lastImSource); + lastImSource = cur; + } else { + CFRelease(cur); + cur = NULL; + } } if (ref) {