Re: Double-click and drag word in NSTextView
Re: Double-click and drag word in NSTextView
- Subject: Re: Double-click and drag word in NSTextView
- From: Keith Blount <email@hidden>
- Date: Tue, 10 Oct 2006 15:29:07 -0700 (PDT)
Okay, now I'm **doubly** sorry to reply to my own post
a second time... I just realised that NSTextView's
-selectionGranularity tells me whether or not a word
has been double-clicked for selection. The trouble is
that the selection granularity is set when the word is
selected and seems to be reset when it is dragged, so
when I come to check whether or not I need to add
extra whitespace in
-readSelectionFromPasteboard:type:, the
-selectionGranularity is no longer NSSelectByWord. My
current solution to this problem is therefore to have
a static variable to save the selection granularity:
static NSSelectionGranularity copyPasteGranularity;
I just set this to [self selectionGranularity] in
-writeSelectionToPasteboard:type:. Then, when I come
to read the copied string from the pasteboard in
-readSelectionFromPasteboard:type:, I check to see if
copyPasteGranularity == NSSelectByWord. If so, then I
call
-smartInsertForString:replacingRange:beforeString:afterString:
and insert any extra whitespace returned from this
method as necessary.
This seems to work. If any text experts out there can
tell me whether this is the best way around this
problem or if there is a better solution, I would
still be grateful. :)
Many thanks again,
Keith
---
Hello,
I have a custom text view that overrides the copy and
paste methods (-writeSelectionToPasteboard:type:) etc.
I have to do this because my text can have custom
attributes applied, and if I don't use my own
pasteboard type these will get lost.
However, one of my users has noticed that this causes
an annoying "bug": the default behaviour of an
NSTextView is that if you double-click on a word to
select it and then drag and drop the word (or phrase)
somewhere else, spaces will be inserted around it as
necessary ("smartly"). But because I am overriding the
methods that do all this, this behaviour is broken in
my custom text view.
So, my question is, how do I go about reimplementing
this behaviour? ie. How do I detect whether the user
has double-clicked the word to select it, and
therefore know that I have to check the context of the
word when copying and pasting? Is there any way of
doing this, or any other solution?
Many thanks,
Keith
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden