0
votes

I am looking at a way to determine the named range in Google docs through Google Apps Script for the current cursor position. Is there anyway to do that?

Context: I am marking a range in the google document for review using named range. I would like to get the named range if the cursor is placed in that location of the document so that I can show that there is a review item on that area.

Could you please let me know if there is a way to do that in Google Apps Script? thanks Jasper

1
What if there are 15 named ranges that contain the cell where the cursor is placed? - user3717023
@sandwich, I would like to get all the named ranges for the current position. - Jasperin
@d.datul1990 the reference is not helping as it is for Google Sheets in a different context. I am looking for Google Docs. - Jasperin

1 Answers

0
votes
var cursor = DocumentApp.getActiveDocument().getCursor();

cursor is a "Position".

A "Position" can tell you several things, for example the element which holds the position. Be careful: The thinking of a position is quite opposite: A position cannot contain other elements. A position is contained within an element.

So i think you could search your named ranges for this element:

cursor.getElement()

You have to iterate through your ranges, i think and if there is a match ... bingo.

Let me know if this helps.