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 +}