Skip to content

Commit

Permalink
Add support for DefaultKeyBindings.dict, based on patch in issue 1630…
Browse files Browse the repository at this point in the history
… by JTheAppleSeed
  • Loading branch information
gnachman committed Dec 9, 2013
1 parent 00da097 commit 5da3dae
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 12 deletions.
1 change: 0 additions & 1 deletion PTYTextView.h
Expand Up @@ -628,7 +628,6 @@ enum {
- (NSRange)selectedRange;
- (NSArray *)validAttributesForMarkedText;
- (NSAttributedString *)attributedSubstringFromRange:(NSRange)theRange;
- (void)doCommandBySelector:(SEL)aSelector;
- (unsigned int)characterIndexForPoint:(NSPoint)thePoint;
- (long)conversationIdentifier;
- (NSRect)firstRectForCharacterRange:(NSRange)theRange;
Expand Down
26 changes: 15 additions & 11 deletions PTYTextView.m
Expand Up @@ -29,7 +29,6 @@

#define DEBUG_ALLOC 0
#define DEBUG_METHOD_TRACE 0
#define GREED_KEYDOWN 1
static const int MAX_WORKING_DIR_COUNT = 50;
static const int kMaxSelectedTextLengthForCustomActions = 8192;
static const int kMaxSelectedTextLinesForCustomActions = 100;
Expand Down Expand Up @@ -73,6 +72,7 @@
#import "iTermApplicationDelegate.h"
#import "iTermController.h"
#import "iTermExpose.h"
#import "iTermNSKeyBindingEmulator.h"
#include <math.h>
#include <sys/time.h>

Expand Down Expand Up @@ -257,6 +257,8 @@ + (void)initialize
gSmartCursorFgThreshold = d;
}
}

[iTermNSKeyBindingEmulator sharedInstance]; // Load and parse DefaultKeyBindings.dict if needed.
}

- (BOOL)xtermMouseReporting
Expand Down Expand Up @@ -2686,6 +2688,12 @@ - (void)keyDown:(NSEvent*)event

// Hide the cursor
[NSCursor setHiddenUntilMouseMoves:YES];

if ([[iTermNSKeyBindingEmulator sharedInstance] handlesEvent:event]) {
DLog(@"iTermNSKeyBindingEmulator reports that event is handled, sending to interpretKeyEvents.");
[self interpretKeyEvents:@[ event ]];
return;
}

// Should we process the event immediately in the delegate?
if ((!prev) &&
Expand Down Expand Up @@ -5514,18 +5522,14 @@ - (void)printContent:(NSString *)aString
[tempView release];
}

/// NSTextInput stuff
#pragma mark - NSTextInput

- (void)doCommandBySelector:(SEL)aSelector
{
//NSLog(@"doCommandBySelector:%@", NSStringFromSelector(aSelector));

#if GREED_KEYDOWN == 0
id delegate = [self delegate];

if ([delegate respondsToSelector:aSelector]) {
[delegate performSelector:aSelector withObject:nil];
}
#endif
// doCommandBySelector isn't safe for us to implement blindly. For example, the standard
// key bindings make Enter send insertNewline:, which does the wrong thing when called on our
// delegate (it sends 0xa instead of 0xd). TODO: Find a list of useful selectors that could be
// whitelisted here.
}

