diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-12 00:36:04 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-12 16:09:28 +0800 |
| commit | 35e4f820998f34fe05e5d9094be440ed04e9ea95 (patch) | |
| tree | be249f185bdba714bdbd035e342c2e4b896035ec | |
| parent | 9fd0f76b892e01ca0e95b1532fcd400e74ea8b5b (diff) | |
feat: add prefix for refLink option about DocLink
| -rw-r--r-- | src/MenuItem.mjs | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs index cffd4a7..2fcb144 100644 --- a/src/MenuItem.mjs +++ b/src/MenuItem.mjs | |||
| @@ -399,16 +399,22 @@ export const restoreCamera = map => | |||
| 399 | export const addRefLink = (cm, refLinks) => | 399 | export const addRefLink = (cm, refLinks) => |
| 400 | new Folder({ | 400 | new Folder({ |
| 401 | text: 'Add Link', | 401 | text: 'Add Link', |
| 402 | items: refLinks.map(refLink => new Item({ | 402 | items: refLinks.map(refLink => { |
| 403 | text: refLink.link.startsWith('geo:') ? `@ ${refLink.ref}` : refLink.ref, | 403 | let text = refLink.ref |
| 404 | title: refLink.link, | 404 | if (refLink.link.startsWith('geo:')) text = `@ ${text}` |
| 405 | onclick: () => { | 405 | if (refLink.title?.match(/^=>/)) text = `=> ${text}` |
| 406 | const selection = cm.getSelection() | 406 | |
| 407 | if (selection === refLink.ref) { | 407 | return new Item({ |
| 408 | cm.replaceSelection(`[${selection}]`) | 408 | text, |
| 409 | } else { | 409 | title: refLink.link, |
| 410 | cm.replaceSelection(`[${selection}][${refLink.ref}]`) | 410 | onclick: () => { |
| 411 | } | 411 | const selection = cm.getSelection() |
| 412 | }, | 412 | if (selection === refLink.ref) { |
| 413 | })), | 413 | cm.replaceSelection(`[${selection}]`) |
| 414 | } else { | ||
| 415 | cm.replaceSelection(`[${selection}][${refLink.ref}]`) | ||
| 416 | } | ||
| 417 | }, | ||
| 418 | }) | ||
| 419 | }), | ||
| 414 | }) | 420 | }) |