Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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,11 +74,11 @@

/**
* Gets information about a given element.
* @param {Element} element The element.
* @param {Object} element The element.
* @return {Object} The information.
*/
function getElementInfo(element) {
return {
type: String(element.getType())

Check failure on line 82 in docs/cursorInspector/cursorInspector.gs

View workflow job for this annotation

GitHub Actions / test (docs)

Property 'getType' does not exist on type 'Object'.
};
}
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]
46 changes: 25 additions & 21 deletions docs/translate/translate.gs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
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 (element.getType() === DocumentApp.ElementType.TEXT) {
const elementText = element.asText().getText();
// This check is necessary to exclude images, which return a blank
// text element.
Expand Down Expand Up @@ -190,42 +190,46 @@
}
} else {
const element = elements[i].getElement();
if (!replaced && element.editAsText) {
// Only translate elements that can be edited as text, removing other
// elements.
element.clear();
element.asText().setText(newText);
// Only translate elements that can be edited as text; skip images and
// other non-text elements.
const type = element.getType();
if (!replaced && type === DocumentApp.ElementType.TEXT) {
const textElement = element.asText();
textElement.clear();

Check failure on line 198 in docs/translate/translate.gs

View workflow job for this annotation

GitHub Actions / test (docs)

Property 'clear' does not exist on type 'Text'.
textElement.setText(newText);
replaced = true;
} else {
// We cannot remove the last paragraph of a doc. If this is the case,
// just clear the element.
if (element.getNextSibling()) {
element.removeFromParent();
} else {
element.clear();
} else if (type === DocumentApp.ElementType.TEXT) {
element.asText().clear();

Check failure on line 207 in docs/translate/translate.gs

View workflow job for this annotation

GitHub Actions / test (docs)

Property 'clear' does not exist on type 'Text'.
}
}
}
}
} 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