static/README.wasm.md | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-)
New commits: commit b4f416abc245ae63c164d51ee9fd4d4c849e0411 Author: Stephan Bergmann <stephan.bergm...@allotropia.de> AuthorDate: Tue Jun 4 17:04:14 2024 +0200 Commit: Stephan Bergmann <stephan.bergm...@allotropia.de> CommitDate: Wed Jun 5 08:08:58 2024 +0200 Clean up example code * Consistently use `const` to introduce variable bindings. * Don't rely on `xText` from the first example in the second one. * No (more) need to query for base interfaces. * No (more) need to delete interface references. * Add a missing delete of Any `next`. * Remove a redundant empty line. * Adapt to our 100 character line width. Change-Id: Ie116021a4b0cc6d88c6204e7ea5147a837c251f5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168405 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de> diff --git a/static/README.wasm.md b/static/README.wasm.md index 5a247b085a0d..c07c3a9a389c 100644 --- a/static/README.wasm.md +++ b/static/README.wasm.md @@ -210,35 +210,32 @@ improvement! ;) Some usage examples through javascript of the current implementation: ```js // inserts a string at the start of the Writer document. -let uno = init_unoembind_uno(Module); -let css = uno.com.sun.star; -xModel = Module.getCurrentModelFromViewSh(); -xTextDocument = css.text.XTextDocument.query(xModel); -xText = xTextDocument.getText(); -xSimpleText = css.text.XSimpleText.query(xText); -xTextCursor = xSimpleText.createTextCursor(); -xTextRange = css.text.XTextRange.query(xTextCursor); -xTextRange.setString("string here!"); -xModel.delete(); xTextDocument.delete(); xText.delete(); xSimpleText.delete(); xTextCursor.delete(); xTextRange.delete(); +const uno = init_unoembind_uno(Module); +const css = uno.com.sun.star; +const xModel = Module.getCurrentModelFromViewSh(); +const xTextDocument = css.text.XTextDocument.query(xModel); +const xText = xTextDocument.getText(); +const xTextCursor = xText.createTextCursor(); +xTextCursor.setString("string here!"); ``` ```js // changes each paragraph of the Writer document to a random color. -let uno = init_unoembind_uno(Module); -let css = uno.com.sun.star; -xModel = Module.getCurrentModelFromViewSh(); -xEnumAccess = css.container.XEnumerationAccess.query(xText); -xParaEnumeration = xEnumAccess.createEnumeration(); - +const uno = init_unoembind_uno(Module); +const css = uno.com.sun.star; +const xModel = Module.getCurrentModelFromViewSh(); +const xTextDocument = css.text.XTextDocument.query(xModel); +const xText = xTextDocument.getText(); +const xEnumAccess = css.container.XEnumerationAccess.query(xText); +const xParaEnumeration = xEnumAccess.createEnumeration(); while (xParaEnumeration.hasMoreElements()) { - xParagraph = css.text.XTextRange.query(xParaEnumeration.nextElement().get()); - if (xParagraph !== null) { - xParaProps = css.beans.XPropertySet.query(xParagraph); - let color = new Module.uno_Any( - Module.uno_Type.Long(), Math.floor(Math.random() * 0xFFFFFF)); - xParaProps.setPropertyValue("CharColor", color); - color.delete(); - } + const next = xParaEnumeration.nextElement(); + const xParagraph = css.text.XTextRange.query(next.get()); + const xParaProps = css.beans.XPropertySet.query(xParagraph); + const color = new Module.uno_Any(Module.uno_Type.Long(), Math.floor(Math.random() * 0xFFFFFF)); + xParaProps.setPropertyValue("CharColor", color); + next.delete(); + color.delete(); } ```