Getting the text of a text view that's being edited
Getting the text of a text view that's being edited
- Subject: Getting the text of a text view that's being edited
- From: Darrin Cardani <email@hidden>
- Date: Fri, 6 Feb 2004 15:59:49 -0600
I have an NSTableView with several text cells in it. While the user
is editing a cell, they can select some of the words in the cell and
choose a menu command that will rearrange them. So, I would like to
be able to get the selected text, delete it from its current
location, and move it to a new location (possibly in a different
cell, possibly in the same one).
I'm able to retrieve the NSTextView object that is doing the editing,
and I can get the range of characters that is currently selected.
However, I don't see any way to get the actual current string out of
it. Actually, I see 2 possible ways, neither of which seems very
convenient:
1) use [ myTextView writeSelectionToPasteboard:pb type:NSStringPboardType ];
I've tried this, and I'm not getting the results I expected. (I get
the string that was previously on the pasteboard. It's as if the
above message did nothing.)
2) get the text view's textStorage, and use its -characters method to
return an array of the characters in it. I could then create a string
using the array's componentsJoinedByString method. That seems like a
really cumbersome way to do it.
Is one of those methods the expected way of getting the string, or is
there some other way that makes more sense?
The next task is to delete the selected range of characters, then
insert the characters I deleted somewhere else in the string. Again,
I could muck around with the text storage, or try working with the
pasteboard. Are those the recommended way of doing what I want?
Thanks,
Darrin
--
Darrin Cardani - email@hidden
President, Buena Software, Inc.
<
http://www.buena.com/>
Video, Image and Audio Processing Development
_______________________________________________
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.