From a915a0f136cffdfb0c2cebb165ec16e95a113e84 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Mon, 7 Oct 2024 19:44:46 +0800 Subject: fix: do not add anchor when user input is null --- src/editor.mjs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/editor.mjs b/src/editor.mjs index 8e3e62b..4a58f12 100644 --- a/src/editor.mjs +++ b/src/editor.mjs @@ -424,14 +424,15 @@ const menuForEditor = (event, menu) => { let prompt let anchorName - let link + do { prompt = prompt ? 'Anchor name exists' : 'Name this anchor' anchorName = window.prompt(prompt, `${x}, ${y}`) - link = `geo:${y},${x}?xy=${x},${y}&id=${map.id} "${anchorName}"` } - while (refLinks.find(({ ref }) => ref === anchorName)) + while (anchorName !== null && refLinks.find(({ ref }) => ref === anchorName)) + if (anchorName === null) return + const link = `geo:${y},${x}?xy=${x},${y}&id=${map.id} "${anchorName}"` const lastLineIsRefLink = cm.getLine(cm.lastLine()).match(refLinkPattern) cm.replaceRange( `${lastLineIsRefLink ? '' : '\n'}\n[${anchorName}]: ${link}`, -- cgit v1.2.3-70-g09d2