From 72704e3f5d5f4cbe00640be875955d4649f30780 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sat, 12 Oct 2024 15:46:50 +0800 Subject: feat: use selection as default name of anchor --- src/dumbyUtils.mjs | 3 ++- src/editor.mjs | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index 2f92c18..24699b3 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs @@ -267,6 +267,7 @@ const isAnchorVisible = anchor => { * @param {Function} options.validateAnchorName -- validate anchor name is OK to use */ export const addAnchorByPoint = ({ + defaultName, point, map, validateAnchorName = () => true, @@ -281,7 +282,7 @@ export const addAnchorByPoint = ({ do { prompt = prompt ? 'Anchor name exists' : 'Name this anchor' - anchorName = window.prompt(prompt, `${x},${y}`) + anchorName = window.prompt(prompt, defaultName ?? '') } while (anchorName !== null && !validateAnchorName(anchorName)) if (anchorName === null) return diff --git a/src/editor.mjs b/src/editor.mjs index fd18f78..5a51fbe 100644 --- a/src/editor.mjs +++ b/src/editor.mjs @@ -1124,7 +1124,12 @@ dumbyContainer.onmousedown = (e) => { return } - const refLink = addAnchorByPoint({ point: e, map, validateAnchorName }) + const refLink = addAnchorByPoint({ + defaultName: geoLink.textContent, + point: e, + map, + validateAnchorName, + }) if (!refLink) { resumeContent() return -- cgit v1.2.3-70-g09d2