How do I move the caret position to the end of the current word?
I am using webbrowser control. How do I move the insertion position for execCommand to the end of the word that is currently selected?
Example:
| <- current carriage position
Som | eword → move → Someword | -> execCommand is executed after the current word
What I want to do is insert a line without trading a word. What's happening now:
Multiple lines -> line
Somew
Ord
What is going to happen:
Multiple lines -> line
Someword
This is so hacky that I'm almost confused to post it, but ... you can accomplish "Insert Line Without Breaking Word" using a web browser control by doing something like
webBrowser1.Url =
new Uri("javascript:" +
"var tr=document.selection.createRange();" +
"tr.expand('word');" +
"tr.collapse(false);" +
// "tr.select();" // Necessary to actually move the caret
"tr.pasteHTML('<hr>');");
After the web browser has loaded the document you want to process and the user has selected the text they would like to insert after. If you really need to move the carriage, you'll need tr.select()
after tr.collapse()
.
It doesn't use execCommand, although it might not be suitable for your purposes. Maybe someone else can find a way to make this a little cleaner ...
source to share