Re: limit text input in NSTextView
Re: limit text input in NSTextView
- Subject: Re: limit text input in NSTextView
- From: Arthur Clemens <email@hidden>
- Date: Wed, 18 Sep 2002 15:00:59 +0200
I am almost to a complete solution! Let me share what I've come up with
so far:
I was trying to implement willChangeSelectionFromCharacterRange: but I
noticed this method is almost never called, except when tabbing in the
text.
Wanting to find out more about this method I searched in the archives
and stumbled upon this post of Rainer Brockerhoff, "Re: Controlling
selection in NSTextFields" (
http://cocoa.mamasam.com/COCOADEV/2001/11/1/17396.php )
His problem is a bit related to mine, and he uses
- (void)setSelectedRange:(NSRange)charRange
affinity:(NSSelectionAffinity)affinity
stillSelecting:(BOOL)stillSelectingFlag
to check which characters are selected by mouse or keyboard (and which
ones are allowed to be edited).
As I only have a NSTextView and no text fields, I just have to
implement this method, and inside the method check if the charRange
falls within an 'immutable' keyword. If so, I won't pass [super
setSelectedRange:extendRange affinity:affinity
stillSelecting:stillSelectingFlag];
Additionally I added this to move the cursor off the keyword:
if (charRange.length == 0) {
// no selection has been made, so this is just a change of cursor
position by mouse or keyboard
[super setSelectedRange:charRange affinity:affinity
stillSelecting:stillSelectingFlag];
[self moveToEndOfLine:self];
} else {
// a selection has been made
// this part is trickier...
// still have to solve to extend the selection right up to the keyword,
// in both directions!
}
Then I use shouldChangeTextInRange: to disallow text input if the
cursor is directly right to a keyword - otherwise I am extending the
keyword!
doCommandBySelector: I only use for disabling forward delete.
In all, this covers almost everything I need to make certain words
immutable.
Thanks to all who helped me thus far!
Arthur Clemens
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.