Re: Replace Selected Text


On Nov 10, 2008, at 11:06 AM, Brendan Murphy wrote:

Bob Keeney wrote:
Is there a function anywhere in the arsenal of FTC functions that allows one to replace the currently selected text? If not, how would you suggest going about it?

Not specifically yet, but here is the pseudo code to do such a thing.

inhibit updates
get the selection range (save the starting point)
delete the selected text
insert the replacement string
get the current insertion point
reselect the newly inserted text (original starting point to current insertion point)
set the style attributes
restore updates
perform an update

How sophisticated you get with the setting of the style attributes
can get a little tricky depending on your requirements.

Well, I cheated a little (okay a lot). I simply re-used the code you use to paste from the clipboard. It simply replaces anything currently selected.

As far as getting the word selection, I cheated again. I subclassed the control and when I do a right-click I call the HandleDoubleClick code which gives me the word I'm click on and then I get the selection range, replace the line endings and voila I have my selected word. Then I start the spell checking process.

My guess is that all of this destroys my formatting but we'll see how it works in the final projects I'm working on.

BTW, did you get a chance to confirm the bug I sent in yesterday about the user dictionary not getting saved to the proper location? Any ETA on when that could get fixed? I'd like to do an update to an app soon and it will be part of 2 other projects we're just starting development on.

Bob Keeney
BKeeney Software Inc.
FTC Website: 
http://www.truenorthsoftware.com/FormattedTextControl/FormattedTextControl.html
Set List Options (digest and vacation modes): www.freelists.org/list/ftcdev
List Archive: www.freelists.org/archives/ftcdev
Unsubscribe: Send email to ftcdev-request@xxxxxxxxxxxxx with "unsubscribe" in 
the subject field.



Other related posts: