Hey guys,
In my NSTextView subclass, I use keyDown: to intercept the = key and do something with it.
Here is my current code for this:
Code:
- (void)keyDown:(NSEvent *)theEvent
{
unichar unicodeChar;
NSString *characters;
characters = [theEvent characters];
unicodeChar = [characters characterAtIndex:0];
if (unicodeChar == '=')
{
[super keyDown:theEvent];
NSRange selectedRange = [self selectedRange];
[self insertText:@"\"\""];
[self setSelectedRange:NSMakeRange(selectedRange.location + selectedRange.length + 1, 0)];
}
else
{
[super keyDown:theEvent];
}
}
This code works perfect, and does what its meant to do (insert a "" and place the cursor in between) but this isn't too good in terms of usability. What I am looking to do is only insert the "" only if it is inside a "<" and not outside the ">".
Any ideas?
Thanks,
Oliver