From a11c195ea4101ab0a729ce69ecbd809ea06ce263 Mon Sep 17 00:00:00 2001 From: Zsolt Viczian Date: Sun, 6 Feb 2022 23:33:30 +0100 Subject: [PATCH] scribble script --- ea-scripts/Scribble Helper.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ea-scripts/Scribble Helper.md diff --git a/ea-scripts/Scribble Helper.md b/ea-scripts/Scribble Helper.md new file mode 100644 index 0000000..89fe810 --- /dev/null +++ b/ea-scripts/Scribble Helper.md @@ -0,0 +1,29 @@ +/* +![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-scribble-helper.jpg) + +iOS scribble helper for better handwriting experience with text elements. If no elements are selected then the creates a text element at pointer position and you can use the edit box to modify the text with scribble. If a text element is selected then opens the input prompt where you can modify this text with scribble. + +```javascript +*/ + + +elements = ea.getViewSelectedElements().filter(el=>el.type==="text"); +if(elements.length > 1) { + new Notice ("Select only 1 or 0 text elements.") + return; +} + +const text = await utils.inputPrompt("Edit text","",(elements.length === 1)?elements[0].rawText:""); +if(!text) return; + +if(elements.length === 1) { + ea.copyViewElementsToEAforEditing(elements); + ea.getElements()[0].originalText = text; + ea.getElements()[0].text = text; + ea.getElements()[0].rawText = text; + await ea.addElementsToView(false,true); + return; +} + +ea.addText(0,0,text); +await ea.addElementsToView(true, true, true);