|
70 | 70 | CodeMirror.on(node, "mouseout", hide); |
71 | 71 | } |
72 | 72 |
|
73 | | - function showMenu (cm, annotations, e) { |
| 73 | + /** |
| 74 | + * |
| 75 | + * @param {*} cm |
| 76 | + * @param {Array<{ content: string, html: string, onClick: any }>} menus |
| 77 | + * @param {*} e |
| 78 | + */ |
| 79 | + function showMenu (cm, menus, e) { |
74 | 80 | var target = e.target || e.srcElement; |
75 | 81 | var state = cm.state.lint |
76 | 82 |
|
77 | | - if (!(state.options.menus && state.options.menus.length > 0)) { |
| 83 | + if (!menus && menus.length > 0) { |
78 | 84 | return |
79 | 85 | } |
80 | | - |
81 | | - /** @type {Array<{ content: string, html: string, onClick: any }>} */ |
82 | | - const menus = state.options.menus |
83 | 86 |
|
84 | 87 | // build menu |
85 | 88 | var hints = document.createElement("ul"); |
|
98 | 101 | } |
99 | 102 | const onClick = item.onClick |
100 | 103 | elt.addEventListener('click', (e) => { |
101 | | - onClick(e, annotations) |
| 104 | + if (typeof onClick === 'function') { |
| 105 | + onClick(e) |
| 106 | + } |
102 | 107 | remove() |
103 | 108 | }) |
104 | 109 | } |
|
130 | 135 | this.onMouseOver = function(e) { onMouseOver(cm, e); }; |
131 | 136 | this.onClick = function(e) { onClick(cm, e); }; |
132 | 137 | this.waitingFor = 0 |
| 138 | + |
| 139 | + this.contextMenuEnable = typeof options.contextmenu === 'function' |
133 | 140 | } |
134 | 141 |
|
135 | 142 | function parseOptions(_cm, options) { |
|
158 | 165 | showTooltipFor(cm, e, labels, inner); |
159 | 166 | }); |
160 | 167 |
|
161 | | - if (cm.state.lint.options.contextmenu) { |
| 168 | + if (cm.state.lint.contextMenuEnable) { |
162 | 169 | marker.addEventListener('click', function (e) { |
163 | | - if (typeof cm.state.lint.options.onClick === 'function') { |
164 | | - cm.state.lint.options.onClick(cm, e) |
165 | | - } |
166 | | - showMenu(cm, annotations, e) |
| 170 | + const menus = cm.state.lint.options.contextmenu(annotations) |
| 171 | + showMenu(cm, menus, e) |
167 | 172 | }) |
168 | 173 | } |
169 | 174 |
|
|
306 | 311 | } |
307 | 312 |
|
308 | 313 | function onClick (cm, e) { |
309 | | - if (typeof cm.state.lint.options.onClick === 'function') { |
310 | | - cm.state.lint.options.onClick(cm, e) |
311 | | - } |
312 | | - handleMarkerAction(cm, e, showMenu) |
| 314 | + handleMarkerAction(cm, e, function (cm, annotations, e) { |
| 315 | + const menus = cm.state.lint.options.contextmenu(annotations) |
| 316 | + showMenu(cm, menus, e) |
| 317 | + }) |
313 | 318 | } |
314 | 319 |
|
315 | 320 | CodeMirror.defineOption("lint", false, function(cm, val, old) { |
|
330 | 335 | cm.on("change", onChange); |
331 | 336 | if (state.options.tooltips != false && state.options.tooltips != "gutter") |
332 | 337 | CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver); |
333 | | - if (state.options.contextmenu) { |
| 338 | + if (state.contextMenuEnable) { |
334 | 339 | CodeMirror.on(cm.getWrapperElement(), "click", state.onClick); |
335 | 340 | } |
336 | 341 |
|
|
0 commit comments