Skip to content

Commit

Permalink
use firstCharacterIgnoringModifiers/firstCharacter methods that retur…
Browse files Browse the repository at this point in the history
…n USHRT_MAX for empty strings to allow for dead keys
  • Loading branch information
Zachary Schneirov committed Sep 13, 2009
1 parent fb5a491 commit 0ac3566
Show file tree
Hide file tree
Showing 10 changed files with 451 additions and 202 deletions.
2 changes: 1 addition & 1 deletion AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)aTextView doCommandB
//control-U is not set to anything by default, so we have to check the event itself for noops
NSEvent *event = [window currentEvent];
if ([event modifierFlags] & NSControlKeyMask) {
if ([[event charactersIgnoringModifiers] characterAtIndex:0] == 'u') {
if ([event firstCharacterIgnoringModifiers] == 'u') {
//in 1.1.1 this deleted the entire line, like tcsh. this is more in-line with bash
[aTextView deleteToBeginningOfLine:nil];
return YES;
Expand Down
3 changes: 2 additions & 1 deletion BookmarksTable.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "BookmarksTable.h"
#import "BookmarksController.h"
#import "NSString_NV.h"

@implementation BookmarksTable

Expand All @@ -15,7 +16,7 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent {

- (void)keyDown:(NSEvent*)theEvent {

unichar keyChar = [[theEvent characters] characterAtIndex:0];
unichar keyChar = [theEvent firstCharacter];

if (keyChar == NSDeleteCharacter || keyChar == NSDeleteFunctionKey) {
[(BookmarksController*)[self dataSource] removeBookmark:nil];
Expand Down
2 changes: 1 addition & 1 deletion DualField.m
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ - (unsigned int)lastLengthReplaced {

/*
- (BOOL)performKeyEquivalent:(NSEvent *)anEvent {
unichar keyChar = [[anEvent charactersIgnoringModifiers] characterAtIndex:0];
unichar keyChar = [anEvent firstCharacterIgnoringModifiers];
if (keyChar == NSCarriageReturnCharacter || keyChar == NSNewlineCharacter || keyChar == NSEnterCharacter) {
Expand Down
6 changes: 3 additions & 3 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<key>CFBundleExecutable</key>
<string>Notational Velocity</string>
<key>CFBundleGetInfoString</key>
<string>2.0 β, Copyright © 2009 Zachary Schneirov, All Rights Reserved.</string>
<string>2.0 β0, Copyright © 2009 Zachary Schneirov, All Rights Reserved.</string>
<key>CFBundleIconFile</key>
<string>Notality</string>
<key>CFBundleIdentifier</key>
Expand All @@ -142,11 +142,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.0 β</string>
<string>2.0 β0</string>
<key>CFBundleSignature</key>
<string>N†l√</string>
<key>CFBundleVersion</key>
<string>2.0 β</string>
<string>2.0 β0</string>
<key>LSMinimumSystemVersion</key>
<string>10.3.9</string>
<key>NSMainNibFile</key>
Expand Down
5 changes: 2 additions & 3 deletions LinkingEditor.m
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ - (IBAction)performFindPanelAction:(id)sender {

- (BOOL)performKeyEquivalent:(NSEvent *)anEvent {

unichar keyChar = [[anEvent charactersIgnoringModifiers] characterAtIndex:0];
unichar keyChar = [anEvent firstCharacterIgnoringModifiers];

if (keyChar == NSCarriageReturnCharacter || keyChar == NSNewlineCharacter || keyChar == NSEnterCharacter) {

Expand All @@ -767,15 +767,14 @@ - (BOOL)performKeyEquivalent:(NSEvent *)anEvent {
}

- (void)keyDown:(NSEvent*)anEvent {
unichar keyChar = [[anEvent charactersIgnoringModifiers] characterAtIndex:0];
unichar keyChar = [anEvent firstCharacterIgnoringModifiers];

if (keyChar == NSBackTabCharacter) {
//apparently interpretKeyEvents: on 10.3 does not call insertBacktab
//maybe it works on someone else's 10.3 Mac
[self doCommandBySelector:@selector(insertBacktab:)];
return;
}

[super keyDown:anEvent];
}
- (void)insertTab:(id)sender {
Expand Down
7 changes: 6 additions & 1 deletion NSString_NV.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ void resetCurrentDayTime();

@interface NSMutableString (NV)
+ (NSMutableString*)getShortLivedStringFromData:(NSMutableData*)data ofGuessedEncoding:(NSStringEncoding*)encoding;
@end
@end

@interface NSEvent (NV)
- (unichar)firstCharacter;
- (unichar)firstCharacterIgnoringModifiers;
@end
17 changes: 17 additions & 0 deletions NSString_NV.m
Original file line number Diff line number Diff line change
Expand Up @@ -605,3 +605,20 @@ + (NSMutableString*)getShortLivedStringFromData:(NSMutableData*)data ofGuessedEn
}

@end


@implementation NSEvent (NV)

- (unichar)firstCharacter {
NSString *chars = [self characters];
if ([chars length]) return [chars characterAtIndex:0];
return USHRT_MAX;
}

- (unichar)firstCharacterIgnoringModifiers {
NSString *chars = [self charactersIgnoringModifiers];
if ([chars length]) return [chars characterAtIndex:0];
return USHRT_MAX;
}

@end
Loading

0 comments on commit 0ac3566

Please sign in to comment.