(cm, e)
| 3135 | // textarea (making it as unobtrusive as possible) to let the |
| 3136 | // right-click take effect on it. |
| 3137 | function onContextMenu(cm, e) { |
| 3138 | if (signalDOMEvent(cm, e, "contextmenu")) return; |
| 3139 | var display = cm.display; |
| 3140 | if (eventInWidget(display, e) || contextMenuInGutter(cm, e)) return; |
| 3141 | |
| 3142 | var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop; |
| 3143 | if (!pos || presto) return; // Opera is difficult. |
| 3144 | |
| 3145 | // Reset the current text selection only if the click is done outside of the selection |
| 3146 | // and 'resetSelectionOnContextMenu' option is true. |
| 3147 | var reset = cm.options.resetSelectionOnContextMenu; |
| 3148 | if (reset && cm.doc.sel.contains(pos) == -1) |
| 3149 | operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); |
| 3150 | |
| 3151 | var oldCSS = display.input.style.cssText; |
| 3152 | display.inputDiv.style.position = "absolute"; |
| 3153 | display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) + |
| 3154 | "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: " + |
| 3155 | (ie ? "rgba(255, 255, 255, .05)" : "transparent") + |
| 3156 | "; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);"; |
| 3157 | focusInput(cm); |
| 3158 | resetInput(cm); |
| 3159 | // Adds "Select all" to context menu in FF |
| 3160 | if (!cm.somethingSelected()) display.input.value = display.prevInput = " "; |
| 3161 | display.selForContextMenu = cm.doc.sel; |
| 3162 | |
| 3163 | // Select-all will be greyed out if there's nothing to select, so |
| 3164 | // this adds a zero-width space so that we can later check whether |
| 3165 | // it got selected. |
| 3166 | function prepareSelectAllHack() { |
| 3167 | if (display.input.selectionStart != null) { |
| 3168 | var selected = cm.somethingSelected(); |
| 3169 | var extval = display.input.value = "\u200b" + (selected ? display.input.value : ""); |
| 3170 | display.prevInput = selected ? "" : "\u200b"; |
| 3171 | display.input.selectionStart = 1; display.input.selectionEnd = extval.length; |
| 3172 | } |
| 3173 | } |
| 3174 | function rehide() { |
| 3175 | display.inputDiv.style.position = "relative"; |
| 3176 | display.input.style.cssText = oldCSS; |
| 3177 | if (ie_upto8) display.scrollbarV.scrollTop = display.scroller.scrollTop = scrollPos; |
| 3178 | slowPoll(cm); |
| 3179 | |
| 3180 | // Try to detect the user choosing select-all |
| 3181 | if (display.input.selectionStart != null) { |
| 3182 | if (!ie || ie_upto8) prepareSelectAllHack(); |
| 3183 | clearTimeout(detectingSelectAll); |
| 3184 | var i = 0, poll = function() { |
| 3185 | if (display.selForContextMenu == cm.doc.sel && display.input.selectionStart == 0) |
| 3186 | operation(cm, commands.selectAll)(cm); |
| 3187 | else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500); |
| 3188 | else resetInput(cm); |
| 3189 | }; |
| 3190 | detectingSelectAll = setTimeout(poll, 200); |
| 3191 | } |
| 3192 | } |
| 3193 | |
| 3194 | if (ie && !ie_upto8) prepareSelectAllHack(); |
no test coverage detected
searching dependent graphs…