From fa86d65b36b1a4b857d94656e5518a3ecee30d7d Mon Sep 17 00:00:00 2001 From: Kevin Brubeck Unhammer Date: Fri, 7 Feb 2025 12:02:41 +0100 Subject: [PATCH] Set cursor to selection start instead of empty range on clearHighlight --- google/grammarcheck.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/google/grammarcheck.ts b/google/grammarcheck.ts index 631ebd3..4c18922 100644 --- a/google/grammarcheck.ts +++ b/google/grammarcheck.ts @@ -265,8 +265,14 @@ function highlightError(errorText: string, errorIndex: number, paragraphIndex: n function clearHighlight() { const doc = DocumentApp.getActiveDocument() - const range = doc.newRange() - doc.setSelection(range.build()) + const selection = doc.getSelection(); + if (selection) { + for (let element of selection.getRangeElements()) { + const pos = doc.newPosition(element.getElement(), element.getStartOffset()); + doc.setCursor(pos); + return; + } + } } function changeLanguage(key: string) { @@ -301,4 +307,4 @@ function saveSettings(key: string, value: string) { const userProperties = PropertiesService.getUserProperties(); Logger.log("save " + key + " = " + value); userProperties.setProperty(key, value); -} \ No newline at end of file +}