GAS - Google Docs API - getActiveDocument().getCursor().getOffset() returns unexpected '1' for cursor at end of line

Viewed 156

I use CLASP therefore my dummy code is displayed as TypeScript.

If I write "test" into my google document and let the cursor be at what I would expect index 4 of the string, the Apps Script API returns 1 when calling:

const activeDocument = DocumentApp.getActiveDocument();
const cursor = activeDocument.getCursor();
const cursorOffset = cursor.getOffset();

This is a true headage for me because when I rest the cursor at index 1 for the string "test", then the same code returns the expected index 1.

How should anyone know that the cursor is at end of line or at the actual index 1 of the SurroundingText for the cursor Position when the offset is the same?

1 Answers
Related