Ensure starting glyph is valid at layout (fixes :set lines=9999 crash)
[MacVim/jjgod.git] / MMApplication.m
blob4aab703b13655c08a606f73acb90b412e63eb3fe
1 /* vi:set ts=8 sts=4 sw=4 ft=objc:
2  *
3  * VIM - Vi IMproved            by Bram Moolenaar
4  *                              MacVim GUI port by Bjorn Winckler
5  *
6  * Do ":help uganda"  in Vim to read copying and usage conditions.
7  * Do ":help credits" in Vim to see a list of people who contributed.
8  * See README.txt for an overview of the Vim source code.
9  */
11 #import "MMApplication.h"
13 // Ctrl-Tab is broken on pre 10.5, so we add a hack to make it work.
14 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
15 # import "MMTextView.h"
16 # define MM_CTRL_TAB_HACK 1
17 #endif
22 @implementation MMApplication
24 - (void)sendEvent:(NSEvent *)event
26     NSEventType type = [event type];
27     unsigned flags = [event modifierFlags];
29 #ifdef MM_CTRL_TAB_HACK
30     NSResponder *firstResponder = [[self keyWindow] firstResponder];
32     if (NSKeyDown == type && NSControlKeyMask & flags && 48 == [event keyCode]
33             && [firstResponder isKindOfClass:[MMTextView class]]) {
34         // HACK! This is a Ctrl-Tab key down event and the first responder is
35         // an MMTextView; send the event directly to the text view, else it
36         // will never receive it on pre 10.5 systems.
37         [firstResponder keyDown:event];
38         return;
39     }
40 #endif
42     // HACK! Intercept 'help' key presses and clear the 'help key flag', else
43     // Cocoa turns the mouse cursor into a question mark and goes into 'context
44     // help mode' (the keyDown: event itself never reaches the text view).  By
45     // clearing the 'help key flag' this event will be treated like a normal
46     // key event.
47     if ((NSKeyDown == type || NSKeyUp == type) && (flags & NSHelpKeyMask)) {
48         flags &= ~NSHelpKeyMask;
49         event = [NSEvent keyEventWithType:[event type]
50                                  location:[event locationInWindow]
51                             modifierFlags:flags
52                                 timestamp:[event timestamp]
53                              windowNumber:[event windowNumber]
54                                   context:[event context]
55                                characters:[event characters]
56               charactersIgnoringModifiers:[event charactersIgnoringModifiers]
57                                 isARepeat:[event isARepeat]
58                                   keyCode:[event keyCode]];
59     }
61     [super sendEvent:event];
64 @end