(cm, e)
| 3101 | // textarea (making it as unobtrusive as possible) to let the |
| 3102 | // right-click take effect on it. |
| 3103 | function onContextMenu(cm, e) { |
| 3104 | if (signalDOMEvent(cm, e, "contextmenu")) return; |
| 3105 | var display = cm.display; |
| 3106 | if (eventInWidget(display, e) || contextMenuInGutter(cm, e)) return; |
| 3107 | |
| 3108 | var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop; |
| 3109 | if (!pos || presto) return; // Opera is difficult. |
| 3110 | |
| 3111 | // Reset the current text selection only if the click is done outside of the selection |
| 3112 | // and 'resetSelectionOnContextMenu' option is true. |
| 3113 | var reset = cm.options.resetSelectionOnContextMenu; |
| 3114 | if (reset && cm.doc.sel.contains(pos) == -1) |
| 3115 | operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); |
| 3116 | |
| 3117 | var oldCSS = display.input.style.cssText; |
| 3118 | display.inputDiv.style.position = "absolute"; |
| 3119 | display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) + |
| 3120 | "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: " + |
| 3121 | (ie ? "rgba(255, 255, 255, .05)" : "transparent") + |
| 3122 | "; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);"; |
| 3123 | focusInput(cm); |
| 3124 | resetInput(cm); |
| 3125 | // Adds "Select all" to context menu in FF |
| 3126 | if (!cm.somethingSelected()) display.input.value = display.prevInput = " "; |
| 3127 | |
| 3128 | // Select-all will be greyed out if there's nothing to select, so |
| 3129 | // this adds a zero-width space so that we can later check whether |
| 3130 | // it got selected. |
| 3131 | function prepareSelectAllHack() { |
| 3132 | if (display.input.selectionStart != null) { |
| 3133 | var extval = display.input.value = "\u200b" + (cm.somethingSelected() ? display.input.value : ""); |
| 3134 | display.prevInput = "\u200b"; |
| 3135 | display.input.selectionStart = 1; display.input.selectionEnd = extval.length; |
| 3136 | } |
| 3137 | } |
| 3138 | function rehide() { |
| 3139 | display.inputDiv.style.position = "relative"; |
| 3140 | display.input.style.cssText = oldCSS; |
| 3141 | if (ie_upto8) display.scrollbarV.scrollTop = display.scroller.scrollTop = scrollPos; |
| 3142 | slowPoll(cm); |
| 3143 | |
| 3144 | // Try to detect the user choosing select-all |
| 3145 | if (display.input.selectionStart != null) { |
| 3146 | if (!ie || ie_upto8) prepareSelectAllHack(); |
| 3147 | clearTimeout(detectingSelectAll); |
| 3148 | var i = 0, poll = function(){ |
| 3149 | if (display.prevInput == "\u200b" && display.input.selectionStart == 0) |
| 3150 | operation(cm, commands.selectAll)(cm); |
| 3151 | else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500); |
| 3152 | else resetInput(cm); |
| 3153 | }; |
| 3154 | detectingSelectAll = setTimeout(poll, 200); |
| 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | if (ie && !ie_upto8) prepareSelectAllHack(); |
| 3159 | if (captureRightClick) { |
| 3160 | e_stop(e); |
no test coverage detected