Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cursorInspector/cursorInspector.gs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function getDocumentInfo() {

/**
* Gets information about a given element.
* @param {Element} element The element.
* @param {GoogleAppsScript.Document.Element} element The element.
* @return {Object} The information.
*/
function getElementInfo(element) {
Expand Down
2 changes: 1 addition & 1 deletion docs/dialog2sidebar/Code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function showSidebar() {
* @return {string} The dialog ID.
*/
function openDialog() {
var dialogId = Utilities.base64Encode(Math.random());
var dialogId = Utilities.base64Encode(String(Math.random()));
var template = HtmlService.createTemplateFromFile('Dialog');
template.dialogId = dialogId;
var page = template.evaluate()
Expand Down
3 changes: 2 additions & 1 deletion docs/quickstart/quickstart.gs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
*/
function printDocTitle() {
const documentId = '195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE';
const doc = Docs.Documents.get(documentId, {'includeTabsContent': true});
const doc = /** @type {any} */ (Docs).Documents.get(documentId,
{'includeTabsContent': true});
console.log(`The title of the doc is: ${doc.title}`);
}
// [END docs_quickstart]
36 changes: 19 additions & 17 deletions docs/translate/translate.gs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function getSelectedText() {
const element = elements[i].getElement();
// Only translate elements that can be edited as text; skip images and
// other non-text elements.
if (element.editAsText) {
if ((/** @type {any} */ (element)).editAsText) {
const elementText = element.asText().getText();
// This check is necessary to exclude images, which return a blank
// text element.
Expand Down Expand Up @@ -190,10 +190,10 @@ function insertText(newText) {
}
} else {
const element = elements[i].getElement();
if (!replaced && element.editAsText) {
if (!replaced && (/** @type {any} */ (element)).editAsText) {
// Only translate elements that can be edited as text, removing other
// elements.
element.clear();
(/** @type {any} */ (element)).clear();
element.asText().setText(newText);
replaced = true;
} else {
Expand All @@ -202,30 +202,32 @@ function insertText(newText) {
if (element.getNextSibling()) {
element.removeFromParent();
} else {
element.clear();
(/** @type {any} */ (element)).clear();
}
}
}
}
} else {
const cursor = DocumentApp.getActiveDocument().getCursor();
const surroundingText = cursor.getSurroundingText().getText();
const surroundingTextOffset = cursor.getSurroundingTextOffset();
if (cursor) {
const surroundingText = cursor.getSurroundingText().getText();
const surroundingTextOffset = cursor.getSurroundingTextOffset();

// If the cursor follows or preceds a non-space character, insert a space
// between the character and the translation. Otherwise, just insert the
// translation.
if (surroundingTextOffset > 0) {
if (surroundingText.charAt(surroundingTextOffset - 1) !== ' ') {
newText = ' ' + newText;
// If the cursor follows or preceds a non-space character, insert a space
// between the character and the translation. Otherwise, just insert the
// translation.
if (surroundingTextOffset > 0) {
if (surroundingText.charAt(surroundingTextOffset - 1) !== ' ') {
newText = ' ' + newText;
}
}
}
if (surroundingTextOffset < surroundingText.length) {
if (surroundingText.charAt(surroundingTextOffset) !== ' ') {
newText += ' ';
if (surroundingTextOffset < surroundingText.length) {
if (surroundingText.charAt(surroundingTextOffset) !== ' ') {
newText += ' ';
}
}
cursor.insertText(newText);
}
cursor.insertText(newText);
}
}

Expand Down
Loading