Skip to content
Browse files

Added support for Ctr-N/-P for prev/next note

This does not override the prev/next line navigation when you are in the
note subview, only when focus is in the search bar or notes table view.

Emacs keybindings for the win.
  • Loading branch information...
1 parent 8510197 commit f4b78e40906598a4bcf6cdd3f155d10c9ca8a99f @csexton csexton committed Jan 31, 2011
Showing with 23 additions and 7 deletions.
  1. +23 −7 NotesTableView.m
View
30 NotesTableView.m
@@ -870,29 +870,45 @@ - (BOOL)performKeyEquivalent:(NSEvent *)theEvent {
unsigned mods = [theEvent modifierFlags];
+ BOOL isControlKeyPressed = (mods & NSControlKeyMask) != 0;
+ BOOL isCommandKeyPressed = (mods & NSCommandKeyMask) != 0;
+ BOOL isShiftKeyPressed = (mods & NSShiftKeyMask) != 0;
+
// Also catch Ctrl-J/-K to match the shortcuts of other apps
- if (((mods & NSCommandKeyMask) || (mods & NSControlKeyMask)) && ((mods & NSShiftKeyMask) == 0)) {
+ if ((isControlKeyPressed || isCommandKeyPressed) && (!isShiftKeyPressed)) {
+ // Determine the keyChar:
unichar keyChar = ' ';
- if (mods & NSCommandKeyMask) {
+ if (isCommandKeyPressed) {
keyChar = [theEvent firstCharacter]; /*cannot use ignoringModifiers here as it subverts the Dvorak-Qwerty-CMD keyboard layout */
}
- if (mods & NSControlKeyMask) {
+ if (isControlKeyPressed) {
keyChar = [theEvent firstCharacterIgnoringModifiers]; /* first gets '\n' when control key is set, so fall back to ignoringModifiers */
}
- if (keyChar == kNext_Tag || keyChar == kPrev_Tag) {
-
+ // Handle J and K
+ if ( keyChar == kNext_Tag || keyChar == kPrev_Tag ) {
if (mods & NSAlternateKeyMask) {
- [self selectRowAndScroll:(keyChar == kNext_Tag ? [self numberOfRows] - 1 : 0)];
+ [self selectRowAndScroll:((keyChar == kNext_Tag) ? [self numberOfRows] - 1 : 0)];
} else {
if (!dummyItem) dummyItem = [[NSMenuItem alloc] init];
[dummyItem setTag:keyChar];
-
[self incrementNoteSelection:dummyItem];
}
return YES;
}
+
+ // Handle N and P, but only when control is pressed
+ if ( (keyChar == 'n' || keyChar == 'p') && (!isCommandKeyPressed)) {
+ // Determine if the note editing pane is selected:
+ BOOL isEditorFirstResponder = [@"LinkingEditor" isEqualToString: NSStringFromClass([[[NSApp mainWindow] firstResponder] class])]; /* Can't use +isKindOfClass because LinkingEditor is a forwarding class and may not respond to +class */
+ if (!isEditorFirstResponder) {
+ if (!dummyItem) dummyItem = [[NSMenuItem alloc] init];
+ [dummyItem setTag:((keyChar == 'n') ? kNext_Tag : kPrev_Tag)];
+ [self incrementNoteSelection:dummyItem];
+ return YES;
+ }
+ }
}
return [super performKeyEquivalent:theEvent];

0 comments on commit f4b78e4

Please sign in to comment.
Something went wrong with that request. Please try again.