diff options
Diffstat (limited to 'src/editor.mjs')
-rw-r--r-- | src/editor.mjs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index 297d75a..ea80a19 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -2,7 +2,7 @@ | |||
2 | /*eslint no-undef: "error"*/ | 2 | /*eslint no-undef: "error"*/ |
3 | import { markdown2HTML, generateMaps } from './dumbymap' | 3 | import { markdown2HTML, generateMaps } from './dumbymap' |
4 | import { defaultAliases, parseConfigsFromYaml } from 'mapclay' | 4 | import { defaultAliases, parseConfigsFromYaml } from 'mapclay' |
5 | import { GeoLink, Suggestion } from './MenuItem' | 5 | import * as menuItem from './MenuItem' |
6 | 6 | ||
7 | // Set up Containers {{{ | 7 | // Set up Containers {{{ |
8 | 8 | ||
@@ -300,7 +300,7 @@ const getSuggestionsForOptions = (optionTyped, validOptions) => { | |||
300 | } | 300 | } |
301 | 301 | ||
302 | return suggestOptions | 302 | return suggestOptions |
303 | .map(o => new Suggestion({ | 303 | .map(o => new menuItem.Suggestion({ |
304 | text: `<span>${o.valueOf()}</span><span class='info' title="${o.desc ?? ''}">ⓘ</span>`, | 304 | text: `<span>${o.valueOf()}</span><span class='info' title="${o.desc ?? ''}">ⓘ</span>`, |
305 | replace: `${o.valueOf()}: `, | 305 | replace: `${o.valueOf()}: `, |
306 | })) | 306 | })) |
@@ -314,7 +314,7 @@ const getSuggestionFromMapOption = (option) => { | |||
314 | ? `<span>${option.example_desc}</span><span class="truncate"style="color: gray">${option.example}</span>` | 314 | ? `<span>${option.example_desc}</span><span class="truncate"style="color: gray">${option.example}</span>` |
315 | : `<span>${option.example}</span>` | 315 | : `<span>${option.example}</span>` |
316 | 316 | ||
317 | return new Suggestion({ | 317 | return new menuItem.Suggestion({ |
318 | text: text, | 318 | text: text, |
319 | replace: `${option.valueOf()}: ${option.example ?? ""}`, | 319 | replace: `${option.valueOf()}: ${option.example ?? ""}`, |
320 | }) | 320 | }) |
@@ -325,7 +325,7 @@ const getSuggestionsFromAliases = (option) => Object.entries(aliasesForMapOption | |||
325 | ?.map(record => { | 325 | ?.map(record => { |
326 | const [alias, value] = record | 326 | const [alias, value] = record |
327 | const valueString = JSON.stringify(value).replaceAll('"', '') | 327 | const valueString = JSON.stringify(value).replaceAll('"', '') |
328 | return new Suggestion({ | 328 | return new menuItem.Suggestion({ |
329 | text: `<span>${alias}</span><span class="truncate" style="color: gray">${valueString}</span>`, | 329 | text: `<span>${alias}</span><span class="truncate" style="color: gray">${valueString}</span>`, |
330 | replace: `${option.valueOf()}: ${valueString}`, | 330 | replace: `${option.valueOf()}: ${valueString}`, |
331 | }) | 331 | }) |
@@ -420,7 +420,7 @@ const getSuggestions = (anchor) => { | |||
420 | return [ | 420 | return [ |
421 | getSuggestionFromMapOption(matchedOption), | 421 | getSuggestionFromMapOption(matchedOption), |
422 | ...getSuggestionsFromAliases(matchedOption) | 422 | ...getSuggestionsFromAliases(matchedOption) |
423 | ].filter(s => s instanceof Suggestion) | 423 | ].filter(s => s instanceof menuItem.Suggestion) |
424 | } | 424 | } |
425 | if (valueTyped && !isValidValue) { | 425 | if (valueTyped && !isValidValue) { |
426 | markInputIsInvalid() | 426 | markInputIsInvalid() |
@@ -439,7 +439,7 @@ const getSuggestions = (anchor) => { | |||
439 | (suggestionPattern.includes(textPattern)) | 439 | (suggestionPattern.includes(textPattern)) |
440 | }) | 440 | }) |
441 | .map(([renderer, info]) => | 441 | .map(([renderer, info]) => |
442 | new Suggestion({ | 442 | new menuItem.Suggestion({ |
443 | text: `<span>use: ${renderer}</span><span class='info' title="${info.desc}">ⓘ</span>`, | 443 | text: `<span>use: ${renderer}</span><span class='info' title="${info.desc}">ⓘ</span>`, |
444 | replace: `use: ${renderer}`, | 444 | replace: `use: ${renderer}`, |
445 | }) | 445 | }) |
@@ -577,15 +577,20 @@ layoutObserver.observe(HtmlContainer, { | |||
577 | // }}} | 577 | // }}} |
578 | // ContextMenu {{{ | 578 | // ContextMenu {{{ |
579 | document.oncontextmenu = (e) => { | 579 | document.oncontextmenu = (e) => { |
580 | if (cm.hasFocus()) return | ||
581 | |||
580 | const selection = document.getSelection() | 582 | const selection = document.getSelection() |
581 | const range = selection.getRangeAt(0) | 583 | const range = selection.getRangeAt(0) |
582 | if (!cm.hasFocus() && selection) { | 584 | if (selection) { |
583 | e.preventDefault() | 585 | e.preventDefault() |
584 | menu.innerHTML = '' | 586 | menu.innerHTML = '' |
585 | menu.style.cssText = `display: block; left: ${e.clientX + 10}px; top: ${e.clientY + 5}px;` | 587 | menu.style.cssText = `display: block; left: ${e.clientX + 10}px; top: ${e.clientY + 5}px;` |
586 | const addGeoLink = new GeoLink({ range }) | 588 | const addGeoLink = new menuItem.GeoLink({ range }) |
587 | menu.appendChild(addGeoLink.createElement()) | 589 | menu.appendChild(addGeoLink.createElement()) |
588 | } | 590 | } |
591 | menu.appendChild(menuItem.nextMap.bind(dumbymap)()) | ||
592 | menu.appendChild(menuItem.nextBlock.bind(dumbymap)()) | ||
593 | menu.appendChild(menuItem.nextLayout.bind(dumbymap)()) | ||
589 | } | 594 | } |
590 | 595 | ||
591 | const actionOutsideMenu = (e) => { | 596 | const actionOutsideMenu = (e) => { |