diff options
| -rw-r--r-- | src/dumbyUtils.mjs | 8 | ||||
| -rw-r--r-- | src/editor.mjs | 18 |
2 files changed, 14 insertions, 12 deletions
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index 83d24c0..4b2ae2c 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs | |||
| @@ -121,7 +121,7 @@ const addLeaderLine = (link, target) => { | |||
| 121 | start: link, | 121 | start: link, |
| 122 | end: target, | 122 | end: target, |
| 123 | hide: true, | 123 | hide: true, |
| 124 | middleLabel: link.url.searchParams.get('text'), | 124 | middleLabel: link.title, |
| 125 | path: 'magnet', | 125 | path: 'magnet', |
| 126 | }) | 126 | }) |
| 127 | line.show('draw', { duration: 300 }) | 127 | line.show('draw', { duration: 300 }) |
| @@ -270,12 +270,14 @@ export const addAnchorByPoint = ({ | |||
| 270 | while (anchorName !== null && !validateAnchorName(anchorName)) | 270 | while (anchorName !== null && !validateAnchorName(anchorName)) |
| 271 | if (anchorName === null) return | 271 | if (anchorName === null) return |
| 272 | 272 | ||
| 273 | const link = `geo:${y},${x}?xy=${x},${y}&id=${map.id}&text=${anchorName}` | 273 | const desc = window.prompt("Description", anchorName) ?? anchorName |
| 274 | |||
| 275 | const link = `geo:${y},${x}?xy=${x},${y}&id=${map.id}` | ||
| 274 | map.renderer.addMarker({ | 276 | map.renderer.addMarker({ |
| 275 | xy: [x, y], | 277 | xy: [x, y], |
| 276 | title: `${map.id}@${x},${y}`, | 278 | title: `${map.id}@${x},${y}`, |
| 277 | type: 'circle', | 279 | type: 'circle', |
| 278 | }) | 280 | }) |
| 279 | 281 | ||
| 280 | return { ref: anchorName, link } | 282 | return { ref: anchorName, link, title: desc } |
| 281 | } | 283 | } |
diff --git a/src/editor.mjs b/src/editor.mjs index ed63f9c..4f500f5 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
| @@ -19,13 +19,14 @@ const refLinkPattern = /\[([^\x5B\x5D]+)\]:\s+(.+)/ | |||
| 19 | let refLinks = [] | 19 | let refLinks = [] |
| 20 | const validateAnchorName = anchorName => | 20 | const validateAnchorName = anchorName => |
| 21 | !refLinks.find(obj => obj.ref === anchorName) | 21 | !refLinks.find(obj => obj.ref === anchorName) |
| 22 | const appendRefLink = ({ cm, ref, link }) => { | 22 | const appendRefLink = (cm, refLink) => { |
| 23 | let refLinkString = `\n[${ref}]: ${link}` | 23 | const {ref, link, title} = refLink |
| 24 | let refLinkString = `\n[${ref}]: ${link} "${title ?? ''}"` | ||
| 24 | const lastLineIsRefLink = cm.getLine(cm.lastLine()).match(refLinkPattern) | 25 | const lastLineIsRefLink = cm.getLine(cm.lastLine()).match(refLinkPattern) |
| 25 | if (!lastLineIsRefLink) refLinkString = '\n' + refLinkString | 26 | if (!lastLineIsRefLink) refLinkString = '\n' + refLinkString |
| 26 | cm.replaceRange(refLinkString, { line: Infinity }) | 27 | cm.replaceRange(refLinkString, { line: Infinity }) |
| 27 | 28 | ||
| 28 | refLinks.push({ ref, link }) | 29 | refLinks.push(refLink) |
| 29 | } | 30 | } |
| 30 | /** | 31 | /** |
| 31 | * Watch for changes of editing mode | 32 | * Watch for changes of editing mode |
| @@ -468,8 +469,8 @@ const menuForEditor = (event, menu) => { | |||
| 468 | const item = new menuItem.Item({ | 469 | const item = new menuItem.Item({ |
| 469 | text: 'Add Anchor', | 470 | text: 'Add Anchor', |
| 470 | onclick: (event) => { | 471 | onclick: (event) => { |
| 471 | const { ref, link } = addAnchorByPoint({ point: event, map, validateAnchorName }) | 472 | const refLink = addAnchorByPoint({ point: event, map, validateAnchorName }) |
| 472 | appendRefLink({ cm, ref, link }) | 473 | appendRefLink(cm, refLink) |
| 473 | }, | 474 | }, |
| 474 | }) | 475 | }) |
| 475 | menu.insertBefore(item, menu.firstChild) | 476 | menu.insertBefore(item, menu.firstChild) |
| @@ -1146,12 +1147,11 @@ dumbyContainer.onmousedown = (e) => { | |||
| 1146 | return | 1147 | return |
| 1147 | } | 1148 | } |
| 1148 | 1149 | ||
| 1149 | const { ref, link } = refLink | 1150 | appendRefLink(cm, refLink) |
| 1150 | appendRefLink({ cm, ref, link }) | 1151 | if (selection === refLink.ref) { |
| 1151 | if (selection === ref) { | ||
| 1152 | cm.replaceSelection(`[${selection}]`) | 1152 | cm.replaceSelection(`[${selection}]`) |
| 1153 | } else { | 1153 | } else { |
| 1154 | cm.replaceSelection(`[${selection}][${ref}]`) | 1154 | cm.replaceSelection(`[${selection}][${refLink.ref}]`) |
| 1155 | } | 1155 | } |
| 1156 | } | 1156 | } |
| 1157 | } | 1157 | } |