Page 1 of 1

OxygenXML Web author highlighted text

Posted: Mon Dec 12, 2022 11:27 pm
by akshatTR
Hi there,
I am trying to get the highlighted text (which could be a double click or selection with cursor).
when user does this highlight text operation, which is represented on UI with blue background color, how do i get the selected/highlighted text and not the whole text under the tag. For example in attached screenshot "Jennifer Angelini" is under a tag. But if the user highlights Angelini like in the screenshot, how do i get that particular part of the text ("Angelini")?
Screenshot 2022-12-12 at 3.22.54 PM.png
I have tried selection manager and highlights manager. Here is the code I used for highlights manager but somehow its not being called.

Code: Select all

var highlightManager = e.editor.getEditingSupport().getWidgetsFactory().getHighlightsManager();
        highlightManager.listen(sync.api.HighlightUpdateEvent.EventType.HIGHLIGHT_ADDED, function(e) {
            console.log("highlight changed ", e);
});

Re: OxygenXML Web author highlighted text

Posted: Tue Dec 13, 2022 10:10 am
by cristi_talau
Hello,

In Web Author, the selection has two particular cases: an interval selection, and a "caret" selection where the interval is empty. Highlights are a different object. They can be added using the API, so if no customisation is implemented, there are not highligts.
Coming back to your question about how to obtain the selected text, there is no simple API to do this. There are two workarounds:
1. Use the Selection.getCaretPositionInformation() API [1] and travese the XML DOM nodes to obtain the selected text.
2. Use a NON-API JS method that may be removed in a future release, but which works with Web Author 25.0:

Code: Select all

sync.model.ContentModel.getTextFromSelection(sel)
Best,
Cristian

[1] https://www.oxygenxml.com/maven/com/oxy ... on__anchor

Re: OxygenXML Web author highlighted text

Posted: Wed Dec 14, 2022 3:01 am
by akshatTR
Thank you! It's working now!