(cm, e)
| 2214 | |
| 2215 | var detectingSelectAll; |
| 2216 | function onContextMenu(cm, e) { |
| 2217 | if (signalDOMEvent(cm, e, "contextmenu")) return; |
| 2218 | var display = cm.display, sel = cm.doc.sel; |
| 2219 | if (eventInWidget(display, e) || contextMenuInGutter(cm, e)) return; |
| 2220 | |
| 2221 | var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop; |
| 2222 | if (!pos || opera) return; // Opera is difficult. |
| 2223 | |
| 2224 | // Reset the current text selection only if the click is done outside of the selection |
| 2225 | // and 'resetSelectionOnContextMenu' option is true. |
| 2226 | var reset = cm.options.resetSelectionOnContextMenu; |
| 2227 | if (reset && (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))) |
| 2228 | operation(cm, setSelection)(cm.doc, pos, pos); |
| 2229 | |
| 2230 | var oldCSS = display.input.style.cssText; |
| 2231 | display.inputDiv.style.position = "absolute"; |
| 2232 | display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) + |
| 2233 | "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: transparent; outline: none;" + |
| 2234 | "border-width: 0; outline: none; overflow: hidden; opacity: .05; -ms-opacity: .05; filter: alpha(opacity=5);"; |
| 2235 | focusInput(cm); |
| 2236 | resetInput(cm, true); |
| 2237 | // Adds "Select all" to context menu in FF |
| 2238 | if (posEq(sel.from, sel.to)) display.input.value = display.prevInput = " "; |
| 2239 | |
| 2240 | function prepareSelectAllHack() { |
| 2241 | if (display.input.selectionStart != null) { |
| 2242 | var extval = display.input.value = "\u200b" + (posEq(sel.from, sel.to) ? "" : display.input.value); |
| 2243 | display.prevInput = "\u200b"; |
| 2244 | display.input.selectionStart = 1; display.input.selectionEnd = extval.length; |
| 2245 | } |
| 2246 | } |
| 2247 | function rehide() { |
| 2248 | display.inputDiv.style.position = "relative"; |
| 2249 | display.input.style.cssText = oldCSS; |
| 2250 | if (ie_lt9) display.scrollbarV.scrollTop = display.scroller.scrollTop = scrollPos; |
| 2251 | slowPoll(cm); |
| 2252 | |
| 2253 | // Try to detect the user choosing select-all |
| 2254 | if (display.input.selectionStart != null) { |
| 2255 | if (!ie || ie_lt9) prepareSelectAllHack(); |
| 2256 | clearTimeout(detectingSelectAll); |
| 2257 | var i = 0, poll = function(){ |
| 2258 | if (display.prevInput == "\u200b" && display.input.selectionStart == 0) |
| 2259 | operation(cm, commands.selectAll)(cm); |
| 2260 | else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500); |
| 2261 | else resetInput(cm); |
| 2262 | }; |
| 2263 | detectingSelectAll = setTimeout(poll, 200); |
| 2264 | } |
| 2265 | } |
| 2266 | |
| 2267 | if (ie && !ie_lt9) prepareSelectAllHack(); |
| 2268 | if (captureMiddleClick) { |
| 2269 | e_stop(e); |
| 2270 | var mouseup = function() { |
| 2271 | off(window, "mouseup", mouseup); |
| 2272 | setTimeout(rehide, 20); |
| 2273 | }; |
no test coverage detected