What method is available to select text on webkit2gtk. I could not find anything on the API for Vala webkit2.
The requirement is to get the selected text on a webpage after the user releases the mouse after text selection.
The only API for getting the current selection is via the DOM selection API. It is a bit awkward to get access to the DOM in WebKitGTK+ since the DOM representation exists in the memory of the web process, which is separate from the application process that has the WebKit.WebView widget.
To bridge between the two, you can call WebKit.WebView.run_javascript()
and pass the appropriate JavaScript code through to be executed in the web process, something like:
web_view.run_javascript("window.getSelection().getRangeAt(0).toString()")
To use this method, you will need to use vala 0.38, or import the JavaScriptCore VAPI into your own project (like Geary does), so you can work out what the return value is.
Note also that you'll probably want to add some checks to this: that there is at least one range in the DOM selection object, and so on.