- (void)insertText:(id)aString
Expand Down
10 changes: 10 additions & 0 deletions iTerm.xcodeproj/project.pbxproj
Expand Up @@ -569,6 +569,9 @@
A60014F618550F3900CE38D8 /* NSMutableAttributedString+iTerm.h in Headers */ = {isa = PBXBuildFile; fileRef = A60014F418550F3900CE38D8 /* NSMutableAttributedString+iTerm.h */; };
A60014F718550F3900CE38D8 /* NSMutableAttributedString+iTerm.m in Sources */ = {isa = PBXBuildFile; fileRef = A60014F518550F3900CE38D8 /* NSMutableAttributedString+iTerm.m */; };
A60014F818550F3900CE38D8 /* NSMutableAttributedString+iTerm.m in Sources */ = {isa = PBXBuildFile; fileRef = A60014F518550F3900CE38D8 /* NSMutableAttributedString+iTerm.m */; };
A60014FB18552BDF00CE38D8 /* iTermNSKeyBindingEmulator.h in Headers */ = {isa = PBXBuildFile; fileRef = A60014F918552BDF00CE38D8 /* iTermNSKeyBindingEmulator.h */; };
A60014FC18552BDF00CE38D8 /* iTermNSKeyBindingEmulator.m in Sources */ = {isa = PBXBuildFile; fileRef = A60014FA18552BDF00CE38D8 /* iTermNSKeyBindingEmulator.m */; };
A60014FD18552BDF00CE38D8 /* iTermNSKeyBindingEmulator.m in Sources */ = {isa = PBXBuildFile; fileRef = A60014FA18552BDF00CE38D8 /* iTermNSKeyBindingEmulator.m */; };
A6358646184BEA57009ED690 /* AATree.h in Headers */ = {isa = PBXBuildFile; fileRef = A6358642184BEA57009ED690 /* AATree.h */; };
A6358647184BEA57009ED690 /* AATree.m in Sources */ = {isa = PBXBuildFile; fileRef = A6358643184BEA57009ED690 /* AATree.m */; };
A6358648184BEA57009ED690 /* AATree.m in Sources */ = {isa = PBXBuildFile; fileRef = A6358643184BEA57009ED690 /* AATree.m */; };
Expand Down Expand Up @@ -982,6 +985,8 @@
A073973F14C7694600786414 /* ColorsMenuItemView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ColorsMenuItemView.m; sourceTree = "<group>"; };
A60014F418550F3900CE38D8 /* NSMutableAttributedString+iTerm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableAttributedString+iTerm.h"; sourceTree = "<group>"; };
A60014F518550F3900CE38D8 /* NSMutableAttributedString+iTerm.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableAttributedString+iTerm.m"; sourceTree = "<group>"; };
A60014F918552BDF00CE38D8 /* iTermNSKeyBindingEmulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTermNSKeyBindingEmulator.h; sourceTree = "<group>"; };
A60014FA18552BDF00CE38D8 /* iTermNSKeyBindingEmulator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iTermNSKeyBindingEmulator.m; sourceTree = "<group>"; };
A6358642184BEA57009ED690 /* AATree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AATree.h; path = "objc-aatree-master/AATree.h"; sourceTree = "<group>"; };
A6358643184BEA57009ED690 /* AATree.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AATree.m; path = "objc-aatree-master/AATree.m"; sourceTree = "<group>"; };
A6358644184BEA57009ED690 /* AATreeNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AATreeNode.h; path = "objc-aatree-master/AATreeNode.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1221,6 +1226,8 @@
1D06A04F134CDBED00C414EF /* Trouter.m */,
A693395A1851A61D00EBEA20 /* VT100ScreenMark.h */,
A693395B1851A61D00EBEA20 /* VT100ScreenMark.m */,
A60014F918552BDF00CE38D8 /* iTermNSKeyBindingEmulator.h */,
A60014FA18552BDF00CE38D8 /* iTermNSKeyBindingEmulator.m */,
);
name = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -1884,6 +1891,7 @@
1D5FDD6A1208E8F000C46BA3 /* CGSCIFilter.h in Headers */,
1D5FDD6B1208E8F000C46BA3 /* CGSConnection.h in Headers */,
A6C4E8E21846E13800CFAA77 /* IntervalTree.h in Headers */,
A60014FB18552BDF00CE38D8 /* iTermNSKeyBindingEmulator.h in Headers */,
1D5FDD6C1208E8F000C46BA3 /* CGSCursor.h in Headers */,
1D81F0C0183C3C2D00910838 /* NSView+RecursiveDescription.h in Headers */,
1D5FDD6D1208E8F000C46BA3 /* CGSDebug.h in Headers */,
Expand Down Expand Up @@ -2330,6 +2338,7 @@
A60014F818550F3900CE38D8 /* NSMutableAttributedString+iTerm.m in Sources */,
A6C4E8E81846E32700CFAA77 /* IntervalTreeTest.m in Sources */,
1D9A5586180FA87000B42CE9 /* iTermSearchField.m in Sources */,
A60014FD18552BDF00CE38D8 /* iTermNSKeyBindingEmulator.m in Sources */,
1DD39B1F180B841C004E56D5 /* RegexKitLite.m in Sources */,
1D9A55A2180FA87000B42CE9 /* ThreeFingerTapGestureRecognizer.m in Sources */,
1D9A5583180FA87000B42CE9 /* iTermApplicationDelegate.m in Sources */,
Expand Down Expand Up @@ -2485,6 +2494,7 @@
1DDBC61F12E2BCDC00BC3868 /* iTermExpose.m in Sources */,
A63F40A5183F3B78003A6A6D /* LineBlock.m in Sources */,
1DAED28912E9395E005E49ED /* GlobalSearch.m in Sources */,
A60014FC18552BDF00CE38D8 /* iTermNSKeyBindingEmulator.m in Sources */,
1DAED5B212ECC485005E49ED /* FakeWindow.m in Sources */,
1DAED99312EDF923005E49ED /* iTermSearchField.m in Sources */,
1D85D1EF1306687700A3E998 /* RegexKitLite.m in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions iTermNSKeyBindingEmulator.h
@@ -0,0 +1,18 @@
//
// iTermNSKeyBindingEmulator.h
// iTerm
//
// Created by George Nachman on 12/8/13.
//
//

#import <Cocoa/Cocoa.h>

@interface iTermNSKeyBindingEmulator : NSObject

+ (instancetype)sharedInstance;

// Returns YES if the user's key bindings should handle this event.
- (BOOL)handlesEvent:(NSEvent *)event;

@end

2 comments on commit 5da3dae

@JohnTheAppleSeed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to handle "@" in the modifiers which stands for Command, and escapes of it, IOW "^@" means Ctrl-@ and not Ctrl-Cmd obviously.

but it seems to work very well that aside, thank you !!

@gnachman
Copy link
Owner Author

@gnachman gnachman commented on 5da3dae Dec 13, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.