I am trying to create a Google Apps Script that could help navigate through the headers.
I have currently a code searching the position with the function "findText" that I used in a custom menu in my Doc.
function goto (title) {
//Get element
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
//Search element
var searchType = DocumentApp.ElementType.PARAGRAPH;
var searchResult = null;
searchResult = body.findText(title, body.findText(title))
var position = doc.newPosition(searchResult.getElement(), 1);
doc.setCursor(position);
}
However, this seems to run slow on my browser so I would like to improve the speed by getting the position of the headers directly by using, for example, the information of their corresponding URLs (e.g. #heading=h.wtr4epyf5xix
).
Does something like doc.newPosition(body.getHeader("wtr4epyf5xix"))
would exist?