B4J Question HTMLEditor - How to position cursor at end of the text read

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

I am using the HTMLEditor (great control!)...

1. When I bring up the form containing the HTMLEditor, I requestFocus and get it, but no cursor is shown.... How to show the cursor? [I know I asked this specific question before, but I was not clear - my apologies]
2. How do I bring the editor to the end of the text read?

Thank you for your reply.

Sandy
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code will set the focus and move the cursor to the end:
B4X:
Sub Button1_Action
   Dim jo As JavaObject = HTMLEditor1
   Dim r As Reflector
   r.Target = jo.RunMethodJO("getSkin", Null)
   jo = r.GetField("webView")
   jo.RunMethod("requestFocus", Null)
   jo = jo.RunMethod("getEngine", Null)
   jo.RunMethod("executeScript", Array("document.body.focus()"))
   jo.RunMethod("executeScript", Array($"
   var el = document.body;
if (typeof window.getSelection != "undefined"
  && typeof document.createRange != "undefined") {
   var range = document.createRange();
   range.selectNodeContents(el);
   range.collapse(false);
   var sel = window.getSelection();
   sel.removeAllRanges();
   sel.addRange(range);
} else if (typeof document.body.createTextRange != "undefined") {
   var textRange = document.body.createTextRange();
  textRange.moveToElementText(el);
   textRange.collapse(false);
   textRange.select();
}
   "$))
End Sub
It is based on this solution: http://stackoverflow.com/questions/28106194/positioning-caret-in-javafx-htmleditor
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Erel.

It abends - the code is above my tech skills. Simple Project attached .

Sandy
 

Attachments

  • 2 Text Editor.zip
    298.7 KB · Views: 353
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Erel.

it works! For the benefit of others, I post the revised project. I just learned about the smart strings literal.

I could not figure out how to append CRLF and Today's date to the HTML string.

Sandy
 

Attachments

  • 2 Text Editor V2.zip
    298.6 KB · Views: 356
Upvote 0

m4.s

Member
Licensed User
Longtime User
Have either of you tried this solution code using the Java 8 runtime?

It does not work for me in my application; I receive no error, it just does nothing. I tried Sandy's "2 Text Editor V2' project example as well.
 
Upvote 0
Top