Hello,
You can add an on-click listener to the links you create for the TOC. This listener will scroll the document to the element with the given id and set the selection right at the beginning of the element.
Here's how to implement the on-click listener:
Code: Select all
// Get the html element with the required id.
var elem = document.querySelector('[data-attr-id="' + elementId + '"]');
// Create a selection which is set in the element.
var xmlNode = sync.api.dom.createApiNode(elem);
var sel = sync.api.Selection.createEmptySelectionInNode(xmlNode, 'before');
// Put the editor selection into the xmlNode.
editor.getSelectionManager().setSelection(sel);
// Scroll the page to make sure the element is visible.
elem.scrollIntoView();
You can get a reference to the editor variable in the
sync.view.ViewRenderer.prototype.editorChanged method.
Here's some relevant documentation [1][2][3].
Best,
Gabriel
[1]
https://www.oxygenxml.com/maven/com/oxy ... tionInNode
[2]
https://www.oxygenxml.com/maven/com/oxy ... ionManager
[3]
https://www.oxygenxml.com/maven/com/oxy ... torChanged