I don't know know if there's a better way, but I call my selection- fixing code in -selectionRangeForProposedRange:granularity:, and also in the following NSTextView overrides if the selected range length is 0 (if it's not zero, presumably it's already been fixed by - selectionRangeForProposedRange:granularity:):

textView:willChangeSelectionFromCharacterRanges:toCharacterRanges: (delegate method)
deleteForward:
deleteBackward:
deleteWordForward:
deleteWordBackward:
deleteBackwardByDecomposingPreviousCharacter:
deleteToEndOfParagraph:

I wouldn't mess with rangeForUserTextChange; I'm sure it knows more about unicode normalization forms, etc., than I do.

Ross


On Feb 4, 2009, at 8:09 AM, Chris Idou wrote:

That didn't seem to help. I tried overriding selectedRanges, and that makes you delete the whole range when you are clicked in it (good), but nothing seems to help the case of trying to simply backspace from the end of the range. In this case the selected range is not relevant because you are not inside the range yet as far as the existing range, and you can't predict in advance the user intends to backspace into it, and for the same reason, neither is the rangeForUserTextChange.

On Feb 3, 2009, at 5:24 PM, Chris Idou wrote:

So I want it that if you try and delete any character that is part of a token, it deletes the entire token.

So I'm overriding rangeForUserTextChange to return a different range if the current range includes any part of a token.

This seems to work if the user tries to type in any part. For example, clicking on the token and pressing space bar or a letter.

However, it doesn't work if you press backspace or delete, even though rangeForUserTextChange is still called.

I don't think you really want to override that method. Instead override -[NSTextView selectionRangeForProposedRange:granularity:] which should be called for every selection the user makes.

~Martin



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to