diff --git a/ea-scripts/Scribble Helper.md b/ea-scripts/Scribble Helper.md index adb3bde..cebd551 100644 --- a/ea-scripts/Scribble Helper.md +++ b/ea-scripts/Scribble Helper.md @@ -5,58 +5,39 @@ iOS scribble helper for better handwriting experience with text elements. If no ```javascript */ -//const helpLINK = "https://youtu.be/MIZ5hv-pSSs"; -const DBLCLICKTIMEOUT = 300; -const maxWidth = 600; -const padding = 6; - if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.8.24")) { new Notice("This script requires a newer version of Excalidraw. Please install the latest version."); return; } +//const helpLINK = "https://youtu.be/MIZ5hv-pSSs"; +const DBLCLICKTIMEOUT = 300; +const maxWidth = 600; +const padding = 6; const api = ea.getExcalidrawAPI(); const win = ea.targetView.ownerWindow; if(!win.ExcalidrawScribbleHelper) win.ExcalidrawScribbleHelper = {}; - -// if a single element is selected when the action is started, update that existing text -let containerElements = ea.getViewSelectedElements().filter(el=>["arrow","rectangle","ellipse","line","diamond"].contains(el.type)); -let selectedTextElements = ea.getViewSelectedElements().filter(el=>el.type==="text"); - -const addEventHandler = (handler) => { - win.addEventListener("pointerdown",handler); - win.ExcalidrawScribbleHelper.eventHandler = handler; -} - -const removeEventHandler = (handler) => { - win.removeEventListener("pointerdown",handler); - delete win.ExcalidrawScribbleHelper.eventHandler; -} - -let silent = false; -if (win.ExcalidrawScribbleHelper?.eventHandler) { - removeEventHandler(win.ExcalidrawScribbleHelper.eventHandler); - delete win.ExcalidrawScribbleHelper.eventHandler; - if(!(containerElements.length === 1 || selectedTextElements.length === 1)) { - new Notice ("Scribble Helper stopped"); - return; - } - silent = true; +if(typeof win.ExcalidrawScribbleHelper.penOnly === "undefined") { + win.ExcalidrawScribbleHelper.penOnly = false; } +let windowOpen = false; //to prevent the modal window to open again while writing with scribble +let prevZoomValue = api.getAppState().zoom.value; //used to avoid trigger on pinch zoom // ------------- // Load settings // ------------- const settings = ea.getScriptSettings(); - -//set default values on first run +//set default values on first-ever run of the script if(typeof win.ExcalidrawScribbleHelper.action === "undefined") { if(!settings["Default action"]) { settings = { "Default action" : { value: "Text", valueset: ["Text","Sticky","Wrap"], - description: "What type of element should CTRL/CMD+ENTER create. TEXT: A regular text element. STICKY: A sticky note with border color and background color (using the current setting of the canvas). STICKY: A sticky note with transparent border and background color." + description: "What type of element should CTRL/CMD+ENTER create. TEXT: A regular text element. " + + "STICKY: A sticky note with border color and background color " + + "(using the current setting of the canvas). STICKY: A sticky note with transparent " + + "border and background color." }, }; await ea.setScriptSettings(settings); @@ -64,49 +45,143 @@ if(typeof win.ExcalidrawScribbleHelper.action === "undefined") { win.ExcalidrawScribbleHelper.action = settings["Default action"].value; } -// -------------- -// Repeat options -// -------------- -if (typeof win.ExcalidrawScribbleHelper.sticky === "undefined") win.ExcalidrawScribbleHelper.sticky = true; //if true the user can click the screen again to create the next text element -if (typeof win.ExcalidrawScribbleHelper.penOnly === "undefined") win.ExcalidrawScribbleHelper.penOnly = undefined; -if (typeof win.ExcalidrawScribbleHelper.penDetected === "undefined") win.ExcalidrawScribbleHelper.penDetected = false; +//--------------------------------------- +// Color Palette for stroke color setting +//--------------------------------------- +// https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/1.6.8 +const defaultStrokeColors = [ + "#000000", "#343a40", "#495057", "#c92a2a", "#a61e4d", + "#862e9c", "#5f3dc4", "#364fc7", "#1864ab", "#0b7285", + "#087f5b", "#2b8a3e", "#5c940d", "#e67700", "#d9480f" + ]; + +const loadColorPalette = () => { + const st = api.getAppState(); + const strokeColors = new Set(); + let strokeColorPalette = st.colorPalette?.elementStroke ?? defaultStrokeColors; + if(Object.entries(strokeColorPalette).length === 0) { + strokeColorPalette = defaultStrokeColors; + } + + ea.getViewElements().forEach(el => { + if(el.strokeColor.toLowerCase()==="transparent") return; + strokeColors.add(el.strokeColor); + }); + + strokeColorPalette.forEach(color => { + strokeColors.add(color) + }); + + strokeColors.add(st.currentItemStrokeColor ?? ea.style.strokeColor); + return strokeColors; +} + +//---------------------------------------------------------- +// Define variables to cache element location on first click +//---------------------------------------------------------- +// if a single element is selected when the action is started, update that existing text +let containerElements = ea.getViewSelectedElements() + .filter(el=>["arrow","rectangle","ellipse","line","diamond"].contains(el.type)); +let selectedTextElements = ea.getViewSelectedElements().filter(el=>el.type==="text"); + +let textLocationCache = {}; +//Address text jumping on mobile when keyboard is popping up +//This should really be solved in the core product, but that is not yet happening +const cacheTextElCoords = () => { + if(selectedTextElements.length === 1) { + textLocationCache.x = selectedTextElements[0].x; + textLocationCache.y = selectedTextElements[0].y; + return; + } + delete textLocationCache.x; + delete textLocationCache.y; +} +const isLocationCacheValid = () => !(typeof textLocationCache.x === "undefined"); +cacheTextElCoords(); + +//------------------------------------------- +// Functions to add and remove event listners +//------------------------------------------- +const addEventHandler = (handler) => { + if(win.ExcalidrawScribbleHelper.eventHandler) { + win.removeEventListner("pointerdown", handler); + } + win.addEventListener("pointerdown",handler); + win.ExcalidrawScribbleHelper.eventHandler = handler; + win.ExcalidrawScribbleHelper.window = win; +} + +const removeEventHandler = (handler) => { + win.removeEventListener("pointerdown",handler); + delete win.ExcalidrawScribbleHelper.eventHandler; + delete win.ExcalidrawScribbleHelper.window; +} + +//Stop the script if scribble helper is clicked and no eligable element is selected +let silent = false; +if (win.ExcalidrawScribbleHelper?.eventHandler) { + removeEventHandler(win.ExcalidrawScribbleHelper.eventHandler); + delete win.ExcalidrawScribbleHelper.eventHandler; + delete win.ExcalidrawScribbleHelper.window; + if(!(containerElements.length === 1 || selectedTextElements.length === 1)) { + new Notice ("Scribble Helper was stopped"); + return; + } + silent = true; +} + +// ---------------------- +// Custom dialog controls +// ---------------------- +if (typeof win.ExcalidrawScribbleHelper.penOnly === "undefined") { + win.ExcalidrawScribbleHelper.penOnly = undefined; +} +if (typeof win.ExcalidrawScribbleHelper.penDetected === "undefined") { + win.ExcalidrawScribbleHelper.penDetected = false; +} let timer = Date.now(); let eventHandler = () => {}; -const repeatOptions = (container) => { +const customControls = (container) => { //const helpDIV = container.createDiv(); //helpDIV.innerHTML = `Click here for help`; + const viewBackground = api.getAppState().viewBackgroundColor; const el1 = new ea.obsidian.Setting(container) - .setName("Continue adding text") - .addToggle((toggle) => - toggle - .setValue(win.ExcalidrawScribbleHelper.sticky) + .setName(`Text color`) + .addDropdown(dropdown => { + Array.from(loadColorPalette()).forEach(color => { + const options = dropdown.addOption(color, color).selectEl.options; + options[options.length-1].setAttribute("style",`color: ${color + }; background: ${viewBackground};`); + }); + dropdown + .setValue(ea.style.strokeColor) .onChange(value => { - win.ExcalidrawScribbleHelper.sticky = value; - if(value && !win.ExcalidrawScribbleHelper?.eventHandler) addEventHandler(eventHandler); - if(!value && win.ExcalidrawScribbleHelper?.eventHandler) removeEventHandler(win.ExcalidrawScribbleHelper.eventHanlder); - el2.settingEl.style.display = value && win.ExcalidrawScribbleHelper.penDetected ? "" : "none"; + ea.style.strokeColor = value; + el1.nameEl.style.color = value; }) - ); - el1.settingEl.style.border = "none"; - + }) + el1.nameEl.style.color = ea.style.strokeColor; + el1.nameEl.style.background = viewBackground; + el1.nameEl.style.fontWeight = "bold"; + const el2 = new ea.obsidian.Setting(container) .setName(`Trigger editor by pen double tap only`) - .addToggle((toggle) => - toggle - .setValue(win.ExcalidrawScribbleHelper.penOnly) - .onChange(value => { - win.ExcalidrawScribbleHelper.penOnly = value; - }) + .addToggle((toggle) => toggle + .setValue(win.ExcalidrawScribbleHelper.penOnly) + .onChange(value => { + win.ExcalidrawScribbleHelper.penOnly = value; + }) ) el2.settingEl.style.border = "none"; - el2.settingEl.style.display = win.ExcalidrawScribbleHelper.sticky && win.ExcalidrawScribbleHelper.penDetected ? "" : "none"; + el2.settingEl.style.display = win.ExcalidrawScribbleHelper.penDetected ? "" : "none"; } // ------------------------------- // Click / dbl click event handler // ------------------------------- eventHandler = async (evt) => { + if(windowOpen) return; if(ea.targetView !== app.workspace.activeLeaf.view) removeEventHandler(eventHandler); if(evt && (evt.ctrlKey || evt.altKey || evt.metaKey || evt.shiftKey)) return; const st = api.getAppState(); @@ -118,20 +193,28 @@ eventHandler = async (evt) => { win.ExcalidrawScribbleHelper.penOnly = false; } - if(evt && win.ExcalidrawScribbleHelper.penOnly && win.ExcalidrawScribbleHelper.penDetected && evt.pointerType !== "pen") return; + if (evt && win.ExcalidrawScribbleHelper.penOnly && + win.ExcalidrawScribbleHelper.penDetected && evt.pointerType !== "pen") return; const now = Date.now(); - if((now-timer > DBLCLICKTIMEOUT) || (now-timer < 50)) { - timer = now; - containerElements = ea.getViewSelectedElements().filter(el=>["arrow","rectangle","ellipse","line","diamond"].contains(el.type)); - selectedTextElements = ea.getViewSelectedElements().filter(el=>el.type==="text"); - return; - } - //removeEventHandler(eventHandler); - await sleep(300); //sleeping to allow keyboard to pop up on mobile devices + //the <50 condition is to avoid false double click when pinch zooming + if((now-timer > DBLCLICKTIMEOUT) || (now-timer < 50)) { + prevZoomValue = st.zoom.value; + timer = now; + containerElements = ea.getViewSelectedElements() + .filter(el=>["arrow","rectangle","ellipse","line","diamond"].contains(el.type)); + selectedTextElements = ea.getViewSelectedElements().filter(el=>el.type==="text"); + return; + } + //further safeguard against triggering when pinch zooming + if(st.zoom.value !== prevZoomValue) return; + + //sleeping to allow keyboard to pop up on mobile devices + await sleep(200); ea.clear(); - //if a single element with text is selected, edit the text (this can be an arrow, a sticky note, or just a text element) + //if a single element with text is selected, edit the text + //(this can be an arrow, a sticky note, or just a text element) if(selectedTextElements.length === 1) { editExistingTextElement(selectedTextElements); return; @@ -139,7 +222,8 @@ eventHandler = async (evt) => { let containerID; let container; - //if no text elements are selected (i.e. not multiple text elements selected), check if there is a single eligeable container selected + //if no text elements are selected (i.e. not multiple text elements selected), + //check if there is a single eligeable container selected if(selectedTextElements.length === 0) { if(containerElements.length === 1) { ea.copyViewElementsToEAforEditing(containerElements); @@ -148,33 +232,74 @@ eventHandler = async (evt) => { } } - const {x,y} = ea.targetView.currentPosition + const {x,y} = ea.targetView.currentPosition; if(ea.targetView !== app.workspace.activeLeaf.view) return; const actionButtons = [ - {caption: `A`, tooltip: "Add as Text Element", action: ()=>{win.ExcalidrawScribbleHelper.action="Text";if(settings["Default action"].value!=="Text") {settings["Default action"].value = "Text"; ea.setScriptSettings(settings);}; return;}}, - {caption: "📝", tooltip: "Add as Sticky Note (rectangle with border color and background color)", action: ()=>{win.ExcalidrawScribbleHelper.action="Sticky";if(settings["Default action"].value!=="Sticky") {settings["Default action"].value = "Sticky"; ea.setScriptSettings(settings);};return;}}, - {caption: "☱", tooltip: "Add as Wrapped Text (rectangle with transparent border and background)", action: ()=>{win.ExcalidrawScribbleHelper.action="Wrap";if(settings["Default action"].value!=="Wrap") {settings["Default action"].value = "Wrap"; ea.setScriptSettings(settings);};return;}} + { + caption: `A`, + tooltip: "Add as Text Element", + action: () => { + win.ExcalidrawScribbleHelper.action="Text"; + if(settings["Default action"].value!=="Text") { + settings["Default action"].value = "Text"; + ea.setScriptSettings(settings); + }; + return; + } + }, + { + caption: "📝", + tooltip: "Add as Sticky Note (rectangle with border color and background color)", + action: () => { + win.ExcalidrawScribbleHelper.action="Sticky"; + if(settings["Default action"].value!=="Sticky") { + settings["Default action"].value = "Sticky"; + ea.setScriptSettings(settings); + }; + return; + } + }, + { + caption: "☱", + tooltip: "Add as Wrapped Text (rectangle with transparent border and background)", + action: () => { + win.ExcalidrawScribbleHelper.action="Wrap"; + if(settings["Default action"].value!=="Wrap") { + settings["Default action"].value = "Wrap"; + ea.setScriptSettings(settings); + }; + return; + } + } ]; if(win.ExcalidrawScribbleHelper.action !== "Text") actionButtons.push(actionButtons.shift()); if(win.ExcalidrawScribbleHelper.action === "Wrap") actionButtons.push(actionButtons.shift()); - const text = await utils.inputPrompt ("Edit text", "", "", containerID?undefined:actionButtons, 5, true, repeatOptions); - - if(!text || text.trim() === "") return; - ea.style.strokeColor = st.currentItemStrokeColor ?? ea.style.strokeColor; ea.style.backgroundColor = st.currentItemBackgroundColor ?? ea.style.backgroundColor; ea.style.fillStyle = st.currentItemFillStyle ?? ea.style.fillStyle; ea.style.fontFamily = st.currentItemFontFamily ?? ea.style.fontFamily; ea.style.fontSize = st.currentItemFontSize ?? ea.style.fontSize; - ea.style.textAlign = (container && ["arrow","line"].contains(container.type)) ? "center" : st.currentItemTextAlign ?? ea.style.textAlign; - ea.style.verticalAlign = (container && ["arrow","line"].contains(container.type)) ? "middle" : ea.style.verticalAlign; + ea.style.textAlign = (container && ["arrow","line"].contains(container.type)) + ? "center" + : st.currentItemTextAlign ?? ea.style.textAlign; + ea.style.verticalAlign = (container && ["arrow","line"].contains(container.type)) + ? "middle" + : ea.style.verticalAlign; - const textId = ea.addText(x,y, text) + windowOpen = true; + const text = await utils.inputPrompt ( + "Edit text", "", "", containerID?undefined:actionButtons, 5, true, customControls + ); + windowOpen = false; + + if(!text || text.trim() === "") return; + + const textId = ea.addText(x,y, text); if (!container && (win.ExcalidrawScribbleHelper.action === "Text")) { ea.addElementsToView(false, false, true); - if(win.ExcalidrawScribbleHelper.sticky) win.addEventListener("pointerdown",eventHandler); + addEventHandler(eventHandler); return; } const textEl = ea.getElement(textId); @@ -195,13 +320,17 @@ eventHandler = async (evt) => { cy = container.y + dy*container.height/2; textEl.x = cx - textEl.width/2; textEl.y = cy - textEl.height/2; - console.log(container.x, container.width, container.y, container.height, textEl.width, textEl.height, textEl.x, textEl.y); } if(!container) { const width = textEl.width+2*padding; const widthOK = width<=maxWidth; - containerID = ea.addRect(textEl.x-padding,textEl.y-padding,widthOK?width:maxWidth,textEl.height+2*padding); + containerID = ea.addRect( + textEl.x-padding, + textEl.y-padding, + widthOK ? width : maxWidth, + textEl.height + 2 * padding + ); container = ea.getElement(containerID); } boxes.push(containerID); @@ -212,17 +341,28 @@ eventHandler = async (evt) => { const containers = ea.getViewElements().filter(el=>boxes.includes(el.id)); if(["rectangle","diamond","ellipse"].includes(container.type)) api.updateContainerSize(containers); ea.selectElementsInView(containers); - //if(sticky) addEventHandler(eventHandler); }; // --------------------- // Edit Existing Element // --------------------- const editExistingTextElement = async (elements) => { - const text = await utils.inputPrompt("Edit text","",elements[0].rawText,undefined,5,true,repeatOptions); - if(!text) return; + windowOpen = true; ea.copyViewElementsToEAforEditing(elements); const el = ea.getElements()[0]; + //this is a hack to address jumping text + if(isLocationCacheValid()) { + el.x = textLocationCache.x; + el.y = textLocationCache.y; + } + ea.style.strokeColor = el.strokeColor; + const text = await utils.inputPrompt( + "Edit text","",elements[0].rawText,undefined,5,true,customControls + ); + windowOpen = false; + if(!text) return; + + el.strokeColor = ea.style.strokeColor; el.originalText = text; el.text = text; el.rawText = text; @@ -233,11 +373,17 @@ const editExistingTextElement = async (elements) => { api.updateContainerSize(containers); ea.selectElementsInView(containers); } - //if(sticky) addEventHandler(eventHandler); } -if(!win.ExcalidrawScribbleHelper?.eventHandler && win.ExcalidrawScribbleHelper.sticky) { - if(!silent) new Notice("Double click the screen to create a new text element, or double click an element to add or edit text"); +//-------------- +// Start actions +//-------------- +if(!win.ExcalidrawScribbleHelper?.eventHandler) { + if(!silent) new Notice( + "Double click the screen to create a new text element, " + + "or double click an element to add or edit text\nClick the script again or move to " + + "another Obsidian-tab to stop the script" + ); addEventHandler(eventHandler); } diff --git a/ea-scripts/directory-info.json b/ea-scripts/directory-info.json index 996badf..dc429f7 100644 --- a/ea-scripts/directory-info.json +++ b/ea-scripts/directory-info.json @@ -1 +1 @@ -[{"fname":"Mindmap connector.md","mtime":1658686599427},{"fname":"Mindmap connector.svg","mtime":1658686599427},{"fname":"Add Connector Point.md","mtime":1645305706000},{"fname":"Add Connector Point.svg","mtime":1645944722000},{"fname":"Add Link to Existing File and Open.md","mtime":1647807918345},{"fname":"Add Link to Existing File and Open.svg","mtime":1645964261000},{"fname":"Add Link to New Page and Open.md","mtime":1654168862138},{"fname":"Add Link to New Page and Open.svg","mtime":1645960639000},{"fname":"Add Next Step in Process.md","mtime":1645305706000},{"fname":"Add Next Step in Process.svg","mtime":1645960639000},{"fname":"Box Each Selected Groups.md","mtime":1645305706000},{"fname":"Box Each Selected Groups.svg","mtime":1645967510000},{"fname":"Box Selected Elements.md","mtime":1645305706000},{"fname":"Box Selected Elements.svg","mtime":1645960639000},{"fname":"Change shape of selected elements.md","mtime":1652701169236},{"fname":"Change shape of selected elements.svg","mtime":1645960775000},{"fname":"Connect elements.md","mtime":1645305706000},{"fname":"Connect elements.svg","mtime":1645960639000},{"fname":"Convert freedraw to line.md","mtime":1645305706000},{"fname":"Convert freedraw to line.svg","mtime":1645960639000},{"fname":"Convert selected text elements to sticky notes.md","mtime":1670169501383},{"fname":"Convert selected text elements to sticky notes.svg","mtime":1645960639000},{"fname":"Convert text to link with folder and alias.md","mtime":1641639819000},{"fname":"Convert text to link with folder and alias.svg","mtime":1645960639000},{"fname":"Copy Selected Element Styles to Global.md","mtime":1642232088000},{"fname":"Copy Selected Element Styles to Global.svg","mtime":1645960639000},{"fname":"Create new markdown file and embed into active drawing.md","mtime":1640866935000},{"fname":"Create new markdown file and embed into active drawing.svg","mtime":1645960639000},{"fname":"Darken background color.md","mtime":1663059051059},{"fname":"Darken background color.svg","mtime":1645960639000},{"fname":"Elbow connectors.md","mtime":1671126911490},{"fname":"Elbow connectors.svg","mtime":1645960639000},{"fname":"Expand rectangles horizontally keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles horizontally keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles horizontally.md","mtime":1644950235000},{"fname":"Expand rectangles horizontally.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles vertically keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically.md","mtime":1658686599427},{"fname":"Expand rectangles vertically.svg","mtime":1645967510000},{"fname":"Fixed horizontal distance between centers.md","mtime":1646743234000},{"fname":"Fixed horizontal distance between centers.svg","mtime":1645960639000},{"fname":"Fixed inner distance.md","mtime":1646743234000},{"fname":"Fixed inner distance.svg","mtime":1645960639000},{"fname":"Fixed spacing.md","mtime":1646743234000},{"fname":"Fixed spacing.svg","mtime":1645967510000},{"fname":"Fixed vertical distance between centers.md","mtime":1646743234000},{"fname":"Fixed vertical distance between centers.svg","mtime":1645967510000},{"fname":"Fixed vertical distance.md","mtime":1646743234000},{"fname":"Fixed vertical distance.svg","mtime":1645967510000},{"fname":"Lighten background color.md","mtime":1663059051059},{"fname":"Lighten background color.svg","mtime":1645959546000},{"fname":"Modify background color opacity.md","mtime":1644924415000},{"fname":"Modify background color opacity.svg","mtime":1645944722000},{"fname":"Normalize Selected Arrows.md","mtime":1670403743278},{"fname":"Normalize Selected Arrows.svg","mtime":1645960639000},{"fname":"Organic Line.md","mtime":1672920172531},{"fname":"Organic Line.svg","mtime":1645964261000},{"fname":"README.md","mtime":1645175700000},{"fname":"Repeat Elements.md","mtime":1663059051059},{"fname":"Repeat Elements.svg","mtime":1645960639000},{"fname":"Reverse arrows.md","mtime":1645305706000},{"fname":"Reverse arrows.svg","mtime":1645960639000},{"fname":"Scribble Helper.md","mtime":1681757673249},{"fname":"Scribble Helper.svg","mtime":1645944722000},{"fname":"Select Elements of Type.md","mtime":1643464321000},{"fname":"Select Elements of Type.svg","mtime":1645960639000},{"fname":"Set Dimensions.md","mtime":1645305706000},{"fname":"Set Dimensions.svg","mtime":1645944722000},{"fname":"Set Font Family.md","mtime":1645305706000},{"fname":"Set Font Family.svg","mtime":1645944722000},{"fname":"Set Grid.md","mtime":1674326971324},{"fname":"Set Grid.svg","mtime":1645960639000},{"fname":"Set Link Alias.md","mtime":1645305706000},{"fname":"Set Link Alias.svg","mtime":1645960639000},{"fname":"Set Stroke Width of Selected Elements.md","mtime":1645305706000},{"fname":"Set Stroke Width of Selected Elements.svg","mtime":1645960639000},{"fname":"Set Text Alignment.md","mtime":1645305706000},{"fname":"Set Text Alignment.svg","mtime":1645960639000},{"fname":"Set background color of unclosed line object by adding a shadow clone.md","mtime":1681665030892},{"fname":"Set background color of unclosed line object by adding a shadow clone.svg","mtime":1645960639000},{"fname":"Split text by lines.md","mtime":1645305706000},{"fname":"Split text by lines.svg","mtime":1645944722000},{"fname":"Zoom to Fit Selected Elements.md","mtime":1640770602000},{"fname":"Zoom to Fit Selected Elements.svg","mtime":1645960639000},{"fname":"directory-info.json","mtime":1646583437000},{"fname":"index-new.md","mtime":1645986149000},{"fname":"index.md","mtime":1645175700000},{"fname":"Grid Selected Images.md","mtime":1649614401982},{"fname":"Grid Selected Images.svg","mtime":1649614401982},{"fname":"Palette loader.md","mtime":1662992295615},{"fname":"Palette loader.svg","mtime":1649614401982},{"fname":"Rename Image.md","mtime":1663678478785},{"fname":"Rename Image.svg","mtime":1663678478785},{"fname":"Text Arch.md","mtime":1664095143846},{"fname":"Text Arch.svg","mtime":1670403743278},{"fname":"Deconstruct selected elements into new drawing.md","mtime":1672672112439},{"fname":"Deconstruct selected elements into new drawing.svg","mtime":1668541145255},{"fname":"Slideshow.md","mtime":1680418321236},{"fname":"Slideshow.svg","mtime":1670017348333},{"fname":"Auto Layout.md","mtime":1670403743278},{"fname":"Auto Layout.svg","mtime":1670175947081},{"fname":"Uniform size.md","mtime":1670175947081},{"fname":"Uniform size.svg","mtime":1670175947081},{"fname":"Alternative Pens.md", "mtime":1672942234020},{"fname":"Alternative Pens.svg", "mtime":1672942234020},{"fname":"Mindmap format.md","mtime":1674944958059},{"fname":"Mindmap format.svg","mtime":1674944958059},{"fname":"Text to Sticky Notes.md","mtime":1678537561724},{"fname":"Text to Sticky Notes.svg","mtime":1678537561724},{"fname":"Folder Note Core - Make Current Drawing a Folder.md","mtime":1678973697470},{"fname":"Folder Note Core - Make Current Drawing a Folder.svg","mtime":1678973697470},{"fname":"Invert colors.md","mtime":1678973697470},{"fname":"Invert colors.svg","mtime":1678973697470},{"fname":"Auto Draw for Pen.md","mtime":1680418321236},{"fname":"Auto Draw for Pen.svg","mtime":1680418321236},{"fname":"Hardware Eraser Support.md","mtime":1680418321236},{"fname":"Hardware Eraser Support.svg","mtime":1680418321236}] +[{"fname":"Mindmap connector.md","mtime":1658686599427},{"fname":"Mindmap connector.svg","mtime":1658686599427},{"fname":"Add Connector Point.md","mtime":1645305706000},{"fname":"Add Connector Point.svg","mtime":1645944722000},{"fname":"Add Link to Existing File and Open.md","mtime":1647807918345},{"fname":"Add Link to Existing File and Open.svg","mtime":1645964261000},{"fname":"Add Link to New Page and Open.md","mtime":1654168862138},{"fname":"Add Link to New Page and Open.svg","mtime":1645960639000},{"fname":"Add Next Step in Process.md","mtime":1645305706000},{"fname":"Add Next Step in Process.svg","mtime":1645960639000},{"fname":"Box Each Selected Groups.md","mtime":1645305706000},{"fname":"Box Each Selected Groups.svg","mtime":1645967510000},{"fname":"Box Selected Elements.md","mtime":1645305706000},{"fname":"Box Selected Elements.svg","mtime":1645960639000},{"fname":"Change shape of selected elements.md","mtime":1652701169236},{"fname":"Change shape of selected elements.svg","mtime":1645960775000},{"fname":"Connect elements.md","mtime":1645305706000},{"fname":"Connect elements.svg","mtime":1645960639000},{"fname":"Convert freedraw to line.md","mtime":1645305706000},{"fname":"Convert freedraw to line.svg","mtime":1645960639000},{"fname":"Convert selected text elements to sticky notes.md","mtime":1670169501383},{"fname":"Convert selected text elements to sticky notes.svg","mtime":1645960639000},{"fname":"Convert text to link with folder and alias.md","mtime":1641639819000},{"fname":"Convert text to link with folder and alias.svg","mtime":1645960639000},{"fname":"Copy Selected Element Styles to Global.md","mtime":1642232088000},{"fname":"Copy Selected Element Styles to Global.svg","mtime":1645960639000},{"fname":"Create new markdown file and embed into active drawing.md","mtime":1640866935000},{"fname":"Create new markdown file and embed into active drawing.svg","mtime":1645960639000},{"fname":"Darken background color.md","mtime":1663059051059},{"fname":"Darken background color.svg","mtime":1645960639000},{"fname":"Elbow connectors.md","mtime":1671126911490},{"fname":"Elbow connectors.svg","mtime":1645960639000},{"fname":"Expand rectangles horizontally keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles horizontally keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles horizontally.md","mtime":1644950235000},{"fname":"Expand rectangles horizontally.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles vertically keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically.md","mtime":1658686599427},{"fname":"Expand rectangles vertically.svg","mtime":1645967510000},{"fname":"Fixed horizontal distance between centers.md","mtime":1646743234000},{"fname":"Fixed horizontal distance between centers.svg","mtime":1645960639000},{"fname":"Fixed inner distance.md","mtime":1646743234000},{"fname":"Fixed inner distance.svg","mtime":1645960639000},{"fname":"Fixed spacing.md","mtime":1646743234000},{"fname":"Fixed spacing.svg","mtime":1645967510000},{"fname":"Fixed vertical distance between centers.md","mtime":1646743234000},{"fname":"Fixed vertical distance between centers.svg","mtime":1645967510000},{"fname":"Fixed vertical distance.md","mtime":1646743234000},{"fname":"Fixed vertical distance.svg","mtime":1645967510000},{"fname":"Lighten background color.md","mtime":1663059051059},{"fname":"Lighten background color.svg","mtime":1645959546000},{"fname":"Modify background color opacity.md","mtime":1644924415000},{"fname":"Modify background color opacity.svg","mtime":1645944722000},{"fname":"Normalize Selected Arrows.md","mtime":1670403743278},{"fname":"Normalize Selected Arrows.svg","mtime":1645960639000},{"fname":"Organic Line.md","mtime":1672920172531},{"fname":"Organic Line.svg","mtime":1645964261000},{"fname":"README.md","mtime":1645175700000},{"fname":"Repeat Elements.md","mtime":1663059051059},{"fname":"Repeat Elements.svg","mtime":1645960639000},{"fname":"Reverse arrows.md","mtime":1645305706000},{"fname":"Reverse arrows.svg","mtime":1645960639000},{"fname":"Scribble Helper.md","mtime":1682048822687},{"fname":"Scribble Helper.svg","mtime":1645944722000},{"fname":"Select Elements of Type.md","mtime":1643464321000},{"fname":"Select Elements of Type.svg","mtime":1645960639000},{"fname":"Set Dimensions.md","mtime":1645305706000},{"fname":"Set Dimensions.svg","mtime":1645944722000},{"fname":"Set Font Family.md","mtime":1645305706000},{"fname":"Set Font Family.svg","mtime":1645944722000},{"fname":"Set Grid.md","mtime":1674326971324},{"fname":"Set Grid.svg","mtime":1645960639000},{"fname":"Set Link Alias.md","mtime":1645305706000},{"fname":"Set Link Alias.svg","mtime":1645960639000},{"fname":"Set Stroke Width of Selected Elements.md","mtime":1645305706000},{"fname":"Set Stroke Width of Selected Elements.svg","mtime":1645960639000},{"fname":"Set Text Alignment.md","mtime":1645305706000},{"fname":"Set Text Alignment.svg","mtime":1645960639000},{"fname":"Set background color of unclosed line object by adding a shadow clone.md","mtime":1681665030892},{"fname":"Set background color of unclosed line object by adding a shadow clone.svg","mtime":1645960639000},{"fname":"Split text by lines.md","mtime":1645305706000},{"fname":"Split text by lines.svg","mtime":1645944722000},{"fname":"Zoom to Fit Selected Elements.md","mtime":1640770602000},{"fname":"Zoom to Fit Selected Elements.svg","mtime":1645960639000},{"fname":"directory-info.json","mtime":1646583437000},{"fname":"index-new.md","mtime":1645986149000},{"fname":"index.md","mtime":1645175700000},{"fname":"Grid Selected Images.md","mtime":1649614401982},{"fname":"Grid Selected Images.svg","mtime":1649614401982},{"fname":"Palette loader.md","mtime":1662992295615},{"fname":"Palette loader.svg","mtime":1649614401982},{"fname":"Rename Image.md","mtime":1663678478785},{"fname":"Rename Image.svg","mtime":1663678478785},{"fname":"Text Arch.md","mtime":1664095143846},{"fname":"Text Arch.svg","mtime":1670403743278},{"fname":"Deconstruct selected elements into new drawing.md","mtime":1672672112439},{"fname":"Deconstruct selected elements into new drawing.svg","mtime":1668541145255},{"fname":"Slideshow.md","mtime":1680418321236},{"fname":"Slideshow.svg","mtime":1670017348333},{"fname":"Auto Layout.md","mtime":1670403743278},{"fname":"Auto Layout.svg","mtime":1670175947081},{"fname":"Uniform size.md","mtime":1670175947081},{"fname":"Uniform size.svg","mtime":1670175947081},{"fname":"Alternative Pens.md", "mtime":1672942234020},{"fname":"Alternative Pens.svg", "mtime":1672942234020},{"fname":"Mindmap format.md","mtime":1674944958059},{"fname":"Mindmap format.svg","mtime":1674944958059},{"fname":"Text to Sticky Notes.md","mtime":1678537561724},{"fname":"Text to Sticky Notes.svg","mtime":1678537561724},{"fname":"Folder Note Core - Make Current Drawing a Folder.md","mtime":1678973697470},{"fname":"Folder Note Core - Make Current Drawing a Folder.svg","mtime":1678973697470},{"fname":"Invert colors.md","mtime":1678973697470},{"fname":"Invert colors.svg","mtime":1678973697470},{"fname":"Auto Draw for Pen.md","mtime":1680418321236},{"fname":"Auto Draw for Pen.svg","mtime":1680418321236},{"fname":"Hardware Eraser Support.md","mtime":1680418321236},{"fname":"Hardware Eraser Support.svg","mtime":1680418321236}] diff --git a/src/dialogs/Prompt.ts b/src/dialogs/Prompt.ts index 2d18dab..2dac0c5 100644 --- a/src/dialogs/Prompt.ts +++ b/src/dialogs/Prompt.ts @@ -183,6 +183,7 @@ export class GenericInputPrompt extends Modal { .onChange((value) => (this.input = value)); let i = 0; + const checkcaret = () => { //timer is implemented because on iPad with pencil the button click generates an event on the textarea this.selectionUpdateTimer = this.view.ownerWindow.setTimeout(() => { @@ -274,7 +275,10 @@ export class GenericInputPrompt extends Modal { this.inputComponent.inputEl.value = newVal; this.input = this.inputComponent.inputEl.value; this.inputComponent.inputEl.focus(); - this.inputComponent.inputEl.setSelectionRange(this.selectionStart+text.length, this.selectionStart+text.length); + this.selectionStart = this.selectionStart+text.length; + this.selectionEnd = this.selectionStart+text.length; + this.inputComponent.inputEl.setSelectionRange(this.selectionStart, this.selectionStart); + } this.plugin.insertLinkDialog.start(this.view.file.path, addText); } @@ -285,7 +289,9 @@ export class GenericInputPrompt extends Modal { this.inputComponent.inputEl.value = newVal; this.input = this.inputComponent.inputEl.value; this.inputComponent.inputEl.focus(); - this.inputComponent.inputEl.setSelectionRange(this.selectionStart+1, this.selectionStart+1); + this.selectionStart = this.selectionStart+1; + this.selectionEnd = this.selectionStart; + this.inputComponent.inputEl.setSelectionRange(this.selectionStart, this.selectionEnd); } private delBtnClickCallback = () => { @@ -299,6 +305,8 @@ export class GenericInputPrompt extends Modal { this.inputComponent.inputEl.value = newVal; this.input = this.inputComponent.inputEl.value; this.inputComponent.inputEl.focus(); + this.selectionStart = delStart; + this.selectionEnd = delStart; this.inputComponent.inputEl.setSelectionRange(delStart, delStart); }