aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/MenuItem.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/MenuItem.mjs')
-rw-r--r--src/MenuItem.mjs41
1 files changed, 16 insertions, 25 deletions
diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs
index d485032..4028702 100644
--- a/src/MenuItem.mjs
+++ b/src/MenuItem.mjs
@@ -134,41 +134,32 @@ export const addGeoLink = ({ utils }, range) =>
134 } 134 }
135 }) 135 })
136 136
137export class Suggestion { 137export class Suggestion extends Item {
138 constructor ({ text, replace }) { 138 constructor ({ text, replace, cm }) {
139 this.text = text 139 super({ text })
140 this.replace = replace 140 this.replace = replace
141 } 141 this.classList.add('suggestion')
142 142
143 createElement (codemirror) { 143 this.onmouseover = () => {
144 const option = document.createElement('div') 144 Array.from(this.parentElement?.children)?.forEach(s =>
145 if (this.text.startsWith('<')) {
146 option.innerHTML = this.text
147 } else {
148 option.innerText = this.text
149 }
150 option.classList.add('container__suggestion')
151 option.onmouseover = () => {
152 Array.from(option.parentElement?.children)?.forEach(s =>
153 s.classList.remove('focus') 145 s.classList.remove('focus')
154 ) 146 )
155 option.classList.add('focus') 147 this.classList.add('focus')
156 } 148 }
157 option.onmouseout = () => { 149 this.onmouseout = () => {
158 option.classList.remove('focus') 150 this.classList.remove('focus')
159 } 151 }
160 option.onclick = () => { 152 this.onclick = () => {
161 const anchor = codemirror.getCursor() 153 const anchor = cm.getCursor()
162 codemirror.setSelection(anchor, { ...anchor, ch: 0 }) 154 cm.setSelection(anchor, { ...anchor, ch: 0 })
163 codemirror.replaceSelection(this.replace) 155 cm.replaceSelection(this.replace)
164 codemirror.focus() 156 cm.focus()
165 const newAnchor = { ...anchor, ch: this.replace.length } 157 const newAnchor = { ...anchor, ch: this.replace.length }
166 codemirror.setCursor(newAnchor) 158 cm.setCursor(newAnchor)
167 } 159 }
168
169 return option
170 } 160 }
171} 161}
162window.customElements.define('menu-item-suggestion', Suggestion, { extends: 'div' })
172 163
173export const renderResults = ({ modal, modalContent }, map) => 164export const renderResults = ({ modal, modalContent }, map) =>
174 new Item({ 165 new Item({