Skip to content

Commit

Permalink
Cleanup and Ctl-[ in performKeyEquivalent
Browse files Browse the repository at this point in the history
Moved redundant code into it's own method to clean up the method a bit.

Added handler for Control-[ to make it equivalent to Escape or
Command-L. Bringing the Emacs and Vim to NV.
  • Loading branch information
csexton committed Feb 8, 2011
1 parent f4b78e4 commit abbd650
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions NotesTableView.h
Expand Up @@ -88,6 +88,7 @@ typedef struct _ViewLocationContext {
- (NoteAttributeColumn*)noteAttributeColumnForIdentifier:(NSString*)identifier;

- (void)incrementNoteSelection:(id)sender;
- (void)incrementNoteSelectionWithDummyItem:(unichar) keyChar;

- (id)labelsListSource;
- (void)setLabelsListSource:(id)labelsSource;
Expand Down
29 changes: 20 additions & 9 deletions NotesTableView.m
Expand Up @@ -22,6 +22,7 @@
#import "UnifiedCell.h"
#import "HeaderViewWithMenu.h"
#import "NSString_NV.h"
#import "LinkingEditor.h"

#define STATUS_STRING_FONT_SIZE 16.0f
#define SET_DUAL_HIGHLIGHTS 0
Expand Down Expand Up @@ -862,6 +863,7 @@ - (void)keyDown:(NSEvent*)theEvent {
}



enum { kNext_Tag = 'j', kPrev_Tag = 'k' };

//use this method to catch next note/prev note before View menu does
Expand All @@ -886,29 +888,32 @@ - (BOOL)performKeyEquivalent:(NSEvent *)theEvent {
keyChar = [theEvent firstCharacterIgnoringModifiers]; /* first gets '\n' when control key is set, so fall back to ignoringModifiers */
}

// Handle J and K
// Handle J and K for both Control and Command
if ( keyChar == kNext_Tag || keyChar == kPrev_Tag ) {
if (mods & NSAlternateKeyMask) {
[self selectRowAndScroll:((keyChar == kNext_Tag) ? [self numberOfRows] - 1 : 0)];
} else {
if (!dummyItem) dummyItem = [[NSMenuItem alloc] init];
[dummyItem setTag:keyChar];
[self incrementNoteSelection:dummyItem];
[self incrementNoteSelectionWithDummyItem: keyChar];
}
return YES;
}

// Handle N and P, but only when control is pressed
// 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 */
BOOL isEditorFirstResponder = [[[NSApp mainWindow] firstResponder] isKindOfClass: [LinkingEditor class]];
if (!isEditorFirstResponder) {
if (!dummyItem) dummyItem = [[NSMenuItem alloc] init];
[dummyItem setTag:((keyChar == 'n') ? kNext_Tag : kPrev_Tag)];
[self incrementNoteSelection:dummyItem];
[self incrementNoteSelectionWithDummyItem: (keyChar == 'n') ? kNext_Tag : kPrev_Tag];
return YES;
}
}

// Make Control-[ equivalent to Escape
if ( (keyChar == '[' ) && (!isCommandKeyPressed)) {
AppController* appDelegate = (AppController*)[NSApp delegate];
[appDelegate bringFocusToControlField:nil];
return YES;
}
}

return [super performKeyEquivalent:theEvent];
Expand All @@ -932,6 +937,12 @@ - (void)incrementNoteSelection:(id)sender {
[self selectRowAndScroll:rowNumber];
}

- (void)incrementNoteSelectionWithDummyItem:(unichar) keyChar {
if (!dummyItem) dummyItem = [[NSMenuItem alloc] init];
[dummyItem setTag:keyChar];
[self incrementNoteSelection:dummyItem];
}

- (void)deselectAll:(id)sender {

[super deselectAll:sender];
Expand Down

0 comments on commit abbd650

Please sign in to comment.