B4J Question What is the current text phrase position with the HTML editor?

T201016

Active Member
Licensed User
Longtime User
Hi,
I am using HTMLEditorWrapper in a project and would like to position the cursor on the first found word using the search function.
Word highlighting manages to do, unfortunately I have no idea how to reveal the cursor position. It's much easier in TextArea.

Something like:
Dim jo As JavaObject = TextArea1
Dim event As Object = jo.CreateEventFromUI ("javafx.beans.value.ChangeListener", "SelectionChanged", Null)
jo.RunMethodJO ("selectionProperty", Null) .RunMethod ("addListener", Array (event))
 

T201016

Active Member
Licensed User
Longtime User
can you use JS code with the HTMLEditorWrapper?

In TextArea1, each new cursor position provides the following data (total number of lines of text, the current line where the cursor is currently located, and the column number) and I do this:

SelectionChanged_Event:
    #Region SelectionChanged_Event --------------------------------------------------------------------------
    ' Line column in TextArea1
    Dim jo As JavaObject = TextArea1
    Dim event As Object = jo.CreateEventFromUI("javafx.beans.value.ChangeListener", "SelectionChanged", Null)
    jo.RunMethodJO("selectionProperty", Null).RunMethod("addListener", Array(event))
    #End Region ---------------------------------------------------------------------------------------------
   
    . . .  
End Sub

Sub SelectionChanged_Event (MethodName As String, Args() As Object) As Object
    If MethodName = "changed" And TextArea1.Text <> "" Then
        Dim IndexRange As JavaObject = Args(2)
        Dim StartPosition As Int = IndexRange.RunMethod("getStart", Null)
       
        ' copy the text area to a list
        Dim l As List
        l.Initialize
        l.AddAll(Regex.Split(CRLF, TextArea1.Text))
       
        If l.Size > 0 Then
        ' echo the number of line excluding empty line at the end
        ' l.size = "lines in text area"
       
            Dim the_start,the_end,line,column As Int
            Dim the_str As String =""
       
            the_start = 0
            the_end = 0
       
            For i = 0 To l.Size-1
                ' get line length
                the_str = l.Get(i)
                the_end = the_start+the_str.Length
           
                If StartPosition >= the_start And StartPosition <= the_end Then
                    line = i+1
                    column= StartPosition - the_start
                End If
                the_start = the_end+1
                Main.Coordonate4.Text ="Lines : "&l.size&"  "
                Main.Coordonate2.Text ="Ln : "   &line
                Main.Coordonate3.Text ="  Col : "&column
                Main.Coordonate1.Text ="Found : "
            Next
            Return Null
        End If
    End If
    Main.Coordonate4.Text ="Lines : "
    Main.Coordonate2.Text ="Ln : "
    Main.Coordonate3.Text ="  Col : "
    Main.Coordonate1.Text ="Found : "
    Return Null
End Sub
 
Last edited:
Upvote 0
Top