Add selection event listener
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 23
- Joined: Wed Jan 16, 2019 5:16 am
Add selection event listener
Post by nstensland »
Can you provide example code ( or link to documentation of how to) add a custom Selection event listener on the javascript client side (framework.js)? We would like to capture the selection range and re-selection the range at a later time.
Thanks,
Nat
Thanks,
Nat
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: Add selection event listener
Hi,
You can listen for SELECTION_CHANGED event [0] like in this example:
But if you plan to restore selection at a later time I suggest to do that by implementing a custom Java operation.
The selection available from JavaScript is not updated as the document changes, so the selection may no longer be valid at a later time.
The Java code that restores a seletion from a operation may look like this:
You an find more details about customizing Web Author with plugins here:
https://www.oxygenxml.com/doc/ug-waCust ... ugins.html
[0] https://www.oxygenxml.com/maven/com/oxy ... Model.html
Best Regards,
Mihaela
You can listen for SELECTION_CHANGED event [0] like in this example:
Code: Select all
goog.events.listen(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
var editor = e.editor;
var selectionModel = editor.getSelectionManager();
var eventHandler = new goog.events.EventHandler(this)
eventHandler.listen(selectionModel, sync.api.SelectionModel.EventType.SELECTION_CHANGED, function() {
var currentSelection = selectionModel.getSelection();
console.log("Selection changed ", currentSelection);
});
});
The selection available from JavaScript is not updated as the document changes, so the selection may no longer be valid at a later time.
The Java code that restores a seletion from a operation may look like this:
Code: Select all
int start = authorAccess.getEditorAccess().getSelectionStart();
int end = authorAccess.getEditorAccess().getSelectionEnd();
Position startPos = authorAccess.getDocumentController().createPositionInContent(start);
Position endPos = authorAccess.getDocumentController().createPositionInContent(end);
authorAccess.getEditorAccess().select(startPos.getOffset(), endPos.getOffset());
https://www.oxygenxml.com/doc/ug-waCust ... ugins.html
[0] https://www.oxygenxml.com/maven/com/oxy ... Model.html
Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
http://www.oxygenxml.com
-
- Posts: 23
- Joined: Wed Jan 16, 2019 5:16 am
Re: Add selection event listener
Post by nstensland »
In this simple example
var currentSelection = selectionModel.getSelection();
selectionModel.setSelection(currentSelection);
It seems to work but results in this error in console:
nIndex is not defined
at <anonymous>:577:74
Should this work without an error?
var currentSelection = selectionModel.getSelection();
selectionModel.setSelection(currentSelection);
It seems to work but results in this error in console:
nIndex is not defined
at <anonymous>:577:74
Should this work without an error?
-
- Posts: 23
- Joined: Wed Jan 16, 2019 5:16 am
Re: Add selection event listener
Post by nstensland »
Is there a way to scroll to a selection? scrollManager.scrollTo(SelectionFromGetSelection)?
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: Add selection event listener
Hi,
1. To scroll to a selection you can find the element at selection:
and then use the "scrollIntoView" method on this element:
2.
Can you check that the error is thrown by a custom plugin?
This can be done by looking for the JavaScript file that throws that exception, by clicking the link presented in browser's console next to the error.
If the JavaScript file is not "workspace*.js" then is thrown by a custom plugin.
[1] https://staging-webapp.sync.ro/oxygen-x ... xygen.html
Bes Regards,
Mihaela
1. To scroll to a selection you can find the element at selection:
Code: Select all
var nodeAtSelection = selection.getNodeAtSelection();
Code: Select all
nodeAtSelection.scrollIntoView()
That snippet shouldn't casuse any errors. On our demo deployment [1] the following code works as expected:Should this work without an error?
Code: Select all
var selectionModel = workspace.currentEditor.getSelectionManager();
var currentSelection = selectionModel.getSelection();
selectionModel.setSelection(currentSelection);
This can be done by looking for the JavaScript file that throws that exception, by clicking the link presented in browser's console next to the error.
If the JavaScript file is not "workspace*.js" then is thrown by a custom plugin.
[1] https://staging-webapp.sync.ro/oxygen-x ... xygen.html
Bes Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
http://www.oxygenxml.com
-
- Posts: 517
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Add selection event listener
Post by cristi_talau »
Hello,
I am updating this thread to let you know that version 21.1.1 of Web Author was released and now there is a new API sync.api.SelectionManager.scrollSelectionIntoView that can be used to scroll the selection into view.
You can find a list of other features and improvements that were added in this version on our website: https://www.oxygenxml.com/xml_web_author/whats_new.html .
Best,
Cristian
I am updating this thread to let you know that version 21.1.1 of Web Author was released and now there is a new API sync.api.SelectionManager.scrollSelectionIntoView that can be used to scroll the selection into view.
You can find a list of other features and improvements that were added in this version on our website: https://www.oxygenxml.com/xml_web_author/whats_new.html .
Best,
Cristian
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service