| 1 |
ace.define("ace/autocomplete/popup",["require","exports","module","ace/virtual_renderer","ace/editor","ace/range","ace/lib/event","ace/lib/lang","ace/lib/dom","ace/config","ace/lib/useragent"], function(require, exports, module){"use strict"; |
| 2 |
var Renderer = require("../virtual_renderer").VirtualRenderer; |
| 3 |
var Editor = require("../editor").Editor; |
| 4 |
var Range = require("../range").Range; |
| 5 |
var event = require("../lib/event"); |
| 6 |
var lang = require("../lib/lang"); |
| 7 |
var dom = require("../lib/dom"); |
| 8 |
var nls = require("../config").nls; |
| 9 |
var userAgent = require("./../lib/useragent"); |
| 10 |
var getAriaId = function (index) { |
| 11 |
return "suggest-aria-id:".concat(index); |
| 12 |
}; |
| 13 |
var popupAriaRole = userAgent.isSafari ? "menu" : "listbox"; |
| 14 |
var optionAriaRole = userAgent.isSafari ? "menuitem" : "option"; |
| 15 |
var ariaActiveState = userAgent.isSafari ? "aria-current" : "aria-selected"; |
| 16 |
var $singleLineEditor = function (el) { |
| 17 |
var renderer = new Renderer(el); |
| 18 |
renderer.$maxLines = 4; |
| 19 |
var editor = new Editor(renderer); |
| 20 |
editor.setHighlightActiveLine(false); |
| 21 |
editor.setShowPrintMargin(false); |
| 22 |
editor.renderer.setShowGutter(false); |
| 23 |
editor.renderer.setHighlightGutterLine(false); |
| 24 |
editor.$mouseHandler.$focusTimeout = 0; |
| 25 |
editor.$highlightTagPending = true; |
| 26 |
return editor; |
| 27 |
}; |
| 28 |
var AcePopup = (function () { |
| 29 |
function AcePopup(parentNode) { |
| 30 |
var el = dom.createElement("div"); |
| 31 |
var popup = $singleLineEditor(el); |
| 32 |
if (parentNode) { |
| 33 |
parentNode.appendChild(el); |
| 34 |
} |
| 35 |
el.style.display = "none"; |
| 36 |
popup.renderer.content.style.cursor = "default"; |
| 37 |
popup.renderer.setStyle("ace_autocomplete"); |
| 38 |
popup.renderer.$textLayer.element.setAttribute("role", popupAriaRole); |
| 39 |
popup.renderer.$textLayer.element.setAttribute("aria-roledescription", nls("Autocomplete suggestions")); |
| 40 |
popup.renderer.$textLayer.element.setAttribute("aria-label", nls("Autocomplete suggestions")); |
| 41 |
popup.renderer.textarea.setAttribute("aria-hidden", "true"); |
| 42 |
popup.setOption("displayIndentGuides", false); |
| 43 |
popup.setOption("dragDelay", 150); |
| 44 |
var noop = function () { }; |
| 45 |
popup.focus = noop; |
| 46 |
popup.$isFocused = true; |
| 47 |
popup.renderer.$cursorLayer.restartTimer = noop; |
| 48 |
popup.renderer.$cursorLayer.element.style.opacity = "0"; |
| 49 |
popup.renderer.$maxLines = 8; |
| 50 |
popup.renderer.$keepTextAreaAtCursor = false; |
| 51 |
popup.setHighlightActiveLine(false); |
| 52 |
popup.session.highlight(""); |
| 53 |
popup.session.$searchHighlight.clazz = "ace_highlight-marker"; |
| 54 |
popup.on("mousedown", function (e) { |
| 55 |
var pos = e.getDocumentPosition(); |
| 56 |
popup.selection.moveToPosition(pos); |
| 57 |
selectionMarker.start.row = selectionMarker.end.row = pos.row; |
| 58 |
e.stop(); |
| 59 |
}); |
| 60 |
var lastMouseEvent; |
| 61 |
var hoverMarker = new Range(-1, 0, -1, Infinity); |
| 62 |
var selectionMarker = new Range(-1, 0, -1, Infinity); |
| 63 |
selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine"); |
| 64 |
popup.setSelectOnHover = function (val) { |
| 65 |
if (!val) { |
| 66 |
hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine"); |
| 67 |
} |
| 68 |
else if (hoverMarker.id) { |
| 69 |
popup.session.removeMarker(hoverMarker.id); |
| 70 |
hoverMarker.id = null; |
| 71 |
} |
| 72 |
}; |
| 73 |
popup.setSelectOnHover(false); |
| 74 |
popup.on("mousemove", function (e) { |
| 75 |
if (!lastMouseEvent) { |
| 76 |
lastMouseEvent = e; |
| 77 |
return; |
| 78 |
} |
| 79 |
if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) { |
| 80 |
return; |
| 81 |
} |
| 82 |
lastMouseEvent = e; |
| 83 |
lastMouseEvent.scrollTop = popup.renderer.scrollTop; |
| 84 |
popup.isMouseOver = true; |
| 85 |
var row = lastMouseEvent.getDocumentPosition().row; |
| 86 |
if (hoverMarker.start.row != row) { |
| 87 |
if (!hoverMarker.id) |
| 88 |
popup.setRow(row); |
| 89 |
setHoverMarker(row); |
| 90 |
} |
| 91 |
}); |
| 92 |
popup.renderer.on("beforeRender", function () { |
| 93 |
if (lastMouseEvent && hoverMarker.start.row != -1) { |
| 94 |
lastMouseEvent.$pos = null; |
| 95 |
var row = lastMouseEvent.getDocumentPosition().row; |
| 96 |
if (!hoverMarker.id) |
| 97 |
popup.setRow(row); |
| 98 |
setHoverMarker(row, true); |
| 99 |
} |
| 100 |
}); |
| 101 |
popup.renderer.on("afterRender", function () { |
| 102 |
var row = popup.getRow(); |
| 103 |
var t = popup.renderer.$textLayer; |
| 104 |
var selected = (t.element.childNodes[row - t.config.firstRow]); |
| 105 |
var el = document.activeElement; |
| 106 |
if (selected !== popup.selectedNode && popup.selectedNode) { |
| 107 |
dom.removeCssClass(popup.selectedNode, "ace_selected"); |
| 108 |
el.removeAttribute("aria-activedescendant"); |
| 109 |
popup.selectedNode.removeAttribute(ariaActiveState); |
| 110 |
popup.selectedNode.removeAttribute("id"); |
| 111 |
} |
| 112 |
popup.selectedNode = selected; |
| 113 |
if (selected) { |
| 114 |
dom.addCssClass(selected, "ace_selected"); |
| 115 |
var ariaId = getAriaId(row); |
| 116 |
selected.id = ariaId; |
| 117 |
t.element.setAttribute("aria-activedescendant", ariaId); |
| 118 |
el.setAttribute("aria-activedescendant", ariaId); |
| 119 |
selected.setAttribute("role", optionAriaRole); |
| 120 |
selected.setAttribute("aria-roledescription", nls("item")); |
| 121 |
selected.setAttribute("aria-label", popup.getData(row).caption || popup.getData(row).value); |
| 122 |
selected.setAttribute("aria-setsize", popup.data.length); |
| 123 |
selected.setAttribute("aria-posinset", row + 1); |
| 124 |
selected.setAttribute("aria-describedby", "doc-tooltip"); |
| 125 |
selected.setAttribute(ariaActiveState, "true"); |
| 126 |
} |
| 127 |
}); |
| 128 |
var hideHoverMarker = function () { setHoverMarker(-1); }; |
| 129 |
var setHoverMarker = function (row, suppressRedraw) { |
| 130 |
if (row !== hoverMarker.start.row) { |
| 131 |
hoverMarker.start.row = hoverMarker.end.row = row; |
| 132 |
if (!suppressRedraw) |
| 133 |
popup.session._emit("changeBackMarker"); |
| 134 |
popup._emit("changeHoverMarker"); |
| 135 |
} |
| 136 |
}; |
| 137 |
popup.getHoveredRow = function () { |
| 138 |
return hoverMarker.start.row; |
| 139 |
}; |
| 140 |
event.addListener(popup.container, "mouseout", function () { |
| 141 |
popup.isMouseOver = false; |
| 142 |
hideHoverMarker(); |
| 143 |
}); |
| 144 |
popup.on("hide", hideHoverMarker); |
| 145 |
popup.on("changeSelection", hideHoverMarker); |
| 146 |
popup.session.doc.getLength = function () { |
| 147 |
return popup.data.length; |
| 148 |
}; |
| 149 |
popup.session.doc.getLine = function (i) { |
| 150 |
var data = popup.data[i]; |
| 151 |
if (typeof data == "string") |
| 152 |
return data; |
| 153 |
return (data && data.value) || ""; |
| 154 |
}; |
| 155 |
var bgTokenizer = popup.session.bgTokenizer; |
| 156 |
bgTokenizer.$tokenizeRow = function (row) { |
| 157 |
var data = popup.data[row]; |
| 158 |
var tokens = []; |
| 159 |
if (!data) |
| 160 |
return tokens; |
| 161 |
if (typeof data == "string") |
| 162 |
data = { value: data }; |
| 163 |
var caption = data.caption || data.value || data.name; |
| 164 |
function addToken(value, className) { |
| 165 |
value && tokens.push({ |
| 166 |
type: (data.className || "") + (className || ""), |
| 167 |
value: value |
| 168 |
}); |
| 169 |
} |
| 170 |
var lower = caption.toLowerCase(); |
| 171 |
var filterText = (popup.filterText || "").toLowerCase(); |
| 172 |
var lastIndex = 0; |
| 173 |
var lastI = 0; |
| 174 |
for (var i = 0; i <= filterText.length; i++) { |
| 175 |
if (i != lastI && (data.matchMask & (1 << i) || i == filterText.length)) { |
| 176 |
var sub = filterText.slice(lastI, i); |
| 177 |
lastI = i; |
| 178 |
var index = lower.indexOf(sub, lastIndex); |
| 179 |
if (index == -1) |
| 180 |
continue; |
| 181 |
addToken(caption.slice(lastIndex, index), ""); |
| 182 |
lastIndex = index + sub.length; |
| 183 |
addToken(caption.slice(index, lastIndex), "completion-highlight"); |
| 184 |
} |
| 185 |
} |
| 186 |
addToken(caption.slice(lastIndex, caption.length), ""); |
| 187 |
tokens.push({ type: "completion-spacer", value: " " }); |
| 188 |
if (data.meta) |
| 189 |
tokens.push({ type: "completion-meta", value: data.meta }); |
| 190 |
if (data.message) |
| 191 |
tokens.push({ type: "completion-message", value: data.message }); |
| 192 |
return tokens; |
| 193 |
}; |
| 194 |
bgTokenizer.$updateOnChange = noop; |
| 195 |
bgTokenizer.start = noop; |
| 196 |
popup.session.$computeWidth = function () { |
| 197 |
return this.screenWidth = 0; |
| 198 |
}; |
| 199 |
popup.isOpen = false; |
| 200 |
popup.isTopdown = false; |
| 201 |
popup.autoSelect = true; |
| 202 |
popup.filterText = ""; |
| 203 |
popup.isMouseOver = false; |
| 204 |
popup.data = []; |
| 205 |
popup.setData = function (list, filterText) { |
| 206 |
popup.filterText = filterText || ""; |
| 207 |
popup.setValue(lang.stringRepeat("\n", list.length), -1); |
| 208 |
popup.data = list || []; |
| 209 |
popup.setRow(0); |
| 210 |
}; |
| 211 |
popup.getData = function (row) { |
| 212 |
return popup.data[row]; |
| 213 |
}; |
| 214 |
popup.getRow = function () { |
| 215 |
return selectionMarker.start.row; |
| 216 |
}; |
| 217 |
popup.setRow = function (line) { |
| 218 |
line = Math.max(this.autoSelect ? 0 : -1, Math.min(this.data.length - 1, line)); |
| 219 |
if (selectionMarker.start.row != line) { |
| 220 |
popup.selection.clearSelection(); |
| 221 |
selectionMarker.start.row = selectionMarker.end.row = line || 0; |
| 222 |
popup.session._emit("changeBackMarker"); |
| 223 |
popup.moveCursorTo(line || 0, 0); |
| 224 |
if (popup.isOpen) |
| 225 |
popup._signal("select"); |
| 226 |
} |
| 227 |
}; |
| 228 |
popup.on("changeSelection", function () { |
| 229 |
if (popup.isOpen) |
| 230 |
popup.setRow(popup.selection.lead.row); |
| 231 |
popup.renderer.scrollCursorIntoView(); |
| 232 |
}); |
| 233 |
popup.hide = function () { |
| 234 |
this.container.style.display = "none"; |
| 235 |
popup.anchorPos = null; |
| 236 |
popup.anchor = null; |
| 237 |
if (popup.isOpen) { |
| 238 |
popup.isOpen = false; |
| 239 |
this._signal("hide"); |
| 240 |
} |
| 241 |
}; |
| 242 |
popup.tryShow = function (pos, lineHeight, anchor, forceShow) { |
| 243 |
if (!forceShow && popup.isOpen && popup.anchorPos && popup.anchor && |
| 244 |
popup.anchorPos.top === pos.top && popup.anchorPos.left === pos.left && |
| 245 |
popup.anchor === anchor) { |
| 246 |
return true; |
| 247 |
} |
| 248 |
var el = this.container; |
| 249 |
var screenHeight = window.innerHeight; |
| 250 |
var screenWidth = window.innerWidth; |
| 251 |
var renderer = this.renderer; |
| 252 |
var maxH = renderer.$maxLines * lineHeight * 1.4; |
| 253 |
var dims = { top: 0, bottom: 0, left: 0 }; |
| 254 |
var spaceBelow = screenHeight - pos.top - 3 * this.$borderSize - lineHeight; |
| 255 |
var spaceAbove = pos.top - 3 * this.$borderSize; |
| 256 |
if (!anchor) { |
| 257 |
if (spaceAbove <= spaceBelow || spaceBelow >= maxH) { |
| 258 |
anchor = "bottom"; |
| 259 |
} |
| 260 |
else { |
| 261 |
anchor = "top"; |
| 262 |
} |
| 263 |
} |
| 264 |
if (anchor === "top") { |
| 265 |
dims.bottom = pos.top - this.$borderSize; |
| 266 |
dims.top = dims.bottom - maxH; |
| 267 |
} |
| 268 |
else if (anchor === "bottom") { |
| 269 |
dims.top = pos.top + lineHeight + this.$borderSize; |
| 270 |
dims.bottom = dims.top + maxH; |
| 271 |
} |
| 272 |
var fitsX = dims.top >= 0 && dims.bottom <= screenHeight; |
| 273 |
if (!forceShow && !fitsX) { |
| 274 |
return false; |
| 275 |
} |
| 276 |
if (!fitsX) { |
| 277 |
if (anchor === "top") { |
| 278 |
renderer.$maxPixelHeight = spaceAbove; |
| 279 |
} |
| 280 |
else { |
| 281 |
renderer.$maxPixelHeight = spaceBelow; |
| 282 |
} |
| 283 |
} |
| 284 |
else { |
| 285 |
renderer.$maxPixelHeight = null; |
| 286 |
} |
| 287 |
if (anchor === "top") { |
| 288 |
el.style.top = ""; |
| 289 |
el.style.bottom = (screenHeight - dims.bottom) + "px"; |
| 290 |
popup.isTopdown = false; |
| 291 |
} |
| 292 |
else { |
| 293 |
el.style.top = dims.top + "px"; |
| 294 |
el.style.bottom = ""; |
| 295 |
popup.isTopdown = true; |
| 296 |
} |
| 297 |
el.style.display = ""; |
| 298 |
var left = pos.left; |
| 299 |
if (left + el.offsetWidth > screenWidth) |
| 300 |
left = screenWidth - el.offsetWidth; |
| 301 |
el.style.left = left + "px"; |
| 302 |
el.style.right = ""; |
| 303 |
if (!popup.isOpen) { |
| 304 |
popup.isOpen = true; |
| 305 |
this._signal("show"); |
| 306 |
lastMouseEvent = null; |
| 307 |
} |
| 308 |
popup.anchorPos = pos; |
| 309 |
popup.anchor = anchor; |
| 310 |
return true; |
| 311 |
}; |
| 312 |
popup.show = function (pos, lineHeight, topdownOnly) { |
| 313 |
this.tryShow(pos, lineHeight, topdownOnly ? "bottom" : undefined, true); |
| 314 |
}; |
| 315 |
popup.goTo = function (where) { |
| 316 |
var row = this.getRow(); |
| 317 |
var max = this.session.getLength() - 1; |
| 318 |
switch (where) { |
| 319 |
case "up": |
| 320 |
row = row <= 0 ? max : row - 1; |
| 321 |
break; |
| 322 |
case "down": |
| 323 |
row = row >= max ? -1 : row + 1; |
| 324 |
break; |
| 325 |
case "start": |
| 326 |
row = 0; |
| 327 |
break; |
| 328 |
case "end": |
| 329 |
row = max; |
| 330 |
break; |
| 331 |
} |
| 332 |
this.setRow(row); |
| 333 |
}; |
| 334 |
popup.getTextLeftOffset = function () { |
| 335 |
return this.$borderSize + this.renderer.$padding + this.$imageSize; |
| 336 |
}; |
| 337 |
popup.$imageSize = 0; |
| 338 |
popup.$borderSize = 1; |
| 339 |
return popup; |
| 340 |
} |
| 341 |
return AcePopup; |
| 342 |
}()); |
| 343 |
dom.importCssString("\n.ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line {\n background-color: #CAD6FA;\n z-index: 1;\n}\n.ace_dark.ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line {\n background-color: #3a674e;\n}\n.ace_editor.ace_autocomplete .ace_line-hover {\n border: 1px solid #abbffe;\n margin-top: -1px;\n background: rgba(233,233,253,0.4);\n position: absolute;\n z-index: 2;\n}\n.ace_dark.ace_editor.ace_autocomplete .ace_line-hover {\n border: 1px solid rgba(109, 150, 13, 0.8);\n background: rgba(58, 103, 78, 0.62);\n}\n.ace_completion-meta {\n opacity: 0.5;\n margin-left: 0.9em;\n}\n.ace_completion-message {\n margin-left: 0.9em;\n color: blue;\n}\n.ace_editor.ace_autocomplete .ace_completion-highlight{\n color: #2d69c7;\n}\n.ace_dark.ace_editor.ace_autocomplete .ace_completion-highlight{\n color: #93ca12;\n}\n.ace_editor.ace_autocomplete {\n width: 300px;\n z-index: 200000;\n border: 1px lightgray solid;\n position: fixed;\n box-shadow: 2px 3px 5px rgba(0,0,0,.2);\n line-height: 1.4;\n background: #fefefe;\n color: #111;\n}\n.ace_dark.ace_editor.ace_autocomplete {\n border: 1px #484747 solid;\n box-shadow: 2px 3px 5px rgba(0, 0, 0, 0.51);\n line-height: 1.4;\n background: #25282c;\n color: #c1c1c1;\n}\n.ace_autocomplete .ace_text-layer {\n width: calc(100% - 8px);\n}\n.ace_autocomplete .ace_line {\n display: flex;\n align-items: center;\n}\n.ace_autocomplete .ace_line > * {\n min-width: 0;\n flex: 0 0 auto;\n}\n.ace_autocomplete .ace_line .ace_ {\n flex: 0 1 auto;\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n}\n.ace_autocomplete .ace_completion-spacer {\n flex: 1;\n}\n.ace_autocomplete.ace_loading:after {\n content: \"\";\n position: absolute;\n top: 0px;\n height: 2px;\n width: 8%;\n background: blue;\n z-index: 100;\n animation: ace_progress 3s infinite linear;\n animation-delay: 300ms;\n transform: translateX(-100%) scaleX(1);\n}\n@keyframes ace_progress {\n 0% { transform: translateX(-100%) scaleX(1) }\n 50% { transform: translateX(625%) scaleX(2) } \n 100% { transform: translateX(1500%) scaleX(3) } \n}\n@media (prefers-reduced-motion) {\n .ace_autocomplete.ace_loading:after {\n transform: translateX(625%) scaleX(2);\n animation: none;\n }\n}\n", "autocompletion.css", false); |
| 344 |
exports.AcePopup = AcePopup; |
| 345 |
exports.$singleLineEditor = $singleLineEditor; |
| 346 |
exports.getAriaId = getAriaId; |
| 347 |
|
| 348 |
}); |
| 349 |
|
| 350 |
ace.define("ace/snippets",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event_emitter","ace/lib/lang","ace/range","ace/range_list","ace/keyboard/hash_handler","ace/tokenizer","ace/clipboard","ace/editor"], function(require, exports, module){"use strict"; |
| 351 |
var dom = require("./lib/dom"); |
| 352 |
var oop = require("./lib/oop"); |
| 353 |
var EventEmitter = require("./lib/event_emitter").EventEmitter; |
| 354 |
var lang = require("./lib/lang"); |
| 355 |
var Range = require("./range").Range; |
| 356 |
var RangeList = require("./range_list").RangeList; |
| 357 |
var HashHandler = require("./keyboard/hash_handler").HashHandler; |
| 358 |
var Tokenizer = require("./tokenizer").Tokenizer; |
| 359 |
var clipboard = require("./clipboard"); |
| 360 |
var VARIABLES = { |
| 361 |
CURRENT_WORD: function (editor) { |
| 362 |
return editor.session.getTextRange(editor.session.getWordRange()); |
| 363 |
}, |
| 364 |
SELECTION: function (editor, name, indentation) { |
| 365 |
var text = editor.session.getTextRange(); |
| 366 |
if (indentation) |
| 367 |
return text.replace(/\n\r?([ \t]*\S)/g, "\n" + indentation + "$1"); |
| 368 |
return text; |
| 369 |
}, |
| 370 |
CURRENT_LINE: function (editor) { |
| 371 |
return editor.session.getLine(editor.getCursorPosition().row); |
| 372 |
}, |
| 373 |
PREV_LINE: function (editor) { |
| 374 |
return editor.session.getLine(editor.getCursorPosition().row - 1); |
| 375 |
}, |
| 376 |
LINE_INDEX: function (editor) { |
| 377 |
return editor.getCursorPosition().row; |
| 378 |
}, |
| 379 |
LINE_NUMBER: function (editor) { |
| 380 |
return editor.getCursorPosition().row + 1; |
| 381 |
}, |
| 382 |
SOFT_TABS: function (editor) { |
| 383 |
return editor.session.getUseSoftTabs() ? "YES" : "NO"; |
| 384 |
}, |
| 385 |
TAB_SIZE: function (editor) { |
| 386 |
return editor.session.getTabSize(); |
| 387 |
}, |
| 388 |
CLIPBOARD: function (editor) { |
| 389 |
return clipboard.getText && clipboard.getText(); |
| 390 |
}, |
| 391 |
FILENAME: function (editor) { |
| 392 |
return /[^/\\]*$/.exec(this.FILEPATH(editor))[0]; |
| 393 |
}, |
| 394 |
FILENAME_BASE: function (editor) { |
| 395 |
return /[^/\\]*$/.exec(this.FILEPATH(editor))[0].replace(/\.[^.]*$/, ""); |
| 396 |
}, |
| 397 |
DIRECTORY: function (editor) { |
| 398 |
return this.FILEPATH(editor).replace(/[^/\\]*$/, ""); |
| 399 |
}, |
| 400 |
FILEPATH: function (editor) { return "/not implemented.txt"; }, |
| 401 |
WORKSPACE_NAME: function () { return "Unknown"; }, |
| 402 |
FULLNAME: function () { return "Unknown"; }, |
| 403 |
BLOCK_COMMENT_START: function (editor) { |
| 404 |
var mode = editor.session.$mode || {}; |
| 405 |
return mode.blockComment && mode.blockComment.start || ""; |
| 406 |
}, |
| 407 |
BLOCK_COMMENT_END: function (editor) { |
| 408 |
var mode = editor.session.$mode || {}; |
| 409 |
return mode.blockComment && mode.blockComment.end || ""; |
| 410 |
}, |
| 411 |
LINE_COMMENT: function (editor) { |
| 412 |
var mode = editor.session.$mode || {}; |
| 413 |
return mode.lineCommentStart || ""; |
| 414 |
}, |
| 415 |
CURRENT_YEAR: date.bind(null, { year: "numeric" }), |
| 416 |
CURRENT_YEAR_SHORT: date.bind(null, { year: "2-digit" }), |
| 417 |
CURRENT_MONTH: date.bind(null, { month: "numeric" }), |
| 418 |
CURRENT_MONTH_NAME: date.bind(null, { month: "long" }), |
| 419 |
CURRENT_MONTH_NAME_SHORT: date.bind(null, { month: "short" }), |
| 420 |
CURRENT_DATE: date.bind(null, { day: "2-digit" }), |
| 421 |
CURRENT_DAY_NAME: date.bind(null, { weekday: "long" }), |
| 422 |
CURRENT_DAY_NAME_SHORT: date.bind(null, { weekday: "short" }), |
| 423 |
CURRENT_HOUR: date.bind(null, { hour: "2-digit", hour12: false }), |
| 424 |
CURRENT_MINUTE: date.bind(null, { minute: "2-digit" }), |
| 425 |
CURRENT_SECOND: date.bind(null, { second: "2-digit" }) |
| 426 |
}; |
| 427 |
VARIABLES.SELECTED_TEXT = VARIABLES.SELECTION; |
| 428 |
function date(dateFormat) { |
| 429 |
var str = new Date().toLocaleString("en-us", dateFormat); |
| 430 |
return str.length == 1 ? "0" + str : str; |
| 431 |
} |
| 432 |
var SnippetManager = (function () { |
| 433 |
function SnippetManager() { |
| 434 |
this.snippetMap = {}; |
| 435 |
this.snippetNameMap = {}; |
| 436 |
this.variables = VARIABLES; |
| 437 |
} |
| 438 |
SnippetManager.prototype.getTokenizer = function () { |
| 439 |
return SnippetManager["$tokenizer"] || this.createTokenizer(); |
| 440 |
}; |
| 441 |
SnippetManager.prototype.createTokenizer = function () { |
| 442 |
function TabstopToken(str) { |
| 443 |
str = str.substr(1); |
| 444 |
if (/^\d+$/.test(str)) |
| 445 |
return [{ tabstopId: parseInt(str, 10) }]; |
| 446 |
return [{ text: str }]; |
| 447 |
} |
| 448 |
function escape(ch) { |
| 449 |
return "(?:[^\\\\" + ch + "]|\\\\.)"; |
| 450 |
} |
| 451 |
var formatMatcher = { |
| 452 |
regex: "/(" + escape("/") + "+)/", |
| 453 |
onMatch: function (val, state, stack) { |
| 454 |
var ts = stack[0]; |
| 455 |
ts.fmtString = true; |
| 456 |
ts.guard = val.slice(1, -1); |
| 457 |
ts.flag = ""; |
| 458 |
return ""; |
| 459 |
}, |
| 460 |
next: "formatString" |
| 461 |
}; |
| 462 |
SnippetManager["$tokenizer"] = new Tokenizer({ |
| 463 |
start: [ |
| 464 |
{ regex: /\\./, onMatch: function (val, state, stack) { |
| 465 |
var ch = val[1]; |
| 466 |
if (ch == "}" && stack.length) { |
| 467 |
val = ch; |
| 468 |
} |
| 469 |
else if ("`$\\".indexOf(ch) != -1) { |
| 470 |
val = ch; |
| 471 |
} |
| 472 |
return [val]; |
| 473 |
} }, |
| 474 |
{ regex: /}/, onMatch: function (val, state, stack) { |
| 475 |
return [stack.length ? stack.shift() : val]; |
| 476 |
} }, |
| 477 |
{ regex: /\$(?:\d+|\w+)/, onMatch: TabstopToken }, |
| 478 |
{ regex: /\$\{[\dA-Z_a-z]+/, onMatch: function (str, state, stack) { |
| 479 |
var t = TabstopToken(str.substr(1)); |
| 480 |
stack.unshift(t[0]); |
| 481 |
return t; |
| 482 |
}, next: "snippetVar" }, |
| 483 |
{ regex: /\n/, token: "newline", merge: false } |
| 484 |
], |
| 485 |
snippetVar: [ |
| 486 |
{ regex: "\\|" + escape("\\|") + "*\\|", onMatch: function (val, state, stack) { |
| 487 |
var choices = val.slice(1, -1).replace(/\\[,|\\]|,/g, function (operator) { |
| 488 |
return operator.length == 2 ? operator[1] : "\x00"; |
| 489 |
}).split("\x00").map(function (value) { |
| 490 |
return { value: value }; |
| 491 |
}); |
| 492 |
stack[0].choices = choices; |
| 493 |
return [choices[0]]; |
| 494 |
}, next: "start" }, |
| 495 |
formatMatcher, |
| 496 |
{ regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "start" } |
| 497 |
], |
| 498 |
formatString: [ |
| 499 |
{ regex: /:/, onMatch: function (val, state, stack) { |
| 500 |
if (stack.length && stack[0].expectElse) { |
| 501 |
stack[0].expectElse = false; |
| 502 |
stack[0].ifEnd = { elseEnd: stack[0] }; |
| 503 |
return [stack[0].ifEnd]; |
| 504 |
} |
| 505 |
return ":"; |
| 506 |
} }, |
| 507 |
{ regex: /\\./, onMatch: function (val, state, stack) { |
| 508 |
var ch = val[1]; |
| 509 |
if (ch == "}" && stack.length) |
| 510 |
val = ch; |
| 511 |
else if ("`$\\".indexOf(ch) != -1) |
| 512 |
val = ch; |
| 513 |
else if (ch == "n") |
| 514 |
val = "\n"; |
| 515 |
else if (ch == "t") |
| 516 |
val = "\t"; |
| 517 |
else if ("ulULE".indexOf(ch) != -1) |
| 518 |
val = { changeCase: ch, local: ch > "a" }; |
| 519 |
return [val]; |
| 520 |
} }, |
| 521 |
{ regex: "/\\w*}", onMatch: function (val, state, stack) { |
| 522 |
var next = stack.shift(); |
| 523 |
if (next) |
| 524 |
next.flag = val.slice(1, -1); |
| 525 |
this.next = next && next.tabstopId ? "start" : ""; |
| 526 |
return [next || val]; |
| 527 |
}, next: "start" }, |
| 528 |
{ regex: /\$(?:\d+|\w+)/, onMatch: function (val, state, stack) { |
| 529 |
return [{ text: val.slice(1) }]; |
| 530 |
} }, |
| 531 |
{ regex: /\${\w+/, onMatch: function (val, state, stack) { |
| 532 |
var token = { text: val.slice(2) }; |
| 533 |
stack.unshift(token); |
| 534 |
return [token]; |
| 535 |
}, next: "formatStringVar" }, |
| 536 |
{ regex: /\n/, token: "newline", merge: false }, |
| 537 |
{ regex: /}/, onMatch: function (val, state, stack) { |
| 538 |
var next = stack.shift(); |
| 539 |
this.next = next && next.tabstopId ? "start" : ""; |
| 540 |
return [next || val]; |
| 541 |
}, next: "start" } |
| 542 |
], |
| 543 |
formatStringVar: [ |
| 544 |
{ regex: /:\/\w+}/, onMatch: function (val, state, stack) { |
| 545 |
var ts = stack[0]; |
| 546 |
ts.formatFunction = val.slice(2, -1); |
| 547 |
return [stack.shift()]; |
| 548 |
}, next: "formatString" }, |
| 549 |
formatMatcher, |
| 550 |
{ regex: /:[\?\-+]?/, onMatch: function (val, state, stack) { |
| 551 |
if (val[1] == "+") |
| 552 |
stack[0].ifEnd = stack[0]; |
| 553 |
if (val[1] == "?") |
| 554 |
stack[0].expectElse = true; |
| 555 |
}, next: "formatString" }, |
| 556 |
{ regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "formatString" } |
| 557 |
] |
| 558 |
}); |
| 559 |
return SnippetManager["$tokenizer"]; |
| 560 |
}; |
| 561 |
SnippetManager.prototype.tokenizeTmSnippet = function (str, startState) { |
| 562 |
return this.getTokenizer().getLineTokens(str, startState).tokens.map(function (x) { |
| 563 |
return x.value || x; |
| 564 |
}); |
| 565 |
}; |
| 566 |
SnippetManager.prototype.getVariableValue = function (editor, name, indentation) { |
| 567 |
if (/^\d+$/.test(name)) |
| 568 |
return (this.variables.__ || {})[name] || ""; |
| 569 |
if (/^[A-Z]\d+$/.test(name)) |
| 570 |
return (this.variables[name[0] + "__"] || {})[name.substr(1)] || ""; |
| 571 |
name = name.replace(/^TM_/, ""); |
| 572 |
if (!this.variables.hasOwnProperty(name)) |
| 573 |
return ""; |
| 574 |
var value = this.variables[name]; |
| 575 |
if (typeof value == "function") |
| 576 |
value = this.variables[name](editor, name, indentation); |
| 577 |
return value == null ? "" : value; |
| 578 |
}; |
| 579 |
SnippetManager.prototype.tmStrFormat = function (str, ch, editor) { |
| 580 |
if (!ch.fmt) |
| 581 |
return str; |
| 582 |
var flag = ch.flag || ""; |
| 583 |
var re = ch.guard; |
| 584 |
re = new RegExp(re, flag.replace(/[^gim]/g, "")); |
| 585 |
var fmtTokens = typeof ch.fmt == "string" ? this.tokenizeTmSnippet(ch.fmt, "formatString") : ch.fmt; |
| 586 |
var _self = this; |
| 587 |
var formatted = str.replace(re, function () { |
| 588 |
var oldArgs = _self.variables.__; |
| 589 |
_self.variables.__ = [].slice.call(arguments); |
| 590 |
var fmtParts = _self.resolveVariables(fmtTokens, editor); |
| 591 |
var gChangeCase = "E"; |
| 592 |
for (var i = 0; i < fmtParts.length; i++) { |
| 593 |
var ch = fmtParts[i]; |
| 594 |
if (typeof ch == "object") { |
| 595 |
fmtParts[i] = ""; |
| 596 |
if (ch.changeCase && ch.local) { |
| 597 |
var next = fmtParts[i + 1]; |
| 598 |
if (next && typeof next == "string") { |
| 599 |
if (ch.changeCase == "u") |
| 600 |
fmtParts[i] = next[0].toUpperCase(); |
| 601 |
else |
| 602 |
fmtParts[i] = next[0].toLowerCase(); |
| 603 |
fmtParts[i + 1] = next.substr(1); |
| 604 |
} |
| 605 |
} |
| 606 |
else if (ch.changeCase) { |
| 607 |
gChangeCase = ch.changeCase; |
| 608 |
} |
| 609 |
} |
| 610 |
else if (gChangeCase == "U") { |
| 611 |
fmtParts[i] = ch.toUpperCase(); |
| 612 |
} |
| 613 |
else if (gChangeCase == "L") { |
| 614 |
fmtParts[i] = ch.toLowerCase(); |
| 615 |
} |
| 616 |
} |
| 617 |
_self.variables.__ = oldArgs; |
| 618 |
return fmtParts.join(""); |
| 619 |
}); |
| 620 |
return formatted; |
| 621 |
}; |
| 622 |
SnippetManager.prototype.tmFormatFunction = function (str, ch, editor) { |
| 623 |
if (ch.formatFunction == "upcase") |
| 624 |
return str.toUpperCase(); |
| 625 |
if (ch.formatFunction == "downcase") |
| 626 |
return str.toLowerCase(); |
| 627 |
return str; |
| 628 |
}; |
| 629 |
SnippetManager.prototype.resolveVariables = function (snippet, editor) { |
| 630 |
var result = []; |
| 631 |
var indentation = ""; |
| 632 |
var afterNewLine = true; |
| 633 |
for (var i = 0; i < snippet.length; i++) { |
| 634 |
var ch = snippet[i]; |
| 635 |
if (typeof ch == "string") { |
| 636 |
result.push(ch); |
| 637 |
if (ch == "\n") { |
| 638 |
afterNewLine = true; |
| 639 |
indentation = ""; |
| 640 |
} |
| 641 |
else if (afterNewLine) { |
| 642 |
indentation = /^\t*/.exec(ch)[0]; |
| 643 |
afterNewLine = /\S/.test(ch); |
| 644 |
} |
| 645 |
continue; |
| 646 |
} |
| 647 |
if (!ch) |
| 648 |
continue; |
| 649 |
afterNewLine = false; |
| 650 |
if (ch.fmtString) { |
| 651 |
var j = snippet.indexOf(ch, i + 1); |
| 652 |
if (j == -1) |
| 653 |
j = snippet.length; |
| 654 |
ch.fmt = snippet.slice(i + 1, j); |
| 655 |
i = j; |
| 656 |
} |
| 657 |
if (ch.text) { |
| 658 |
var value = this.getVariableValue(editor, ch.text, indentation) + ""; |
| 659 |
if (ch.fmtString) |
| 660 |
value = this.tmStrFormat(value, ch, editor); |
| 661 |
if (ch.formatFunction) |
| 662 |
value = this.tmFormatFunction(value, ch, editor); |
| 663 |
if (value && !ch.ifEnd) { |
| 664 |
result.push(value); |
| 665 |
gotoNext(ch); |
| 666 |
} |
| 667 |
else if (!value && ch.ifEnd) { |
| 668 |
gotoNext(ch.ifEnd); |
| 669 |
} |
| 670 |
} |
| 671 |
else if (ch.elseEnd) { |
| 672 |
gotoNext(ch.elseEnd); |
| 673 |
} |
| 674 |
else if (ch.tabstopId != null) { |
| 675 |
result.push(ch); |
| 676 |
} |
| 677 |
else if (ch.changeCase != null) { |
| 678 |
result.push(ch); |
| 679 |
} |
| 680 |
} |
| 681 |
function gotoNext(ch) { |
| 682 |
var i1 = snippet.indexOf(ch, i + 1); |
| 683 |
if (i1 != -1) |
| 684 |
i = i1; |
| 685 |
} |
| 686 |
return result; |
| 687 |
}; |
| 688 |
SnippetManager.prototype.getDisplayTextForSnippet = function (editor, snippetText) { |
| 689 |
var processedSnippet = processSnippetText.call(this, editor, snippetText); |
| 690 |
return processedSnippet.text; |
| 691 |
}; |
| 692 |
SnippetManager.prototype.insertSnippetForSelection = function (editor, snippetText, options) { |
| 693 |
if (options === void 0) { options = {}; } |
| 694 |
var processedSnippet = processSnippetText.call(this, editor, snippetText, options); |
| 695 |
var range = editor.getSelectionRange(); |
| 696 |
var end = editor.session.replace(range, processedSnippet.text); |
| 697 |
var tabstopManager = new TabstopManager(editor); |
| 698 |
var selectionId = editor.inVirtualSelectionMode && editor.selection.index; |
| 699 |
tabstopManager.addTabstops(processedSnippet.tabstops, range.start, end, selectionId); |
| 700 |
}; |
| 701 |
SnippetManager.prototype.insertSnippet = function (editor, snippetText, options) { |
| 702 |
if (options === void 0) { options = {}; } |
| 703 |
var self = this; |
| 704 |
if (editor.inVirtualSelectionMode) |
| 705 |
return self.insertSnippetForSelection(editor, snippetText, options); |
| 706 |
editor.forEachSelection(function () { |
| 707 |
self.insertSnippetForSelection(editor, snippetText, options); |
| 708 |
}, null, { keepOrder: true }); |
| 709 |
if (editor.tabstopManager) |
| 710 |
editor.tabstopManager.tabNext(); |
| 711 |
}; |
| 712 |
SnippetManager.prototype.$getScope = function (editor) { |
| 713 |
var scope = editor.session.$mode.$id || ""; |
| 714 |
scope = scope.split("/").pop(); |
| 715 |
if (scope === "html" || scope === "php") { |
| 716 |
if (scope === "php" && !editor.session.$mode.inlinePhp) |
| 717 |
scope = "html"; |
| 718 |
var c = editor.getCursorPosition(); |
| 719 |
var state = editor.session.getState(c.row); |
| 720 |
if (typeof state === "object") { |
| 721 |
state = state[0]; |
| 722 |
} |
| 723 |
if (state.substring) { |
| 724 |
if (state.substring(0, 3) == "js-") |
| 725 |
scope = "javascript"; |
| 726 |
else if (state.substring(0, 4) == "css-") |
| 727 |
scope = "css"; |
| 728 |
else if (state.substring(0, 4) == "php-") |
| 729 |
scope = "php"; |
| 730 |
} |
| 731 |
} |
| 732 |
return scope; |
| 733 |
}; |
| 734 |
SnippetManager.prototype.getActiveScopes = function (editor) { |
| 735 |
var scope = this.$getScope(editor); |
| 736 |
var scopes = [scope]; |
| 737 |
var snippetMap = this.snippetMap; |
| 738 |
if (snippetMap[scope] && snippetMap[scope].includeScopes) { |
| 739 |
scopes.push.apply(scopes, snippetMap[scope].includeScopes); |
| 740 |
} |
| 741 |
scopes.push("_"); |
| 742 |
return scopes; |
| 743 |
}; |
| 744 |
SnippetManager.prototype.expandWithTab = function (editor, options) { |
| 745 |
var self = this; |
| 746 |
var result = editor.forEachSelection(function () { |
| 747 |
return self.expandSnippetForSelection(editor, options); |
| 748 |
}, null, { keepOrder: true }); |
| 749 |
if (result && editor.tabstopManager) |
| 750 |
editor.tabstopManager.tabNext(); |
| 751 |
return result; |
| 752 |
}; |
| 753 |
SnippetManager.prototype.expandSnippetForSelection = function (editor, options) { |
| 754 |
var cursor = editor.getCursorPosition(); |
| 755 |
var line = editor.session.getLine(cursor.row); |
| 756 |
var before = line.substring(0, cursor.column); |
| 757 |
var after = line.substr(cursor.column); |
| 758 |
var snippetMap = this.snippetMap; |
| 759 |
var snippet; |
| 760 |
this.getActiveScopes(editor).some(function (scope) { |
| 761 |
var snippets = snippetMap[scope]; |
| 762 |
if (snippets) |
| 763 |
snippet = this.findMatchingSnippet(snippets, before, after); |
| 764 |
return !!snippet; |
| 765 |
}, this); |
| 766 |
if (!snippet) |
| 767 |
return false; |
| 768 |
if (options && options.dryRun) |
| 769 |
return true; |
| 770 |
editor.session.doc.removeInLine(cursor.row, cursor.column - snippet.replaceBefore.length, cursor.column + snippet.replaceAfter.length); |
| 771 |
this.variables.M__ = snippet.matchBefore; |
| 772 |
this.variables.T__ = snippet.matchAfter; |
| 773 |
this.insertSnippetForSelection(editor, snippet.content); |
| 774 |
this.variables.M__ = this.variables.T__ = null; |
| 775 |
return true; |
| 776 |
}; |
| 777 |
SnippetManager.prototype.findMatchingSnippet = function (snippetList, before, after) { |
| 778 |
for (var i = snippetList.length; i--;) { |
| 779 |
var s = snippetList[i]; |
| 780 |
if (s.startRe && !s.startRe.test(before)) |
| 781 |
continue; |
| 782 |
if (s.endRe && !s.endRe.test(after)) |
| 783 |
continue; |
| 784 |
if (!s.startRe && !s.endRe) |
| 785 |
continue; |
| 786 |
s.matchBefore = s.startRe ? s.startRe.exec(before) : [""]; |
| 787 |
s.matchAfter = s.endRe ? s.endRe.exec(after) : [""]; |
| 788 |
s.replaceBefore = s.triggerRe ? s.triggerRe.exec(before)[0] : ""; |
| 789 |
s.replaceAfter = s.endTriggerRe ? s.endTriggerRe.exec(after)[0] : ""; |
| 790 |
return s; |
| 791 |
} |
| 792 |
}; |
| 793 |
SnippetManager.prototype.register = function (snippets, scope) { |
| 794 |
var snippetMap = this.snippetMap; |
| 795 |
var snippetNameMap = this.snippetNameMap; |
| 796 |
var self = this; |
| 797 |
if (!snippets) |
| 798 |
snippets = []; |
| 799 |
function wrapRegexp(src) { |
| 800 |
if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src)) |
| 801 |
src = "(?:" + src + ")"; |
| 802 |
return src || ""; |
| 803 |
} |
| 804 |
function guardedRegexp(re, guard, opening) { |
| 805 |
re = wrapRegexp(re); |
| 806 |
guard = wrapRegexp(guard); |
| 807 |
if (opening) { |
| 808 |
re = guard + re; |
| 809 |
if (re && re[re.length - 1] != "$") |
| 810 |
re = re + "$"; |
| 811 |
} |
| 812 |
else { |
| 813 |
re = re + guard; |
| 814 |
if (re && re[0] != "^") |
| 815 |
re = "^" + re; |
| 816 |
} |
| 817 |
return new RegExp(re); |
| 818 |
} |
| 819 |
function addSnippet(s) { |
| 820 |
if (!s.scope) |
| 821 |
s.scope = scope || "_"; |
| 822 |
scope = s.scope; |
| 823 |
if (!snippetMap[scope]) { |
| 824 |
snippetMap[scope] = []; |
| 825 |
snippetNameMap[scope] = {}; |
| 826 |
} |
| 827 |
var map = snippetNameMap[scope]; |
| 828 |
if (s.name) { |
| 829 |
var old = map[s.name]; |
| 830 |
if (old) |
| 831 |
self.unregister(old); |
| 832 |
map[s.name] = s; |
| 833 |
} |
| 834 |
snippetMap[scope].push(s); |
| 835 |
if (s.prefix) |
| 836 |
s.tabTrigger = s.prefix; |
| 837 |
if (!s.content && s.body) |
| 838 |
s.content = Array.isArray(s.body) ? s.body.join("\n") : s.body; |
| 839 |
if (s.tabTrigger && !s.trigger) { |
| 840 |
if (!s.guard && /^\w/.test(s.tabTrigger)) |
| 841 |
s.guard = "\\b"; |
| 842 |
s.trigger = lang.escapeRegExp(s.tabTrigger); |
| 843 |
} |
| 844 |
if (!s.trigger && !s.guard && !s.endTrigger && !s.endGuard) |
| 845 |
return; |
| 846 |
s.startRe = guardedRegexp(s.trigger, s.guard, true); |
| 847 |
s.triggerRe = new RegExp(s.trigger); |
| 848 |
s.endRe = guardedRegexp(s.endTrigger, s.endGuard, true); |
| 849 |
s.endTriggerRe = new RegExp(s.endTrigger); |
| 850 |
} |
| 851 |
if (Array.isArray(snippets)) { |
| 852 |
snippets.forEach(addSnippet); |
| 853 |
} |
| 854 |
else { |
| 855 |
Object.keys(snippets).forEach(function (key) { |
| 856 |
addSnippet(snippets[key]); |
| 857 |
}); |
| 858 |
} |
| 859 |
this._signal("registerSnippets", { scope: scope }); |
| 860 |
}; |
| 861 |
SnippetManager.prototype.unregister = function (snippets, scope) { |
| 862 |
var snippetMap = this.snippetMap; |
| 863 |
var snippetNameMap = this.snippetNameMap; |
| 864 |
function removeSnippet(s) { |
| 865 |
var nameMap = snippetNameMap[s.scope || scope]; |
| 866 |
if (nameMap && nameMap[s.name]) { |
| 867 |
delete nameMap[s.name]; |
| 868 |
var map = snippetMap[s.scope || scope]; |
| 869 |
var i = map && map.indexOf(s); |
| 870 |
if (i >= 0) |
| 871 |
map.splice(i, 1); |
| 872 |
} |
| 873 |
} |
| 874 |
if (snippets.content) |
| 875 |
removeSnippet(snippets); |
| 876 |
else if (Array.isArray(snippets)) |
| 877 |
snippets.forEach(removeSnippet); |
| 878 |
}; |
| 879 |
SnippetManager.prototype.parseSnippetFile = function (str) { |
| 880 |
str = str.replace(/\r/g, ""); |
| 881 |
var list = [], snippet = {}; |
| 882 |
var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm; |
| 883 |
var m; |
| 884 |
while (m = re.exec(str)) { |
| 885 |
if (m[1]) { |
| 886 |
try { |
| 887 |
snippet = JSON.parse(m[1]); |
| 888 |
list.push(snippet); |
| 889 |
} |
| 890 |
catch (e) { } |
| 891 |
} |
| 892 |
if (m[4]) { |
| 893 |
snippet.content = m[4].replace(/^\t/gm, ""); |
| 894 |
list.push(snippet); |
| 895 |
snippet = {}; |
| 896 |
} |
| 897 |
else { |
| 898 |
var key = m[2], val = m[3]; |
| 899 |
if (key == "regex") { |
| 900 |
var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g; |
| 901 |
snippet.guard = guardRe.exec(val)[1]; |
| 902 |
snippet.trigger = guardRe.exec(val)[1]; |
| 903 |
snippet.endTrigger = guardRe.exec(val)[1]; |
| 904 |
snippet.endGuard = guardRe.exec(val)[1]; |
| 905 |
} |
| 906 |
else if (key == "snippet") { |
| 907 |
snippet.tabTrigger = val.match(/^\S*/)[0]; |
| 908 |
if (!snippet.name) |
| 909 |
snippet.name = val; |
| 910 |
} |
| 911 |
else if (key) { |
| 912 |
snippet[key] = val; |
| 913 |
} |
| 914 |
} |
| 915 |
} |
| 916 |
return list; |
| 917 |
}; |
| 918 |
SnippetManager.prototype.getSnippetByName = function (name, editor) { |
| 919 |
var snippetMap = this.snippetNameMap; |
| 920 |
var snippet; |
| 921 |
this.getActiveScopes(editor).some(function (scope) { |
| 922 |
var snippets = snippetMap[scope]; |
| 923 |
if (snippets) |
| 924 |
snippet = snippets[name]; |
| 925 |
return !!snippet; |
| 926 |
}, this); |
| 927 |
return snippet; |
| 928 |
}; |
| 929 |
return SnippetManager; |
| 930 |
}()); |
| 931 |
oop.implement(SnippetManager.prototype, EventEmitter); |
| 932 |
var processSnippetText = function (editor, snippetText, options) { |
| 933 |
if (options === void 0) { options = {}; } |
| 934 |
var cursor = editor.getCursorPosition(); |
| 935 |
var line = editor.session.getLine(cursor.row); |
| 936 |
var tabString = editor.session.getTabString(); |
| 937 |
var indentString = line.match(/^\s*/)[0]; |
| 938 |
if (cursor.column < indentString.length) |
| 939 |
indentString = indentString.slice(0, cursor.column); |
| 940 |
snippetText = snippetText.replace(/\r/g, ""); |
| 941 |
var tokens = this.tokenizeTmSnippet(snippetText); |
| 942 |
tokens = this.resolveVariables(tokens, editor); |
| 943 |
tokens = tokens.map(function (x) { |
| 944 |
if (x == "\n" && !options.excludeExtraIndent) |
| 945 |
return x + indentString; |
| 946 |
if (typeof x == "string") |
| 947 |
return x.replace(/\t/g, tabString); |
| 948 |
return x; |
| 949 |
}); |
| 950 |
var tabstops = []; |
| 951 |
tokens.forEach(function (p, i) { |
| 952 |
if (typeof p != "object") |
| 953 |
return; |
| 954 |
var id = p.tabstopId; |
| 955 |
var ts = tabstops[id]; |
| 956 |
if (!ts) { |
| 957 |
ts = tabstops[id] = []; |
| 958 |
ts.index = id; |
| 959 |
ts.value = ""; |
| 960 |
ts.parents = {}; |
| 961 |
} |
| 962 |
if (ts.indexOf(p) !== -1) |
| 963 |
return; |
| 964 |
if (p.choices && !ts.choices) |
| 965 |
ts.choices = p.choices; |
| 966 |
ts.push(p); |
| 967 |
var i1 = tokens.indexOf(p, i + 1); |
| 968 |
if (i1 === -1) |
| 969 |
return; |
| 970 |
var value = tokens.slice(i + 1, i1); |
| 971 |
var isNested = value.some(function (t) { return typeof t === "object"; }); |
| 972 |
if (isNested && !ts.value) { |
| 973 |
ts.value = value; |
| 974 |
} |
| 975 |
else if (value.length && (!ts.value || typeof ts.value !== "string")) { |
| 976 |
ts.value = value.join(""); |
| 977 |
} |
| 978 |
}); |
| 979 |
tabstops.forEach(function (ts) { ts.length = 0; }); |
| 980 |
var expanding = {}; |
| 981 |
function copyValue(val) { |
| 982 |
var copy = []; |
| 983 |
for (var i = 0; i < val.length; i++) { |
| 984 |
var p = val[i]; |
| 985 |
if (typeof p == "object") { |
| 986 |
if (expanding[p.tabstopId]) |
| 987 |
continue; |
| 988 |
var j = val.lastIndexOf(p, i - 1); |
| 989 |
p = copy[j] || { tabstopId: p.tabstopId }; |
| 990 |
} |
| 991 |
copy[i] = p; |
| 992 |
} |
| 993 |
return copy; |
| 994 |
} |
| 995 |
for (var i = 0; i < tokens.length; i++) { |
| 996 |
var p = tokens[i]; |
| 997 |
if (typeof p != "object") |
| 998 |
continue; |
| 999 |
var id = p.tabstopId; |
| 1000 |
var ts = tabstops[id]; |
| 1001 |
var i1 = tokens.indexOf(p, i + 1); |
| 1002 |
if (expanding[id]) { |
| 1003 |
if (expanding[id] === p) { |
| 1004 |
delete expanding[id]; |
| 1005 |
Object.keys(expanding).forEach(function (parentId) { |
| 1006 |
ts.parents[parentId] = true; |
| 1007 |
}); |
| 1008 |
} |
| 1009 |
continue; |
| 1010 |
} |
| 1011 |
expanding[id] = p; |
| 1012 |
var value = ts.value; |
| 1013 |
if (typeof value !== "string") |
| 1014 |
value = copyValue(value); |
| 1015 |
else if (p.fmt) |
| 1016 |
value = this.tmStrFormat(value, p, editor); |
| 1017 |
tokens.splice.apply(tokens, [i + 1, Math.max(0, i1 - i)].concat(value, p)); |
| 1018 |
if (ts.indexOf(p) === -1) |
| 1019 |
ts.push(p); |
| 1020 |
} |
| 1021 |
var row = 0, column = 0; |
| 1022 |
var text = ""; |
| 1023 |
tokens.forEach(function (t) { |
| 1024 |
if (typeof t === "string") { |
| 1025 |
var lines = t.split("\n"); |
| 1026 |
if (lines.length > 1) { |
| 1027 |
column = lines[lines.length - 1].length; |
| 1028 |
row += lines.length - 1; |
| 1029 |
} |
| 1030 |
else |
| 1031 |
column += t.length; |
| 1032 |
text += t; |
| 1033 |
} |
| 1034 |
else if (t) { |
| 1035 |
if (!t.start) |
| 1036 |
t.start = { row: row, column: column }; |
| 1037 |
else |
| 1038 |
t.end = { row: row, column: column }; |
| 1039 |
} |
| 1040 |
}); |
| 1041 |
return { |
| 1042 |
text: text, |
| 1043 |
tabstops: tabstops, |
| 1044 |
tokens: tokens |
| 1045 |
}; |
| 1046 |
}; |
| 1047 |
var TabstopManager = (function () { |
| 1048 |
function TabstopManager(editor) { |
| 1049 |
this.index = 0; |
| 1050 |
this.ranges = []; |
| 1051 |
this.tabstops = []; |
| 1052 |
if (editor.tabstopManager) |
| 1053 |
return editor.tabstopManager; |
| 1054 |
editor.tabstopManager = this; |
| 1055 |
this.$onChange = this.onChange.bind(this); |
| 1056 |
this.$onChangeSelection = lang.delayedCall(this.onChangeSelection.bind(this)).schedule; |
| 1057 |
this.$onChangeSession = this.onChangeSession.bind(this); |
| 1058 |
this.$onAfterExec = this.onAfterExec.bind(this); |
| 1059 |
this.attach(editor); |
| 1060 |
} |
| 1061 |
TabstopManager.prototype.attach = function (editor) { |
| 1062 |
this.$openTabstops = null; |
| 1063 |
this.selectedTabstop = null; |
| 1064 |
this.editor = editor; |
| 1065 |
this.session = editor.session; |
| 1066 |
this.editor.on("change", this.$onChange); |
| 1067 |
this.editor.on("changeSelection", this.$onChangeSelection); |
| 1068 |
this.editor.on("changeSession", this.$onChangeSession); |
| 1069 |
this.editor.commands.on("afterExec", this.$onAfterExec); |
| 1070 |
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler); |
| 1071 |
}; |
| 1072 |
TabstopManager.prototype.detach = function () { |
| 1073 |
this.tabstops.forEach(this.removeTabstopMarkers, this); |
| 1074 |
this.ranges.length = 0; |
| 1075 |
this.tabstops.length = 0; |
| 1076 |
this.selectedTabstop = null; |
| 1077 |
this.editor.off("change", this.$onChange); |
| 1078 |
this.editor.off("changeSelection", this.$onChangeSelection); |
| 1079 |
this.editor.off("changeSession", this.$onChangeSession); |
| 1080 |
this.editor.commands.off("afterExec", this.$onAfterExec); |
| 1081 |
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler); |
| 1082 |
this.editor.tabstopManager = null; |
| 1083 |
this.session = null; |
| 1084 |
this.editor = null; |
| 1085 |
}; |
| 1086 |
TabstopManager.prototype.onChange = function (delta) { |
| 1087 |
var isRemove = delta.action[0] == "r"; |
| 1088 |
var selectedTabstop = this.selectedTabstop || {}; |
| 1089 |
var parents = selectedTabstop.parents || {}; |
| 1090 |
var tabstops = this.tabstops.slice(); |
| 1091 |
for (var i = 0; i < tabstops.length; i++) { |
| 1092 |
var ts = tabstops[i]; |
| 1093 |
var active = ts == selectedTabstop || parents[ts.index]; |
| 1094 |
ts.rangeList.$bias = active ? 0 : 1; |
| 1095 |
if (delta.action == "remove" && ts !== selectedTabstop) { |
| 1096 |
var parentActive = ts.parents && ts.parents[selectedTabstop.index]; |
| 1097 |
var startIndex = ts.rangeList.pointIndex(delta.start, parentActive); |
| 1098 |
startIndex = startIndex < 0 ? -startIndex - 1 : startIndex + 1; |
| 1099 |
var endIndex = ts.rangeList.pointIndex(delta.end, parentActive); |
| 1100 |
endIndex = endIndex < 0 ? -endIndex - 1 : endIndex - 1; |
| 1101 |
var toRemove = ts.rangeList.ranges.slice(startIndex, endIndex); |
| 1102 |
for (var j = 0; j < toRemove.length; j++) |
| 1103 |
this.removeRange(toRemove[j]); |
| 1104 |
} |
| 1105 |
ts.rangeList.$onChange(delta); |
| 1106 |
} |
| 1107 |
var session = this.session; |
| 1108 |
if (!this.$inChange && isRemove && session.getLength() == 1 && !session.getValue()) |
| 1109 |
this.detach(); |
| 1110 |
}; |
| 1111 |
TabstopManager.prototype.updateLinkedFields = function () { |
| 1112 |
var ts = this.selectedTabstop; |
| 1113 |
if (!ts || !ts.hasLinkedRanges || !ts.firstNonLinked) |
| 1114 |
return; |
| 1115 |
this.$inChange = true; |
| 1116 |
var session = this.session; |
| 1117 |
var text = session.getTextRange(ts.firstNonLinked); |
| 1118 |
for (var i = 0; i < ts.length; i++) { |
| 1119 |
var range = ts[i]; |
| 1120 |
if (!range.linked) |
| 1121 |
continue; |
| 1122 |
var original = range.original; |
| 1123 |
var fmt = exports.snippetManager.tmStrFormat(text, original, this.editor); |
| 1124 |
session.replace(range, fmt); |
| 1125 |
} |
| 1126 |
this.$inChange = false; |
| 1127 |
}; |
| 1128 |
TabstopManager.prototype.onAfterExec = function (e) { |
| 1129 |
if (e.command && !e.command.readOnly) |
| 1130 |
this.updateLinkedFields(); |
| 1131 |
}; |
| 1132 |
TabstopManager.prototype.onChangeSelection = function () { |
| 1133 |
if (!this.editor) |
| 1134 |
return; |
| 1135 |
var lead = this.editor.selection.lead; |
| 1136 |
var anchor = this.editor.selection.anchor; |
| 1137 |
var isEmpty = this.editor.selection.isEmpty(); |
| 1138 |
for (var i = 0; i < this.ranges.length; i++) { |
| 1139 |
if (this.ranges[i].linked) |
| 1140 |
continue; |
| 1141 |
var containsLead = this.ranges[i].contains(lead.row, lead.column); |
| 1142 |
var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column); |
| 1143 |
if (containsLead && containsAnchor) |
| 1144 |
return; |
| 1145 |
} |
| 1146 |
this.detach(); |
| 1147 |
}; |
| 1148 |
TabstopManager.prototype.onChangeSession = function () { |
| 1149 |
this.detach(); |
| 1150 |
}; |
| 1151 |
TabstopManager.prototype.tabNext = function (dir) { |
| 1152 |
var max = this.tabstops.length; |
| 1153 |
var index = this.index + (dir || 1); |
| 1154 |
index = Math.min(Math.max(index, 1), max); |
| 1155 |
if (index == max) |
| 1156 |
index = 0; |
| 1157 |
this.selectTabstop(index); |
| 1158 |
this.updateTabstopMarkers(); |
| 1159 |
if (index === 0) { |
| 1160 |
this.detach(); |
| 1161 |
} |
| 1162 |
}; |
| 1163 |
TabstopManager.prototype.selectTabstop = function (index) { |
| 1164 |
this.$openTabstops = null; |
| 1165 |
var ts = this.tabstops[this.index]; |
| 1166 |
if (ts) |
| 1167 |
this.addTabstopMarkers(ts); |
| 1168 |
this.index = index; |
| 1169 |
ts = this.tabstops[this.index]; |
| 1170 |
if (!ts || !ts.length) |
| 1171 |
return; |
| 1172 |
this.selectedTabstop = ts; |
| 1173 |
var range = ts.firstNonLinked || ts; |
| 1174 |
if (ts.choices) |
| 1175 |
range.cursor = range.start; |
| 1176 |
if (!this.editor.inVirtualSelectionMode) { |
| 1177 |
var sel = this.editor.multiSelect; |
| 1178 |
sel.toSingleRange(range); |
| 1179 |
for (var i = 0; i < ts.length; i++) { |
| 1180 |
if (ts.hasLinkedRanges && ts[i].linked) |
| 1181 |
continue; |
| 1182 |
sel.addRange(ts[i].clone(), true); |
| 1183 |
} |
| 1184 |
} |
| 1185 |
else { |
| 1186 |
this.editor.selection.fromOrientedRange(range); |
| 1187 |
} |
| 1188 |
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler); |
| 1189 |
if (this.selectedTabstop && this.selectedTabstop.choices) |
| 1190 |
this.editor.execCommand("startAutocomplete", { matches: this.selectedTabstop.choices }); |
| 1191 |
}; |
| 1192 |
TabstopManager.prototype.addTabstops = function (tabstops, start, end) { |
| 1193 |
var useLink = this.useLink || !this.editor.getOption("enableMultiselect"); |
| 1194 |
if (!this.$openTabstops) |
| 1195 |
this.$openTabstops = []; |
| 1196 |
if (!tabstops[0]) { |
| 1197 |
var p = Range.fromPoints(end, end); |
| 1198 |
moveRelative(p.start, start); |
| 1199 |
moveRelative(p.end, start); |
| 1200 |
tabstops[0] = [p]; |
| 1201 |
tabstops[0].index = 0; |
| 1202 |
} |
| 1203 |
var i = this.index; |
| 1204 |
var arg = [i + 1, 0]; |
| 1205 |
var ranges = this.ranges; |
| 1206 |
var snippetId = this.snippetId = (this.snippetId || 0) + 1; |
| 1207 |
tabstops.forEach(function (ts, index) { |
| 1208 |
var dest = this.$openTabstops[index] || ts; |
| 1209 |
dest.snippetId = snippetId; |
| 1210 |
for (var i = 0; i < ts.length; i++) { |
| 1211 |
var p = ts[i]; |
| 1212 |
var range = Range.fromPoints(p.start, p.end || p.start); |
| 1213 |
movePoint(range.start, start); |
| 1214 |
movePoint(range.end, start); |
| 1215 |
range.original = p; |
| 1216 |
range.tabstop = dest; |
| 1217 |
ranges.push(range); |
| 1218 |
if (dest != ts) |
| 1219 |
dest.unshift(range); |
| 1220 |
else |
| 1221 |
dest[i] = range; |
| 1222 |
if (p.fmtString || (dest.firstNonLinked && useLink)) { |
| 1223 |
range.linked = true; |
| 1224 |
dest.hasLinkedRanges = true; |
| 1225 |
} |
| 1226 |
else if (!dest.firstNonLinked) |
| 1227 |
dest.firstNonLinked = range; |
| 1228 |
} |
| 1229 |
if (!dest.firstNonLinked) |
| 1230 |
dest.hasLinkedRanges = false; |
| 1231 |
if (dest === ts) { |
| 1232 |
arg.push(dest); |
| 1233 |
this.$openTabstops[index] = dest; |
| 1234 |
} |
| 1235 |
this.addTabstopMarkers(dest); |
| 1236 |
dest.rangeList = dest.rangeList || new RangeList(); |
| 1237 |
dest.rangeList.$bias = 0; |
| 1238 |
dest.rangeList.addList(dest); |
| 1239 |
}, this); |
| 1240 |
if (arg.length > 2) { |
| 1241 |
if (this.tabstops.length) |
| 1242 |
arg.push(arg.splice(2, 1)[0]); |
| 1243 |
this.tabstops.splice.apply(this.tabstops, arg); |
| 1244 |
} |
| 1245 |
}; |
| 1246 |
TabstopManager.prototype.addTabstopMarkers = function (ts) { |
| 1247 |
var session = this.session; |
| 1248 |
ts.forEach(function (range) { |
| 1249 |
if (!range.markerId) |
| 1250 |
range.markerId = session.addMarker(range, "ace_snippet-marker", "text"); |
| 1251 |
}); |
| 1252 |
}; |
| 1253 |
TabstopManager.prototype.removeTabstopMarkers = function (ts) { |
| 1254 |
var session = this.session; |
| 1255 |
ts.forEach(function (range) { |
| 1256 |
session.removeMarker(range.markerId); |
| 1257 |
range.markerId = null; |
| 1258 |
}); |
| 1259 |
}; |
| 1260 |
TabstopManager.prototype.updateTabstopMarkers = function () { |
| 1261 |
if (!this.selectedTabstop) |
| 1262 |
return; |
| 1263 |
var currentSnippetId = this.selectedTabstop.snippetId; |
| 1264 |
if (this.selectedTabstop.index === 0) { |
| 1265 |
currentSnippetId--; |
| 1266 |
} |
| 1267 |
this.tabstops.forEach(function (ts) { |
| 1268 |
if (ts.snippetId === currentSnippetId) |
| 1269 |
this.addTabstopMarkers(ts); |
| 1270 |
else |
| 1271 |
this.removeTabstopMarkers(ts); |
| 1272 |
}, this); |
| 1273 |
}; |
| 1274 |
TabstopManager.prototype.removeRange = function (range) { |
| 1275 |
var i = range.tabstop.indexOf(range); |
| 1276 |
if (i != -1) |
| 1277 |
range.tabstop.splice(i, 1); |
| 1278 |
i = this.ranges.indexOf(range); |
| 1279 |
if (i != -1) |
| 1280 |
this.ranges.splice(i, 1); |
| 1281 |
i = range.tabstop.rangeList.ranges.indexOf(range); |
| 1282 |
if (i != -1) |
| 1283 |
range.tabstop.splice(i, 1); |
| 1284 |
this.session.removeMarker(range.markerId); |
| 1285 |
if (!range.tabstop.length) { |
| 1286 |
i = this.tabstops.indexOf(range.tabstop); |
| 1287 |
if (i != -1) |
| 1288 |
this.tabstops.splice(i, 1); |
| 1289 |
if (!this.tabstops.length) |
| 1290 |
this.detach(); |
| 1291 |
} |
| 1292 |
}; |
| 1293 |
return TabstopManager; |
| 1294 |
}()); |
| 1295 |
TabstopManager.prototype.keyboardHandler = new HashHandler(); |
| 1296 |
TabstopManager.prototype.keyboardHandler.bindKeys({ |
| 1297 |
"Tab": function (editor) { |
| 1298 |
if (exports.snippetManager && exports.snippetManager.expandWithTab(editor)) |
| 1299 |
return; |
| 1300 |
editor.tabstopManager.tabNext(1); |
| 1301 |
editor.renderer.scrollCursorIntoView(); |
| 1302 |
}, |
| 1303 |
"Shift-Tab": function (editor) { |
| 1304 |
editor.tabstopManager.tabNext(-1); |
| 1305 |
editor.renderer.scrollCursorIntoView(); |
| 1306 |
}, |
| 1307 |
"Esc": function (editor) { |
| 1308 |
editor.tabstopManager.detach(); |
| 1309 |
} |
| 1310 |
}); |
| 1311 |
var movePoint = function (point, diff) { |
| 1312 |
if (point.row == 0) |
| 1313 |
point.column += diff.column; |
| 1314 |
point.row += diff.row; |
| 1315 |
}; |
| 1316 |
var moveRelative = function (point, start) { |
| 1317 |
if (point.row == start.row) |
| 1318 |
point.column -= start.column; |
| 1319 |
point.row -= start.row; |
| 1320 |
}; |
| 1321 |
dom.importCssString("\n.ace_snippet-marker {\n -moz-box-sizing: border-box;\n box-sizing: border-box;\n background: rgba(194, 193, 208, 0.09);\n border: 1px dotted rgba(211, 208, 235, 0.62);\n position: absolute;\n}", "snippets.css", false); |
| 1322 |
exports.snippetManager = new SnippetManager(); |
| 1323 |
var Editor = require("./editor").Editor; |
| 1324 |
(function () { |
| 1325 |
this.insertSnippet = function (content, options) { |
| 1326 |
return exports.snippetManager.insertSnippet(this, content, options); |
| 1327 |
}; |
| 1328 |
this.expandSnippet = function (options) { |
| 1329 |
return exports.snippetManager.expandWithTab(this, options); |
| 1330 |
}; |
| 1331 |
}).call(Editor.prototype); |
| 1332 |
|
| 1333 |
}); |
| 1334 |
|
| 1335 |
ace.define("ace/autocomplete/inline_screenreader",["require","exports","module"], function(require, exports, module){"use strict"; |
| 1336 |
var AceInlineScreenReader = (function () { |
| 1337 |
function AceInlineScreenReader(editor) { |
| 1338 |
this.editor = editor; |
| 1339 |
this.screenReaderDiv = document.createElement("div"); |
| 1340 |
this.screenReaderDiv.classList.add("ace_screenreader-only"); |
| 1341 |
this.editor.container.appendChild(this.screenReaderDiv); |
| 1342 |
} |
| 1343 |
AceInlineScreenReader.prototype.setScreenReaderContent = function (content) { |
| 1344 |
if (!this.popup && this.editor.completer && (this.editor.completer).popup) { |
| 1345 |
this.popup = (this.editor.completer).popup; |
| 1346 |
this.popup.renderer.on("afterRender", function () { |
| 1347 |
var row = this.popup.getRow(); |
| 1348 |
var t = this.popup.renderer.$textLayer; |
| 1349 |
var selected = t.element.childNodes[row - t.config.firstRow]; |
| 1350 |
if (selected) { |
| 1351 |
var idString = "doc-tooltip "; |
| 1352 |
for (var lineIndex = 0; lineIndex < this._lines.length; lineIndex++) { |
| 1353 |
idString += "ace-inline-screenreader-line-".concat(lineIndex, " "); |
| 1354 |
} |
| 1355 |
selected.setAttribute("aria-describedby", idString); |
| 1356 |
} |
| 1357 |
}.bind(this)); |
| 1358 |
} |
| 1359 |
while (this.screenReaderDiv.firstChild) { |
| 1360 |
this.screenReaderDiv.removeChild(this.screenReaderDiv.firstChild); |
| 1361 |
} |
| 1362 |
this._lines = content.split(/\r\n|\r|\n/); |
| 1363 |
var codeElement = this.createCodeBlock(); |
| 1364 |
this.screenReaderDiv.appendChild(codeElement); |
| 1365 |
}; |
| 1366 |
AceInlineScreenReader.prototype.destroy = function () { |
| 1367 |
this.screenReaderDiv.remove(); |
| 1368 |
}; |
| 1369 |
AceInlineScreenReader.prototype.createCodeBlock = function () { |
| 1370 |
var container = document.createElement("pre"); |
| 1371 |
container.setAttribute("id", "ace-inline-screenreader"); |
| 1372 |
for (var lineIndex = 0; lineIndex < this._lines.length; lineIndex++) { |
| 1373 |
var codeElement = document.createElement("code"); |
| 1374 |
codeElement.setAttribute("id", "ace-inline-screenreader-line-".concat(lineIndex)); |
| 1375 |
var line = document.createTextNode(this._lines[lineIndex]); |
| 1376 |
codeElement.appendChild(line); |
| 1377 |
container.appendChild(codeElement); |
| 1378 |
} |
| 1379 |
return container; |
| 1380 |
}; |
| 1381 |
return AceInlineScreenReader; |
| 1382 |
}()); |
| 1383 |
exports.AceInlineScreenReader = AceInlineScreenReader; |
| 1384 |
|
| 1385 |
}); |
| 1386 |
|
| 1387 |
ace.define("ace/autocomplete/inline",["require","exports","module","ace/snippets","ace/autocomplete/inline_screenreader"], function(require, exports, module){"use strict"; |
| 1388 |
var snippetManager = require("../snippets").snippetManager; |
| 1389 |
var AceInlineScreenReader = require("./inline_screenreader").AceInlineScreenReader; |
| 1390 |
var AceInline = (function () { |
| 1391 |
function AceInline() { |
| 1392 |
this.editor = null; |
| 1393 |
} |
| 1394 |
AceInline.prototype.show = function (editor, completion, prefix) { |
| 1395 |
prefix = prefix || ""; |
| 1396 |
if (editor && this.editor && this.editor !== editor) { |
| 1397 |
this.hide(); |
| 1398 |
this.editor = null; |
| 1399 |
this.inlineScreenReader = null; |
| 1400 |
} |
| 1401 |
if (!editor || !completion) { |
| 1402 |
return false; |
| 1403 |
} |
| 1404 |
if (!this.inlineScreenReader) { |
| 1405 |
this.inlineScreenReader = new AceInlineScreenReader(editor); |
| 1406 |
} |
| 1407 |
var displayText = completion.snippet ? snippetManager.getDisplayTextForSnippet(editor, completion.snippet) : completion.value; |
| 1408 |
if (completion.hideInlinePreview || !displayText || !displayText.startsWith(prefix)) { |
| 1409 |
return false; |
| 1410 |
} |
| 1411 |
this.editor = editor; |
| 1412 |
this.inlineScreenReader.setScreenReaderContent(displayText); |
| 1413 |
displayText = displayText.slice(prefix.length); |
| 1414 |
if (displayText === "") { |
| 1415 |
editor.removeGhostText(); |
| 1416 |
} |
| 1417 |
else { |
| 1418 |
editor.setGhostText(displayText); |
| 1419 |
} |
| 1420 |
return true; |
| 1421 |
}; |
| 1422 |
AceInline.prototype.isOpen = function () { |
| 1423 |
if (!this.editor) { |
| 1424 |
return false; |
| 1425 |
} |
| 1426 |
return !!this.editor.renderer.$ghostText; |
| 1427 |
}; |
| 1428 |
AceInline.prototype.hide = function () { |
| 1429 |
if (!this.editor) { |
| 1430 |
return false; |
| 1431 |
} |
| 1432 |
this.editor.removeGhostText(); |
| 1433 |
return true; |
| 1434 |
}; |
| 1435 |
AceInline.prototype.destroy = function () { |
| 1436 |
this.hide(); |
| 1437 |
this.editor = null; |
| 1438 |
if (this.inlineScreenReader) { |
| 1439 |
this.inlineScreenReader.destroy(); |
| 1440 |
this.inlineScreenReader = null; |
| 1441 |
} |
| 1442 |
}; |
| 1443 |
return AceInline; |
| 1444 |
}()); |
| 1445 |
exports.AceInline = AceInline; |
| 1446 |
|
| 1447 |
}); |
| 1448 |
|
| 1449 |
ace.define("ace/autocomplete/util",["require","exports","module"], function(require, exports, module){"use strict"; |
| 1450 |
exports.parForEach = function (array, fn, callback) { |
| 1451 |
var completed = 0; |
| 1452 |
var arLength = array.length; |
| 1453 |
if (arLength === 0) |
| 1454 |
callback(); |
| 1455 |
for (var i = 0; i < arLength; i++) { |
| 1456 |
fn(array[i], function (result, err) { |
| 1457 |
completed++; |
| 1458 |
if (completed === arLength) |
| 1459 |
callback(result, err); |
| 1460 |
}); |
| 1461 |
} |
| 1462 |
}; |
| 1463 |
var ID_REGEX = /[a-zA-Z_0-9\$\-\u00A2-\u2000\u2070-\uFFFF]/; |
| 1464 |
exports.retrievePrecedingIdentifier = function (text, pos, regex) { |
| 1465 |
regex = regex || ID_REGEX; |
| 1466 |
var buf = []; |
| 1467 |
for (var i = pos - 1; i >= 0; i--) { |
| 1468 |
if (regex.test(text[i])) |
| 1469 |
buf.push(text[i]); |
| 1470 |
else |
| 1471 |
break; |
| 1472 |
} |
| 1473 |
return buf.reverse().join(""); |
| 1474 |
}; |
| 1475 |
exports.retrieveFollowingIdentifier = function (text, pos, regex) { |
| 1476 |
regex = regex || ID_REGEX; |
| 1477 |
var buf = []; |
| 1478 |
for (var i = pos; i < text.length; i++) { |
| 1479 |
if (regex.test(text[i])) |
| 1480 |
buf.push(text[i]); |
| 1481 |
else |
| 1482 |
break; |
| 1483 |
} |
| 1484 |
return buf; |
| 1485 |
}; |
| 1486 |
exports.getCompletionPrefix = function (editor) { |
| 1487 |
var pos = editor.getCursorPosition(); |
| 1488 |
var line = editor.session.getLine(pos.row); |
| 1489 |
var prefix; |
| 1490 |
editor.completers.forEach(function (completer) { |
| 1491 |
if (completer.identifierRegexps) { |
| 1492 |
completer.identifierRegexps.forEach(function (identifierRegex) { |
| 1493 |
if (!prefix && identifierRegex) |
| 1494 |
prefix = this.retrievePrecedingIdentifier(line, pos.column, identifierRegex); |
| 1495 |
}.bind(this)); |
| 1496 |
} |
| 1497 |
}.bind(this)); |
| 1498 |
return prefix || this.retrievePrecedingIdentifier(line, pos.column); |
| 1499 |
}; |
| 1500 |
exports.triggerAutocomplete = function (editor) { |
| 1501 |
var pos = editor.getCursorPosition(); |
| 1502 |
var line = editor.session.getLine(pos.row); |
| 1503 |
var column = (pos.column === 0) ? 0 : pos.column - 1; |
| 1504 |
var previousChar = line[column]; |
| 1505 |
return editor.completers.some(function (el) { |
| 1506 |
if (el.triggerCharacters && Array.isArray(el.triggerCharacters)) { |
| 1507 |
return el.triggerCharacters.includes(previousChar); |
| 1508 |
} |
| 1509 |
}); |
| 1510 |
}; |
| 1511 |
|
| 1512 |
}); |
| 1513 |
|
| 1514 |
ace.define("ace/autocomplete",["require","exports","module","ace/keyboard/hash_handler","ace/autocomplete/popup","ace/autocomplete/inline","ace/autocomplete/popup","ace/autocomplete/util","ace/lib/lang","ace/lib/dom","ace/snippets","ace/config","ace/lib/event","ace/lib/scroll"], function(require, exports, module){"use strict"; |
| 1515 |
var HashHandler = require("./keyboard/hash_handler").HashHandler; |
| 1516 |
var AcePopup = require("./autocomplete/popup").AcePopup; |
| 1517 |
var AceInline = require("./autocomplete/inline").AceInline; |
| 1518 |
var getAriaId = require("./autocomplete/popup").getAriaId; |
| 1519 |
var util = require("./autocomplete/util"); |
| 1520 |
var lang = require("./lib/lang"); |
| 1521 |
var dom = require("./lib/dom"); |
| 1522 |
var snippetManager = require("./snippets").snippetManager; |
| 1523 |
var config = require("./config"); |
| 1524 |
var event = require("./lib/event"); |
| 1525 |
var preventParentScroll = require("./lib/scroll").preventParentScroll; |
| 1526 |
var destroyCompleter = function (e, editor) { |
| 1527 |
editor.completer && editor.completer.destroy(); |
| 1528 |
}; |
| 1529 |
var Autocomplete = (function () { |
| 1530 |
function Autocomplete() { |
| 1531 |
this.autoInsert = false; |
| 1532 |
this.autoSelect = true; |
| 1533 |
this.autoShown = false; |
| 1534 |
this.exactMatch = false; |
| 1535 |
this.inlineEnabled = false; |
| 1536 |
this.keyboardHandler = new HashHandler(); |
| 1537 |
this.keyboardHandler.bindKeys(this.commands); |
| 1538 |
this.parentNode = null; |
| 1539 |
this.setSelectOnHover = false; |
| 1540 |
this.hasSeen = new Set(); |
| 1541 |
this.showLoadingState = false; |
| 1542 |
this.stickySelectionDelay = 500; |
| 1543 |
this.blurListener = this.blurListener.bind(this); |
| 1544 |
this.changeListener = this.changeListener.bind(this); |
| 1545 |
this.mousedownListener = this.mousedownListener.bind(this); |
| 1546 |
this.mousewheelListener = this.mousewheelListener.bind(this); |
| 1547 |
this.onLayoutChange = this.onLayoutChange.bind(this); |
| 1548 |
this.changeTimer = lang.delayedCall(function () { |
| 1549 |
this.updateCompletions(true); |
| 1550 |
}.bind(this)); |
| 1551 |
this.tooltipTimer = lang.delayedCall(this.updateDocTooltip.bind(this), 50); |
| 1552 |
this.popupTimer = lang.delayedCall(this.$updatePopupPosition.bind(this), 50); |
| 1553 |
this.stickySelectionTimer = lang.delayedCall(function () { |
| 1554 |
this.stickySelection = true; |
| 1555 |
}.bind(this), this.stickySelectionDelay); |
| 1556 |
this.$firstOpenTimer = lang.delayedCall( function () { |
| 1557 |
var initialPosition = this.completionProvider && this.completionProvider.initialPosition; |
| 1558 |
if (this.autoShown || (this.popup && this.popup.isOpen) || !initialPosition || this.editor.completers.length === 0) |
| 1559 |
return; |
| 1560 |
this.completions = new FilteredList(Autocomplete.completionsForLoading); |
| 1561 |
this.openPopup(this.editor, initialPosition.prefix, false); |
| 1562 |
this.popup.renderer.setStyle("ace_loading", true); |
| 1563 |
}.bind(this), this.stickySelectionDelay); |
| 1564 |
} |
| 1565 |
Object.defineProperty(Autocomplete, "completionsForLoading", { |
| 1566 |
get: function () { |
| 1567 |
return [{ |
| 1568 |
caption: config.nls("Loading..."), |
| 1569 |
value: "" |
| 1570 |
}]; |
| 1571 |
}, |
| 1572 |
enumerable: false, |
| 1573 |
configurable: true |
| 1574 |
}); |
| 1575 |
Autocomplete.prototype.$init = function () { |
| 1576 |
this.popup = new AcePopup(this.parentNode || document.body || document.documentElement); |
| 1577 |
this.popup.on("click", function (e) { |
| 1578 |
this.insertMatch(); |
| 1579 |
e.stop(); |
| 1580 |
}.bind(this)); |
| 1581 |
this.popup.focus = this.editor.focus.bind(this.editor); |
| 1582 |
this.popup.on("show", this.$onPopupShow.bind(this)); |
| 1583 |
this.popup.on("hide", this.$onHidePopup.bind(this)); |
| 1584 |
this.popup.on("select", this.$onPopupChange.bind(this)); |
| 1585 |
event.addListener(this.popup.container, "mouseout", this.mouseOutListener.bind(this)); |
| 1586 |
this.popup.on("changeHoverMarker", this.tooltipTimer.bind(null, null)); |
| 1587 |
this.popup.renderer.on("afterRender", this.$onPopupRender.bind(this)); |
| 1588 |
return this.popup; |
| 1589 |
}; |
| 1590 |
Autocomplete.prototype.$initInline = function () { |
| 1591 |
if (!this.inlineEnabled || this.inlineRenderer) |
| 1592 |
return; |
| 1593 |
this.inlineRenderer = new AceInline(); |
| 1594 |
return this.inlineRenderer; |
| 1595 |
}; |
| 1596 |
Autocomplete.prototype.getPopup = function () { |
| 1597 |
return this.popup || this.$init(); |
| 1598 |
}; |
| 1599 |
Autocomplete.prototype.$onHidePopup = function () { |
| 1600 |
if (this.inlineRenderer) { |
| 1601 |
this.inlineRenderer.hide(); |
| 1602 |
} |
| 1603 |
this.hideDocTooltip(); |
| 1604 |
this.stickySelectionTimer.cancel(); |
| 1605 |
this.popupTimer.cancel(); |
| 1606 |
this.stickySelection = false; |
| 1607 |
}; |
| 1608 |
Autocomplete.prototype.$seen = function (completion) { |
| 1609 |
if (!this.hasSeen.has(completion) && completion && completion.completer && completion.completer.onSeen && typeof completion.completer.onSeen === "function") { |
| 1610 |
completion.completer.onSeen(this.editor, completion); |
| 1611 |
this.hasSeen.add(completion); |
| 1612 |
} |
| 1613 |
}; |
| 1614 |
Autocomplete.prototype.$onPopupChange = function (hide) { |
| 1615 |
if (this.inlineRenderer && this.inlineEnabled) { |
| 1616 |
var completion = hide ? null : this.popup.getData(this.popup.getRow()); |
| 1617 |
this.$updateGhostText(completion); |
| 1618 |
if (this.popup.isMouseOver && this.setSelectOnHover) { |
| 1619 |
this.tooltipTimer.call(null, null); |
| 1620 |
return; |
| 1621 |
} |
| 1622 |
this.popupTimer.schedule(); |
| 1623 |
this.tooltipTimer.schedule(); |
| 1624 |
} |
| 1625 |
else { |
| 1626 |
this.popupTimer.call(null, null); |
| 1627 |
this.tooltipTimer.call(null, null); |
| 1628 |
} |
| 1629 |
}; |
| 1630 |
Autocomplete.prototype.$updateGhostText = function (completion) { |
| 1631 |
var row = this.base.row; |
| 1632 |
var column = this.base.column; |
| 1633 |
var cursorColumn = this.editor.getCursorPosition().column; |
| 1634 |
var prefix = this.editor.session.getLine(row).slice(column, cursorColumn); |
| 1635 |
if (!this.inlineRenderer.show(this.editor, completion, prefix)) { |
| 1636 |
this.inlineRenderer.hide(); |
| 1637 |
} |
| 1638 |
else { |
| 1639 |
this.$seen(completion); |
| 1640 |
} |
| 1641 |
}; |
| 1642 |
Autocomplete.prototype.$onPopupRender = function () { |
| 1643 |
var inlineEnabled = this.inlineRenderer && this.inlineEnabled; |
| 1644 |
if (this.completions && this.completions.filtered && this.completions.filtered.length > 0) { |
| 1645 |
for (var i = this.popup.getFirstVisibleRow(); i <= this.popup.getLastVisibleRow(); i++) { |
| 1646 |
var completion = this.popup.getData(i); |
| 1647 |
if (completion && (!inlineEnabled || completion.hideInlinePreview)) { |
| 1648 |
this.$seen(completion); |
| 1649 |
} |
| 1650 |
} |
| 1651 |
} |
| 1652 |
}; |
| 1653 |
Autocomplete.prototype.$onPopupShow = function (hide) { |
| 1654 |
this.$onPopupChange(hide); |
| 1655 |
this.stickySelection = false; |
| 1656 |
if (this.stickySelectionDelay >= 0) |
| 1657 |
this.stickySelectionTimer.schedule(this.stickySelectionDelay); |
| 1658 |
}; |
| 1659 |
Autocomplete.prototype.observeLayoutChanges = function () { |
| 1660 |
if (this.$elements || !this.editor) |
| 1661 |
return; |
| 1662 |
window.addEventListener("resize", this.onLayoutChange, { passive: true }); |
| 1663 |
window.addEventListener("wheel", this.mousewheelListener); |
| 1664 |
var el = this.editor.container.parentNode; |
| 1665 |
var elements = []; |
| 1666 |
while (el) { |
| 1667 |
elements.push(el); |
| 1668 |
el.addEventListener("scroll", this.onLayoutChange, { passive: true }); |
| 1669 |
el = el.parentNode; |
| 1670 |
} |
| 1671 |
this.$elements = elements; |
| 1672 |
}; |
| 1673 |
Autocomplete.prototype.unObserveLayoutChanges = function () { |
| 1674 |
var _this = this; |
| 1675 |
window.removeEventListener("resize", this.onLayoutChange, { passive: true }); |
| 1676 |
window.removeEventListener("wheel", this.mousewheelListener); |
| 1677 |
this.$elements && this.$elements.forEach(function (el) { |
| 1678 |
el.removeEventListener("scroll", _this.onLayoutChange, { passive: true }); |
| 1679 |
}); |
| 1680 |
this.$elements = null; |
| 1681 |
}; |
| 1682 |
Autocomplete.prototype.onLayoutChange = function () { |
| 1683 |
if (!this.popup.isOpen) |
| 1684 |
return this.unObserveLayoutChanges(); |
| 1685 |
this.$updatePopupPosition(); |
| 1686 |
this.updateDocTooltip(); |
| 1687 |
}; |
| 1688 |
Autocomplete.prototype.$updatePopupPosition = function () { |
| 1689 |
var editor = this.editor; |
| 1690 |
var renderer = editor.renderer; |
| 1691 |
var lineHeight = renderer.layerConfig.lineHeight; |
| 1692 |
var pos = renderer.$cursorLayer.getPixelPosition(this.base, true); |
| 1693 |
pos.left -= this.popup.getTextLeftOffset(); |
| 1694 |
var rect = editor.container.getBoundingClientRect(); |
| 1695 |
pos.top += rect.top - renderer.layerConfig.offset; |
| 1696 |
pos.left += rect.left - editor.renderer.scrollLeft; |
| 1697 |
pos.left += renderer.gutterWidth; |
| 1698 |
var posGhostText = { |
| 1699 |
top: pos.top, |
| 1700 |
left: pos.left |
| 1701 |
}; |
| 1702 |
if (renderer.$ghostText && renderer.$ghostTextWidget) { |
| 1703 |
if (this.base.row === renderer.$ghostText.position.row) { |
| 1704 |
posGhostText.top += renderer.$ghostTextWidget.el.offsetHeight; |
| 1705 |
} |
| 1706 |
} |
| 1707 |
var editorContainerBottom = editor.container.getBoundingClientRect().bottom - lineHeight; |
| 1708 |
var lowestPosition = editorContainerBottom < posGhostText.top ? |
| 1709 |
{ top: editorContainerBottom, left: posGhostText.left } : |
| 1710 |
posGhostText; |
| 1711 |
if (this.popup.tryShow(lowestPosition, lineHeight, "bottom")) { |
| 1712 |
return; |
| 1713 |
} |
| 1714 |
if (this.popup.tryShow(pos, lineHeight, "top")) { |
| 1715 |
return; |
| 1716 |
} |
| 1717 |
this.popup.show(pos, lineHeight); |
| 1718 |
}; |
| 1719 |
Autocomplete.prototype.openPopup = function (editor, prefix, keepPopupPosition) { |
| 1720 |
this.$firstOpenTimer.cancel(); |
| 1721 |
if (!this.popup) |
| 1722 |
this.$init(); |
| 1723 |
if (this.inlineEnabled && !this.inlineRenderer) |
| 1724 |
this.$initInline(); |
| 1725 |
this.popup.autoSelect = this.autoSelect; |
| 1726 |
this.popup.setSelectOnHover(this.setSelectOnHover); |
| 1727 |
var oldRow = this.popup.getRow(); |
| 1728 |
var previousSelectedItem = this.popup.data[oldRow]; |
| 1729 |
this.popup.setData(this.completions.filtered, this.completions.filterText); |
| 1730 |
if (this.editor.textInput.setAriaOptions) { |
| 1731 |
this.editor.textInput.setAriaOptions({ |
| 1732 |
activeDescendant: getAriaId(this.popup.getRow()), |
| 1733 |
inline: this.inlineEnabled |
| 1734 |
}); |
| 1735 |
} |
| 1736 |
editor.keyBinding.addKeyboardHandler(this.keyboardHandler); |
| 1737 |
var newRow; |
| 1738 |
if (this.stickySelection) |
| 1739 |
newRow = this.popup.data.indexOf(previousSelectedItem); |
| 1740 |
if (!newRow || newRow === -1) |
| 1741 |
newRow = 0; |
| 1742 |
this.popup.setRow(this.autoSelect ? newRow : -1); |
| 1743 |
if (newRow === oldRow && previousSelectedItem !== this.completions.filtered[newRow]) |
| 1744 |
this.$onPopupChange(); |
| 1745 |
var inlineEnabled = this.inlineRenderer && this.inlineEnabled; |
| 1746 |
if (newRow === oldRow && inlineEnabled) { |
| 1747 |
var completion = this.popup.getData(this.popup.getRow()); |
| 1748 |
this.$updateGhostText(completion); |
| 1749 |
} |
| 1750 |
if (!keepPopupPosition) { |
| 1751 |
this.popup.setTheme(editor.getTheme()); |
| 1752 |
this.popup.setFontSize(editor.getFontSize()); |
| 1753 |
this.$updatePopupPosition(); |
| 1754 |
if (this.tooltipNode) { |
| 1755 |
this.updateDocTooltip(); |
| 1756 |
} |
| 1757 |
} |
| 1758 |
else if (keepPopupPosition && !prefix) { |
| 1759 |
this.detach(); |
| 1760 |
} |
| 1761 |
this.changeTimer.cancel(); |
| 1762 |
this.observeLayoutChanges(); |
| 1763 |
}; |
| 1764 |
Autocomplete.prototype.detach = function () { |
| 1765 |
if (this.editor) { |
| 1766 |
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler); |
| 1767 |
this.editor.off("changeSelection", this.changeListener); |
| 1768 |
this.editor.off("blur", this.blurListener); |
| 1769 |
this.editor.off("mousedown", this.mousedownListener); |
| 1770 |
this.editor.off("mousewheel", this.mousewheelListener); |
| 1771 |
} |
| 1772 |
this.$firstOpenTimer.cancel(); |
| 1773 |
this.changeTimer.cancel(); |
| 1774 |
this.hideDocTooltip(); |
| 1775 |
if (this.completionProvider) { |
| 1776 |
this.completionProvider.detach(); |
| 1777 |
} |
| 1778 |
if (this.popup && this.popup.isOpen) |
| 1779 |
this.popup.hide(); |
| 1780 |
if (this.popup && this.popup.renderer) { |
| 1781 |
this.popup.renderer.off("afterRender", this.$onPopupRender); |
| 1782 |
} |
| 1783 |
if (this.base) |
| 1784 |
this.base.detach(); |
| 1785 |
this.activated = false; |
| 1786 |
this.completionProvider = this.completions = this.base = null; |
| 1787 |
this.unObserveLayoutChanges(); |
| 1788 |
}; |
| 1789 |
Autocomplete.prototype.changeListener = function (e) { |
| 1790 |
var cursor = this.editor.selection.lead; |
| 1791 |
if (cursor.row != this.base.row || cursor.column < this.base.column) { |
| 1792 |
this.detach(); |
| 1793 |
} |
| 1794 |
if (this.activated) |
| 1795 |
this.changeTimer.schedule(); |
| 1796 |
else |
| 1797 |
this.detach(); |
| 1798 |
}; |
| 1799 |
Autocomplete.prototype.blurListener = function (e) { |
| 1800 |
var el = document.activeElement; |
| 1801 |
var text = this.editor.textInput.getElement(); |
| 1802 |
var fromTooltip = e.relatedTarget && this.tooltipNode && this.tooltipNode.contains(e.relatedTarget); |
| 1803 |
var container = this.popup && this.popup.container; |
| 1804 |
if (el != text && el.parentNode != container && !fromTooltip |
| 1805 |
&& el != this.tooltipNode && e.relatedTarget != text) { |
| 1806 |
this.detach(); |
| 1807 |
} |
| 1808 |
}; |
| 1809 |
Autocomplete.prototype.mousedownListener = function (e) { |
| 1810 |
this.detach(); |
| 1811 |
}; |
| 1812 |
Autocomplete.prototype.mousewheelListener = function (e) { |
| 1813 |
if (!this.popup.isMouseOver) |
| 1814 |
this.detach(); |
| 1815 |
}; |
| 1816 |
Autocomplete.prototype.mouseOutListener = function (e) { |
| 1817 |
if (this.popup.isOpen) |
| 1818 |
this.$updatePopupPosition(); |
| 1819 |
}; |
| 1820 |
Autocomplete.prototype.goTo = function (where) { |
| 1821 |
this.popup.goTo(where); |
| 1822 |
}; |
| 1823 |
Autocomplete.prototype.insertMatch = function (data, options) { |
| 1824 |
if (!data) |
| 1825 |
data = this.popup.getData(this.popup.getRow()); |
| 1826 |
if (!data) |
| 1827 |
return false; |
| 1828 |
if (data.value === "") |
| 1829 |
return this.detach(); |
| 1830 |
var completions = this.completions; |
| 1831 |
var result = this.getCompletionProvider().insertMatch(this.editor, data, completions.filterText, options); |
| 1832 |
if (this.completions == completions) |
| 1833 |
this.detach(); |
| 1834 |
return result; |
| 1835 |
}; |
| 1836 |
Autocomplete.prototype.showPopup = function (editor, options) { |
| 1837 |
if (this.editor) |
| 1838 |
this.detach(); |
| 1839 |
this.activated = true; |
| 1840 |
this.editor = editor; |
| 1841 |
if (editor.completer != this) { |
| 1842 |
if (editor.completer) |
| 1843 |
editor.completer.detach(); |
| 1844 |
editor.completer = this; |
| 1845 |
} |
| 1846 |
editor.on("changeSelection", this.changeListener); |
| 1847 |
editor.on("blur", this.blurListener); |
| 1848 |
editor.on("mousedown", this.mousedownListener); |
| 1849 |
editor.on("mousewheel", this.mousewheelListener); |
| 1850 |
this.updateCompletions(false, options); |
| 1851 |
}; |
| 1852 |
Autocomplete.prototype.getCompletionProvider = function (initialPosition) { |
| 1853 |
if (!this.completionProvider) |
| 1854 |
this.completionProvider = new CompletionProvider(initialPosition); |
| 1855 |
return this.completionProvider; |
| 1856 |
}; |
| 1857 |
Autocomplete.prototype.gatherCompletions = function (editor, callback) { |
| 1858 |
return this.getCompletionProvider().gatherCompletions(editor, callback); |
| 1859 |
}; |
| 1860 |
Autocomplete.prototype.updateCompletions = function (keepPopupPosition, options) { |
| 1861 |
if (keepPopupPosition && this.base && this.completions) { |
| 1862 |
var pos = this.editor.getCursorPosition(); |
| 1863 |
var prefix = this.editor.session.getTextRange({ start: this.base, end: pos }); |
| 1864 |
if (prefix == this.completions.filterText) |
| 1865 |
return; |
| 1866 |
this.completions.setFilter(prefix); |
| 1867 |
if (!this.completions.filtered.length) |
| 1868 |
return this.detach(); |
| 1869 |
if (this.completions.filtered.length == 1 |
| 1870 |
&& this.completions.filtered[0].value == prefix |
| 1871 |
&& !this.completions.filtered[0].snippet) |
| 1872 |
return this.detach(); |
| 1873 |
this.openPopup(this.editor, prefix, keepPopupPosition); |
| 1874 |
return; |
| 1875 |
} |
| 1876 |
if (options && options.matches) { |
| 1877 |
var pos = this.editor.getSelectionRange().start; |
| 1878 |
this.base = this.editor.session.doc.createAnchor(pos.row, pos.column); |
| 1879 |
this.base.$insertRight = true; |
| 1880 |
this.completions = new FilteredList(options.matches); |
| 1881 |
this.getCompletionProvider().completions = this.completions; |
| 1882 |
return this.openPopup(this.editor, "", keepPopupPosition); |
| 1883 |
} |
| 1884 |
var session = this.editor.getSession(); |
| 1885 |
var pos = this.editor.getCursorPosition(); |
| 1886 |
var prefix = util.getCompletionPrefix(this.editor); |
| 1887 |
this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length); |
| 1888 |
this.base.$insertRight = true; |
| 1889 |
var completionOptions = { |
| 1890 |
exactMatch: this.exactMatch, |
| 1891 |
ignoreCaption: this.ignoreCaption |
| 1892 |
}; |
| 1893 |
this.getCompletionProvider({ |
| 1894 |
prefix: prefix, |
| 1895 |
pos: pos |
| 1896 |
}).provideCompletions(this.editor, completionOptions, |
| 1897 |
function (err, completions, finished) { |
| 1898 |
var filtered = completions.filtered; |
| 1899 |
var prefix = util.getCompletionPrefix(this.editor); |
| 1900 |
this.$firstOpenTimer.cancel(); |
| 1901 |
if (finished) { |
| 1902 |
if (!filtered.length) { |
| 1903 |
var emptyMessage = !this.autoShown && this.emptyMessage; |
| 1904 |
if (typeof emptyMessage == "function") |
| 1905 |
emptyMessage = this.emptyMessage(prefix); |
| 1906 |
if (emptyMessage) { |
| 1907 |
var completionsForEmpty = [{ |
| 1908 |
caption: emptyMessage, |
| 1909 |
value: "" |
| 1910 |
} |
| 1911 |
]; |
| 1912 |
this.completions = new FilteredList(completionsForEmpty); |
| 1913 |
this.openPopup(this.editor, prefix, keepPopupPosition); |
| 1914 |
this.popup.renderer.setStyle("ace_loading", false); |
| 1915 |
return; |
| 1916 |
} |
| 1917 |
return this.detach(); |
| 1918 |
} |
| 1919 |
if (filtered.length == 1 && filtered[0].value == prefix |
| 1920 |
&& !filtered[0].snippet) |
| 1921 |
return this.detach(); |
| 1922 |
if (this.autoInsert && !this.autoShown && filtered.length == 1) |
| 1923 |
return this.insertMatch(filtered[0]); |
| 1924 |
} |
| 1925 |
this.completions = !finished && this.showLoadingState ? |
| 1926 |
new FilteredList(Autocomplete.completionsForLoading.concat(filtered), completions.filterText) : |
| 1927 |
completions; |
| 1928 |
this.openPopup(this.editor, prefix, keepPopupPosition); |
| 1929 |
this.popup.renderer.setStyle("ace_loading", !finished); |
| 1930 |
}.bind(this)); |
| 1931 |
if (this.showLoadingState && !this.autoShown && !(this.popup && this.popup.isOpen)) { |
| 1932 |
this.$firstOpenTimer.delay(this.stickySelectionDelay / 2); |
| 1933 |
} |
| 1934 |
}; |
| 1935 |
Autocomplete.prototype.cancelContextMenu = function () { |
| 1936 |
this.editor.$mouseHandler.cancelContextMenu(); |
| 1937 |
}; |
| 1938 |
Autocomplete.prototype.updateDocTooltip = function () { |
| 1939 |
var popup = this.popup; |
| 1940 |
var all = this.completions.filtered; |
| 1941 |
var selected = all && (all[popup.getHoveredRow()] || all[popup.getRow()]); |
| 1942 |
var doc = null; |
| 1943 |
if (!selected || !this.editor || !this.popup.isOpen) |
| 1944 |
return this.hideDocTooltip(); |
| 1945 |
var completersLength = this.editor.completers.length; |
| 1946 |
for (var i = 0; i < completersLength; i++) { |
| 1947 |
var completer = this.editor.completers[i]; |
| 1948 |
if (completer.getDocTooltip && selected.completerId === completer.id) { |
| 1949 |
doc = completer.getDocTooltip(selected); |
| 1950 |
break; |
| 1951 |
} |
| 1952 |
} |
| 1953 |
if (!doc && typeof selected != "string") |
| 1954 |
doc = selected; |
| 1955 |
if (typeof doc == "string") |
| 1956 |
doc = { docText: doc }; |
| 1957 |
if (!doc || !(doc.docHTML || doc.docText)) |
| 1958 |
return this.hideDocTooltip(); |
| 1959 |
this.showDocTooltip(doc); |
| 1960 |
}; |
| 1961 |
Autocomplete.prototype.showDocTooltip = function (item) { |
| 1962 |
if (!this.tooltipNode) { |
| 1963 |
this.tooltipNode = dom.createElement("div"); |
| 1964 |
this.tooltipNode.style.margin = "0"; |
| 1965 |
this.tooltipNode.style.pointerEvents = "auto"; |
| 1966 |
this.tooltipNode.style.overscrollBehavior = "contain"; |
| 1967 |
this.tooltipNode.tabIndex = -1; |
| 1968 |
this.tooltipNode.onblur = this.blurListener.bind(this); |
| 1969 |
this.tooltipNode.onclick = this.onTooltipClick.bind(this); |
| 1970 |
this.tooltipNode.id = "doc-tooltip"; |
| 1971 |
this.tooltipNode.setAttribute("role", "tooltip"); |
| 1972 |
this.tooltipNode.addEventListener("wheel", preventParentScroll); |
| 1973 |
} |
| 1974 |
var theme = this.editor.renderer.theme; |
| 1975 |
this.tooltipNode.className = "ace_tooltip ace_doc-tooltip " + |
| 1976 |
(theme.isDark ? "ace_dark " : "") + (theme.cssClass || ""); |
| 1977 |
var tooltipNode = this.tooltipNode; |
| 1978 |
if (item.docHTML) { |
| 1979 |
tooltipNode.innerHTML = item.docHTML; |
| 1980 |
} |
| 1981 |
else if (item.docText) { |
| 1982 |
tooltipNode.textContent = item.docText; |
| 1983 |
} |
| 1984 |
if (!tooltipNode.parentNode) |
| 1985 |
this.popup.container.appendChild(this.tooltipNode); |
| 1986 |
var popup = this.popup; |
| 1987 |
var rect = popup.container.getBoundingClientRect(); |
| 1988 |
tooltipNode.style.top = popup.container.style.top; |
| 1989 |
tooltipNode.style.bottom = popup.container.style.bottom; |
| 1990 |
tooltipNode.style.display = "block"; |
| 1991 |
if (window.innerWidth - rect.right < 320) { |
| 1992 |
if (rect.left < 320) { |
| 1993 |
if (popup.isTopdown) { |
| 1994 |
tooltipNode.style.top = rect.bottom + "px"; |
| 1995 |
tooltipNode.style.left = rect.left + "px"; |
| 1996 |
tooltipNode.style.right = ""; |
| 1997 |
tooltipNode.style.bottom = ""; |
| 1998 |
} |
| 1999 |
else { |
| 2000 |
tooltipNode.style.top = popup.container.offsetTop - tooltipNode.offsetHeight + "px"; |
| 2001 |
tooltipNode.style.left = rect.left + "px"; |
| 2002 |
tooltipNode.style.right = ""; |
| 2003 |
tooltipNode.style.bottom = ""; |
| 2004 |
} |
| 2005 |
} |
| 2006 |
else { |
| 2007 |
tooltipNode.style.right = window.innerWidth - rect.left + "px"; |
| 2008 |
tooltipNode.style.left = ""; |
| 2009 |
} |
| 2010 |
} |
| 2011 |
else { |
| 2012 |
tooltipNode.style.left = (rect.right + 1) + "px"; |
| 2013 |
tooltipNode.style.right = ""; |
| 2014 |
} |
| 2015 |
}; |
| 2016 |
Autocomplete.prototype.hideDocTooltip = function () { |
| 2017 |
this.tooltipTimer.cancel(); |
| 2018 |
if (!this.tooltipNode) |
| 2019 |
return; |
| 2020 |
var el = this.tooltipNode; |
| 2021 |
if (!this.editor.isFocused() && document.activeElement == el) |
| 2022 |
this.editor.focus(); |
| 2023 |
this.tooltipNode = null; |
| 2024 |
if (el.parentNode) |
| 2025 |
el.parentNode.removeChild(el); |
| 2026 |
}; |
| 2027 |
Autocomplete.prototype.onTooltipClick = function (e) { |
| 2028 |
var a = e.target; |
| 2029 |
while (a && a != this.tooltipNode) { |
| 2030 |
if (a.nodeName == "A" && a.href) { |
| 2031 |
a.rel = "noreferrer"; |
| 2032 |
a.target = "_blank"; |
| 2033 |
break; |
| 2034 |
} |
| 2035 |
a = a.parentNode; |
| 2036 |
} |
| 2037 |
}; |
| 2038 |
Autocomplete.prototype.destroy = function () { |
| 2039 |
this.detach(); |
| 2040 |
if (this.popup) { |
| 2041 |
this.popup.destroy(); |
| 2042 |
var el = this.popup.container; |
| 2043 |
if (el && el.parentNode) |
| 2044 |
el.parentNode.removeChild(el); |
| 2045 |
} |
| 2046 |
if (this.editor && this.editor.completer == this) { |
| 2047 |
this.editor.off("destroy", destroyCompleter); |
| 2048 |
this.editor.completer = null; |
| 2049 |
} |
| 2050 |
this.inlineRenderer = this.popup = this.editor = null; |
| 2051 |
}; |
| 2052 |
return Autocomplete; |
| 2053 |
}()); |
| 2054 |
Autocomplete.prototype.commands = { |
| 2055 |
"Up": function (editor) { editor.completer.goTo("up"); }, |
| 2056 |
"Down": function (editor) { editor.completer.goTo("down"); }, |
| 2057 |
"Ctrl-Up|Ctrl-Home": function (editor) { editor.completer.goTo("start"); }, |
| 2058 |
"Ctrl-Down|Ctrl-End": function (editor) { editor.completer.goTo("end"); }, |
| 2059 |
"Esc": function (editor) { editor.completer.detach(); }, |
| 2060 |
"Return": function (editor) { return editor.completer.insertMatch(); }, |
| 2061 |
"Shift-Return": function (editor) { editor.completer.insertMatch(null, { deleteSuffix: true }); }, |
| 2062 |
"Tab": function (editor) { |
| 2063 |
var result = editor.completer.insertMatch(); |
| 2064 |
if (!result && !editor.tabstopManager) |
| 2065 |
editor.completer.goTo("down"); |
| 2066 |
else |
| 2067 |
return result; |
| 2068 |
}, |
| 2069 |
"PageUp": function (editor) { editor.completer.popup.gotoPageUp(); }, |
| 2070 |
"PageDown": function (editor) { editor.completer.popup.gotoPageDown(); } |
| 2071 |
}; |
| 2072 |
Autocomplete.for = function (editor) { |
| 2073 |
if (editor.completer instanceof Autocomplete) { |
| 2074 |
return editor.completer; |
| 2075 |
} |
| 2076 |
if (editor.completer) { |
| 2077 |
editor.completer.destroy(); |
| 2078 |
editor.completer = null; |
| 2079 |
} |
| 2080 |
if (config.get("sharedPopups")) { |
| 2081 |
if (!Autocomplete["$sharedInstance"]) |
| 2082 |
Autocomplete["$sharedInstance"] = new Autocomplete(); |
| 2083 |
editor.completer = Autocomplete["$sharedInstance"]; |
| 2084 |
} |
| 2085 |
else { |
| 2086 |
editor.completer = new Autocomplete(); |
| 2087 |
editor.once("destroy", destroyCompleter); |
| 2088 |
} |
| 2089 |
return editor.completer; |
| 2090 |
}; |
| 2091 |
Autocomplete.startCommand = { |
| 2092 |
name: "startAutocomplete", |
| 2093 |
exec: function (editor, options) { |
| 2094 |
var completer = Autocomplete.for(editor); |
| 2095 |
completer.autoInsert = false; |
| 2096 |
completer.autoSelect = true; |
| 2097 |
completer.autoShown = false; |
| 2098 |
completer.showPopup(editor, options); |
| 2099 |
completer.cancelContextMenu(); |
| 2100 |
}, |
| 2101 |
bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space" |
| 2102 |
}; |
| 2103 |
var CompletionProvider = (function () { |
| 2104 |
function CompletionProvider(initialPosition) { |
| 2105 |
this.initialPosition = initialPosition; |
| 2106 |
this.active = true; |
| 2107 |
} |
| 2108 |
CompletionProvider.prototype.insertByIndex = function (editor, index, options) { |
| 2109 |
if (!this.completions || !this.completions.filtered) { |
| 2110 |
return false; |
| 2111 |
} |
| 2112 |
return this.insertMatch(editor, this.completions.filtered[index], options); |
| 2113 |
}; |
| 2114 |
CompletionProvider.prototype.insertMatch = function (editor, data, options) { |
| 2115 |
if (!data) |
| 2116 |
return false; |
| 2117 |
editor.startOperation({ command: { name: "insertMatch" } }); |
| 2118 |
if (data.completer && data.completer.insertMatch) { |
| 2119 |
data.completer.insertMatch(editor, data); |
| 2120 |
} |
| 2121 |
else { |
| 2122 |
if (!this.completions) |
| 2123 |
return false; |
| 2124 |
var replaceBefore = this.completions.filterText.length; |
| 2125 |
var replaceAfter = 0; |
| 2126 |
if (data.range && data.range.start.row === data.range.end.row) { |
| 2127 |
replaceBefore -= this.initialPosition.prefix.length; |
| 2128 |
replaceBefore += this.initialPosition.pos.column - data.range.start.column; |
| 2129 |
replaceAfter += data.range.end.column - this.initialPosition.pos.column; |
| 2130 |
} |
| 2131 |
if (replaceBefore || replaceAfter) { |
| 2132 |
var ranges; |
| 2133 |
if (editor.selection.getAllRanges) { |
| 2134 |
ranges = editor.selection.getAllRanges(); |
| 2135 |
} |
| 2136 |
else { |
| 2137 |
ranges = [editor.getSelectionRange()]; |
| 2138 |
} |
| 2139 |
for (var i = 0, range; range = ranges[i]; i++) { |
| 2140 |
range.start.column -= replaceBefore; |
| 2141 |
range.end.column += replaceAfter; |
| 2142 |
editor.session.remove(range); |
| 2143 |
} |
| 2144 |
} |
| 2145 |
if (data.snippet) { |
| 2146 |
snippetManager.insertSnippet(editor, data.snippet); |
| 2147 |
} |
| 2148 |
else { |
| 2149 |
this.$insertString(editor, data); |
| 2150 |
} |
| 2151 |
if (data.completer && data.completer.onInsert && typeof data.completer.onInsert == "function") { |
| 2152 |
data.completer.onInsert(editor, data); |
| 2153 |
} |
| 2154 |
if (data.command && data.command === "startAutocomplete") { |
| 2155 |
editor.execCommand(data.command); |
| 2156 |
} |
| 2157 |
} |
| 2158 |
editor.endOperation(); |
| 2159 |
return true; |
| 2160 |
}; |
| 2161 |
CompletionProvider.prototype.$insertString = function (editor, data) { |
| 2162 |
var text = data.value || data; |
| 2163 |
editor.execCommand("insertstring", text); |
| 2164 |
}; |
| 2165 |
CompletionProvider.prototype.gatherCompletions = function (editor, callback) { |
| 2166 |
var session = editor.getSession(); |
| 2167 |
var pos = editor.getCursorPosition(); |
| 2168 |
var prefix = util.getCompletionPrefix(editor); |
| 2169 |
var matches = []; |
| 2170 |
this.completers = editor.completers; |
| 2171 |
var total = editor.completers.length; |
| 2172 |
editor.completers.forEach(function (completer, i) { |
| 2173 |
completer.getCompletions(editor, session, pos, prefix, function (err, results) { |
| 2174 |
if (completer.hideInlinePreview) |
| 2175 |
results = results.map(function (result) { |
| 2176 |
return Object.assign(result, { hideInlinePreview: completer.hideInlinePreview }); |
| 2177 |
}); |
| 2178 |
if (!err && results) |
| 2179 |
matches = matches.concat(results); |
| 2180 |
callback(null, { |
| 2181 |
prefix: util.getCompletionPrefix(editor), |
| 2182 |
matches: matches, |
| 2183 |
finished: (--total === 0) |
| 2184 |
}); |
| 2185 |
}); |
| 2186 |
}); |
| 2187 |
return true; |
| 2188 |
}; |
| 2189 |
CompletionProvider.prototype.provideCompletions = function (editor, options, callback) { |
| 2190 |
var processResults = function (results) { |
| 2191 |
var prefix = results.prefix; |
| 2192 |
var matches = results.matches; |
| 2193 |
this.completions = new FilteredList(matches); |
| 2194 |
if (options.exactMatch) |
| 2195 |
this.completions.exactMatch = true; |
| 2196 |
if (options.ignoreCaption) |
| 2197 |
this.completions.ignoreCaption = true; |
| 2198 |
this.completions.setFilter(prefix); |
| 2199 |
if (results.finished || this.completions.filtered.length) |
| 2200 |
callback(null, this.completions, results.finished); |
| 2201 |
}.bind(this); |
| 2202 |
var isImmediate = true; |
| 2203 |
var immediateResults = null; |
| 2204 |
this.gatherCompletions(editor, function (err, results) { |
| 2205 |
if (!this.active) { |
| 2206 |
return; |
| 2207 |
} |
| 2208 |
if (err) { |
| 2209 |
callback(err, [], true); |
| 2210 |
this.detach(); |
| 2211 |
} |
| 2212 |
var prefix = results.prefix; |
| 2213 |
if (prefix.indexOf(results.prefix) !== 0) |
| 2214 |
return; |
| 2215 |
if (isImmediate) { |
| 2216 |
immediateResults = results; |
| 2217 |
return; |
| 2218 |
} |
| 2219 |
processResults(results); |
| 2220 |
}.bind(this)); |
| 2221 |
isImmediate = false; |
| 2222 |
if (immediateResults) { |
| 2223 |
var results = immediateResults; |
| 2224 |
immediateResults = null; |
| 2225 |
processResults(results); |
| 2226 |
} |
| 2227 |
}; |
| 2228 |
CompletionProvider.prototype.detach = function () { |
| 2229 |
this.active = false; |
| 2230 |
this.completers && this.completers.forEach(function (completer) { |
| 2231 |
if (typeof completer.cancel === "function") { |
| 2232 |
completer.cancel(); |
| 2233 |
} |
| 2234 |
}); |
| 2235 |
}; |
| 2236 |
return CompletionProvider; |
| 2237 |
}()); |
| 2238 |
var FilteredList = (function () { |
| 2239 |
function FilteredList(array, filterText) { |
| 2240 |
this.all = array; |
| 2241 |
this.filtered = array; |
| 2242 |
this.filterText = filterText || ""; |
| 2243 |
this.exactMatch = false; |
| 2244 |
this.ignoreCaption = false; |
| 2245 |
} |
| 2246 |
FilteredList.prototype.setFilter = function (str) { |
| 2247 |
if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0) |
| 2248 |
var matches = this.filtered; |
| 2249 |
else |
| 2250 |
var matches = this.all; |
| 2251 |
this.filterText = str; |
| 2252 |
matches = this.filterCompletions(matches, this.filterText); |
| 2253 |
matches = matches.sort(function (a, b) { |
| 2254 |
return b.exactMatch - a.exactMatch || b.$score - a.$score |
| 2255 |
|| (a.caption || a.value).localeCompare(b.caption || b.value); |
| 2256 |
}); |
| 2257 |
var prev = null; |
| 2258 |
matches = matches.filter(function (item) { |
| 2259 |
var caption = item.snippet || item.caption || item.value; |
| 2260 |
if (caption === prev) |
| 2261 |
return false; |
| 2262 |
prev = caption; |
| 2263 |
return true; |
| 2264 |
}); |
| 2265 |
this.filtered = matches; |
| 2266 |
}; |
| 2267 |
FilteredList.prototype.filterCompletions = function (items, needle) { |
| 2268 |
var results = []; |
| 2269 |
var upper = needle.toUpperCase(); |
| 2270 |
var lower = needle.toLowerCase(); |
| 2271 |
loop: for (var i = 0, item; item = items[i]; i++) { |
| 2272 |
var caption = (!this.ignoreCaption && item.caption) || item.value || item.snippet; |
| 2273 |
if (!caption) |
| 2274 |
continue; |
| 2275 |
var lastIndex = -1; |
| 2276 |
var matchMask = 0; |
| 2277 |
var penalty = 0; |
| 2278 |
var index, distance; |
| 2279 |
if (this.exactMatch) { |
| 2280 |
if (needle !== caption.substr(0, needle.length)) |
| 2281 |
continue loop; |
| 2282 |
} |
| 2283 |
else { |
| 2284 |
var fullMatchIndex = caption.toLowerCase().indexOf(lower); |
| 2285 |
if (fullMatchIndex > -1) { |
| 2286 |
penalty = fullMatchIndex; |
| 2287 |
} |
| 2288 |
else { |
| 2289 |
for (var j = 0; j < needle.length; j++) { |
| 2290 |
var i1 = caption.indexOf(lower[j], lastIndex + 1); |
| 2291 |
var i2 = caption.indexOf(upper[j], lastIndex + 1); |
| 2292 |
index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2; |
| 2293 |
if (index < 0) |
| 2294 |
continue loop; |
| 2295 |
distance = index - lastIndex - 1; |
| 2296 |
if (distance > 0) { |
| 2297 |
if (lastIndex === -1) |
| 2298 |
penalty += 10; |
| 2299 |
penalty += distance; |
| 2300 |
matchMask = matchMask | (1 << j); |
| 2301 |
} |
| 2302 |
lastIndex = index; |
| 2303 |
} |
| 2304 |
} |
| 2305 |
} |
| 2306 |
item.matchMask = matchMask; |
| 2307 |
item.exactMatch = penalty ? 0 : 1; |
| 2308 |
item.$score = (item.score || 0) - penalty; |
| 2309 |
results.push(item); |
| 2310 |
} |
| 2311 |
return results; |
| 2312 |
}; |
| 2313 |
return FilteredList; |
| 2314 |
}()); |
| 2315 |
exports.Autocomplete = Autocomplete; |
| 2316 |
exports.CompletionProvider = CompletionProvider; |
| 2317 |
exports.FilteredList = FilteredList; |
| 2318 |
|
| 2319 |
}); |
| 2320 |
|
| 2321 |
ace.define("ace/ext/menu_tools/settings_menu.css",["require","exports","module"], function(require, exports, module){module.exports = "#ace_settingsmenu, #kbshortcutmenu {\n background-color: #F7F7F7;\n color: black;\n box-shadow: -5px 4px 5px rgba(126, 126, 126, 0.55);\n padding: 1em 0.5em 2em 1em;\n overflow: auto;\n position: absolute;\n margin: 0;\n bottom: 0;\n right: 0;\n top: 0;\n z-index: 9991;\n cursor: default;\n}\n\n.ace_dark #ace_settingsmenu, .ace_dark #kbshortcutmenu {\n box-shadow: -20px 10px 25px rgba(126, 126, 126, 0.25);\n background-color: rgba(255, 255, 255, 0.6);\n color: black;\n}\n\n.ace_optionsMenuEntry:hover {\n background-color: rgba(100, 100, 100, 0.1);\n transition: all 0.3s\n}\n\n.ace_closeButton {\n background: rgba(245, 146, 146, 0.5);\n border: 1px solid #F48A8A;\n border-radius: 50%;\n padding: 7px;\n position: absolute;\n right: -8px;\n top: -8px;\n z-index: 100000;\n}\n.ace_closeButton{\n background: rgba(245, 146, 146, 0.9);\n}\n.ace_optionsMenuKey {\n color: darkslateblue;\n font-weight: bold;\n}\n.ace_optionsMenuCommand {\n color: darkcyan;\n font-weight: normal;\n}\n.ace_optionsMenuEntry input, .ace_optionsMenuEntry button {\n vertical-align: middle;\n}\n\n.ace_optionsMenuEntry button[ace_selected_button=true] {\n background: #e7e7e7;\n box-shadow: 1px 0px 2px 0px #adadad inset;\n border-color: #adadad;\n}\n.ace_optionsMenuEntry button {\n background: white;\n border: 1px solid lightgray;\n margin: 0px;\n}\n.ace_optionsMenuEntry button:hover{\n background: #f0f0f0;\n}"; |
| 2322 |
|
| 2323 |
}); |
| 2324 |
|
| 2325 |
ace.define("ace/ext/menu_tools/overlay_page",["require","exports","module","ace/lib/dom","ace/ext/menu_tools/settings_menu.css"], function(require, exports, module){ |
| 2326 |
'use strict'; |
| 2327 |
var dom = require("../../lib/dom"); |
| 2328 |
var cssText = require("./settings_menu.css"); |
| 2329 |
dom.importCssString(cssText, "settings_menu.css", false); |
| 2330 |
module.exports.overlayPage = function overlayPage(editor, contentElement, callback) { |
| 2331 |
var closer = document.createElement('div'); |
| 2332 |
var ignoreFocusOut = false; |
| 2333 |
function documentEscListener(e) { |
| 2334 |
if (e.keyCode === 27) { |
| 2335 |
close(); |
| 2336 |
} |
| 2337 |
} |
| 2338 |
function close() { |
| 2339 |
if (!closer) |
| 2340 |
return; |
| 2341 |
document.removeEventListener('keydown', documentEscListener); |
| 2342 |
closer.parentNode.removeChild(closer); |
| 2343 |
if (editor) { |
| 2344 |
editor.focus(); |
| 2345 |
} |
| 2346 |
closer = null; |
| 2347 |
callback && callback(); |
| 2348 |
} |
| 2349 |
function setIgnoreFocusOut(ignore) { |
| 2350 |
ignoreFocusOut = ignore; |
| 2351 |
if (ignore) { |
| 2352 |
closer.style.pointerEvents = "none"; |
| 2353 |
contentElement.style.pointerEvents = "auto"; |
| 2354 |
} |
| 2355 |
} |
| 2356 |
closer.style.cssText = 'margin: 0; padding: 0; ' + |
| 2357 |
'position: fixed; top:0; bottom:0; left:0; right:0;' + |
| 2358 |
'z-index: 9990; ' + |
| 2359 |
(editor ? 'background-color: rgba(0, 0, 0, 0.3);' : ''); |
| 2360 |
closer.addEventListener('click', function (e) { |
| 2361 |
if (!ignoreFocusOut) { |
| 2362 |
close(); |
| 2363 |
} |
| 2364 |
}); |
| 2365 |
document.addEventListener('keydown', documentEscListener); |
| 2366 |
contentElement.addEventListener('click', function (e) { |
| 2367 |
e.stopPropagation(); |
| 2368 |
}); |
| 2369 |
closer.appendChild(contentElement); |
| 2370 |
document.body.appendChild(closer); |
| 2371 |
if (editor) { |
| 2372 |
editor.blur(); |
| 2373 |
} |
| 2374 |
return { |
| 2375 |
close: close, |
| 2376 |
setIgnoreFocusOut: setIgnoreFocusOut |
| 2377 |
}; |
| 2378 |
}; |
| 2379 |
|
| 2380 |
}); |
| 2381 |
|
| 2382 |
ace.define("ace/ext/modelist",["require","exports","module"], function(require, exports, module){"use strict"; |
| 2383 |
var modes = []; |
| 2384 |
function getModeForPath(path) { |
| 2385 |
var mode = modesByName.text; |
| 2386 |
var fileName = path.split(/[\/\\]/).pop(); |
| 2387 |
for (var i = 0; i < modes.length; i++) { |
| 2388 |
if (modes[i].supportsFile(fileName)) { |
| 2389 |
mode = modes[i]; |
| 2390 |
break; |
| 2391 |
} |
| 2392 |
} |
| 2393 |
return mode; |
| 2394 |
} |
| 2395 |
var Mode = (function () { |
| 2396 |
function Mode(name, caption, extensions) { |
| 2397 |
this.name = name; |
| 2398 |
this.caption = caption; |
| 2399 |
this.mode = "ace/mode/" + name; |
| 2400 |
this.extensions = extensions; |
| 2401 |
var re; |
| 2402 |
if (/\^/.test(extensions)) { |
| 2403 |
re = extensions.replace(/\|(\^)?/g, function (a, b) { |
| 2404 |
return "$|" + (b ? "^" : "^.*\\."); |
| 2405 |
}) + "$"; |
| 2406 |
} |
| 2407 |
else { |
| 2408 |
re = "^.*\\.(" + extensions + ")$"; |
| 2409 |
} |
| 2410 |
this.extRe = new RegExp(re, "gi"); |
| 2411 |
} |
| 2412 |
Mode.prototype.supportsFile = function (filename) { |
| 2413 |
return filename.match(this.extRe); |
| 2414 |
}; |
| 2415 |
return Mode; |
| 2416 |
}()); |
| 2417 |
var supportedModes = { |
| 2418 |
ABAP: ["abap"], |
| 2419 |
ABC: ["abc"], |
| 2420 |
ActionScript: ["as"], |
| 2421 |
ADA: ["ada|adb"], |
| 2422 |
Alda: ["alda"], |
| 2423 |
Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"], |
| 2424 |
Apex: ["apex|cls|trigger|tgr"], |
| 2425 |
AQL: ["aql"], |
| 2426 |
AsciiDoc: ["asciidoc|adoc"], |
| 2427 |
ASL: ["dsl|asl|asl.json"], |
| 2428 |
Assembly_ARM32: ["s"], |
| 2429 |
Assembly_x86: ["asm|a"], |
| 2430 |
Astro: ["astro"], |
| 2431 |
AutoHotKey: ["ahk"], |
| 2432 |
BatchFile: ["bat|cmd"], |
| 2433 |
BibTeX: ["bib"], |
| 2434 |
C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp|ino"], |
| 2435 |
C9Search: ["c9search_results"], |
| 2436 |
Cirru: ["cirru|cr"], |
| 2437 |
Clojure: ["clj|cljs"], |
| 2438 |
Cobol: ["CBL|COB"], |
| 2439 |
coffee: ["coffee|cf|cson|^Cakefile"], |
| 2440 |
ColdFusion: ["cfm|cfc"], |
| 2441 |
Crystal: ["cr"], |
| 2442 |
CSharp: ["cs"], |
| 2443 |
Csound_Document: ["csd"], |
| 2444 |
Csound_Orchestra: ["orc"], |
| 2445 |
Csound_Score: ["sco"], |
| 2446 |
CSS: ["css"], |
| 2447 |
Curly: ["curly"], |
| 2448 |
Cuttlefish: ["conf"], |
| 2449 |
D: ["d|di"], |
| 2450 |
Dart: ["dart"], |
| 2451 |
Diff: ["diff|patch"], |
| 2452 |
Django: ["djt|html.djt|dj.html|djhtml"], |
| 2453 |
Dockerfile: ["^Dockerfile"], |
| 2454 |
Dot: ["dot"], |
| 2455 |
Drools: ["drl"], |
| 2456 |
Edifact: ["edi"], |
| 2457 |
Eiffel: ["e|ge"], |
| 2458 |
EJS: ["ejs"], |
| 2459 |
Elixir: ["ex|exs"], |
| 2460 |
Elm: ["elm"], |
| 2461 |
Erlang: ["erl|hrl"], |
| 2462 |
Flix: ["flix"], |
| 2463 |
Forth: ["frt|fs|ldr|fth|4th"], |
| 2464 |
Fortran: ["f|f90"], |
| 2465 |
FSharp: ["fsi|fs|ml|mli|fsx|fsscript"], |
| 2466 |
FSL: ["fsl"], |
| 2467 |
FTL: ["ftl"], |
| 2468 |
Gcode: ["gcode"], |
| 2469 |
Gherkin: ["feature"], |
| 2470 |
Gitignore: ["^.gitignore"], |
| 2471 |
Glsl: ["glsl|frag|vert"], |
| 2472 |
Gobstones: ["gbs"], |
| 2473 |
golang: ["go"], |
| 2474 |
GraphQLSchema: ["gql"], |
| 2475 |
Groovy: ["groovy"], |
| 2476 |
HAML: ["haml"], |
| 2477 |
Handlebars: ["hbs|handlebars|tpl|mustache"], |
| 2478 |
Haskell: ["hs"], |
| 2479 |
Haskell_Cabal: ["cabal"], |
| 2480 |
haXe: ["hx"], |
| 2481 |
Hjson: ["hjson"], |
| 2482 |
HTML: ["html|htm|xhtml|we|wpy"], |
| 2483 |
HTML_Elixir: ["eex|html.eex"], |
| 2484 |
HTML_Ruby: ["erb|rhtml|html.erb"], |
| 2485 |
INI: ["ini|conf|cfg|prefs"], |
| 2486 |
Io: ["io"], |
| 2487 |
Ion: ["ion"], |
| 2488 |
Jack: ["jack"], |
| 2489 |
Jade: ["jade|pug"], |
| 2490 |
Java: ["java"], |
| 2491 |
JavaScript: ["js|jsm|cjs|mjs"], |
| 2492 |
JEXL: ["jexl"], |
| 2493 |
JSON: ["json"], |
| 2494 |
JSON5: ["json5"], |
| 2495 |
JSONiq: ["jq"], |
| 2496 |
JSP: ["jsp"], |
| 2497 |
JSSM: ["jssm|jssm_state"], |
| 2498 |
JSX: ["jsx"], |
| 2499 |
Julia: ["jl"], |
| 2500 |
Kotlin: ["kt|kts"], |
| 2501 |
LaTeX: ["tex|latex|ltx|bib"], |
| 2502 |
Latte: ["latte"], |
| 2503 |
LESS: ["less"], |
| 2504 |
Liquid: ["liquid"], |
| 2505 |
Lisp: ["lisp"], |
| 2506 |
LiveScript: ["ls"], |
| 2507 |
Log: ["log"], |
| 2508 |
LogiQL: ["logic|lql"], |
| 2509 |
Logtalk: ["lgt"], |
| 2510 |
LSL: ["lsl"], |
| 2511 |
Lua: ["lua"], |
| 2512 |
LuaPage: ["lp"], |
| 2513 |
Lucene: ["lucene"], |
| 2514 |
Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"], |
| 2515 |
Markdown: ["md|markdown"], |
| 2516 |
Mask: ["mask"], |
| 2517 |
MATLAB: ["matlab"], |
| 2518 |
Maze: ["mz"], |
| 2519 |
MediaWiki: ["wiki|mediawiki"], |
| 2520 |
MEL: ["mel"], |
| 2521 |
MIPS: ["s|asm"], |
| 2522 |
MIXAL: ["mixal"], |
| 2523 |
MUSHCode: ["mc|mush"], |
| 2524 |
MySQL: ["mysql"], |
| 2525 |
Nasal: ["nas"], |
| 2526 |
Nginx: ["nginx|conf"], |
| 2527 |
Nim: ["nim"], |
| 2528 |
Nix: ["nix"], |
| 2529 |
NSIS: ["nsi|nsh"], |
| 2530 |
Nunjucks: ["nunjucks|nunjs|nj|njk"], |
| 2531 |
ObjectiveC: ["m|mm"], |
| 2532 |
OCaml: ["ml|mli"], |
| 2533 |
Odin: ["odin"], |
| 2534 |
PartiQL: ["partiql|pql"], |
| 2535 |
Pascal: ["pas|p"], |
| 2536 |
Perl: ["pl|pm"], |
| 2537 |
pgSQL: ["pgsql"], |
| 2538 |
PHP: ["php|inc|phtml|shtml|php3|php4|php5|phps|phpt|aw|ctp|module"], |
| 2539 |
PHP_Laravel_blade: ["blade.php"], |
| 2540 |
Pig: ["pig"], |
| 2541 |
PLSQL: ["plsql"], |
| 2542 |
Powershell: ["ps1"], |
| 2543 |
Praat: ["praat|praatscript|psc|proc"], |
| 2544 |
Prisma: ["prisma"], |
| 2545 |
Prolog: ["plg|prolog"], |
| 2546 |
Properties: ["properties"], |
| 2547 |
Protobuf: ["proto"], |
| 2548 |
PRQL: ["prql"], |
| 2549 |
Puppet: ["epp|pp"], |
| 2550 |
Python: ["py"], |
| 2551 |
QML: ["qml"], |
| 2552 |
R: ["r"], |
| 2553 |
Raku: ["raku|rakumod|rakutest|p6|pl6|pm6"], |
| 2554 |
Razor: ["cshtml|asp"], |
| 2555 |
RDoc: ["Rd"], |
| 2556 |
Red: ["red|reds"], |
| 2557 |
RHTML: ["Rhtml"], |
| 2558 |
Robot: ["robot|resource"], |
| 2559 |
RST: ["rst"], |
| 2560 |
Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"], |
| 2561 |
Rust: ["rs"], |
| 2562 |
SaC: ["sac"], |
| 2563 |
SASS: ["sass"], |
| 2564 |
SCAD: ["scad"], |
| 2565 |
Scala: ["scala|sbt"], |
| 2566 |
Scheme: ["scm|sm|rkt|oak|scheme"], |
| 2567 |
Scrypt: ["scrypt"], |
| 2568 |
SCSS: ["scss"], |
| 2569 |
SH: ["sh|bash|^.bashrc"], |
| 2570 |
SJS: ["sjs"], |
| 2571 |
Slim: ["slim|skim"], |
| 2572 |
Smarty: ["smarty|tpl"], |
| 2573 |
Smithy: ["smithy"], |
| 2574 |
snippets: ["snippets"], |
| 2575 |
Soy_Template: ["soy"], |
| 2576 |
Space: ["space"], |
| 2577 |
SPARQL: ["rq"], |
| 2578 |
SQL: ["sql"], |
| 2579 |
SQLServer: ["sqlserver"], |
| 2580 |
Stylus: ["styl|stylus"], |
| 2581 |
SVG: ["svg"], |
| 2582 |
Swift: ["swift"], |
| 2583 |
Tcl: ["tcl"], |
| 2584 |
Terraform: ["tf", "tfvars", "terragrunt"], |
| 2585 |
Tex: ["tex"], |
| 2586 |
Text: ["txt"], |
| 2587 |
Textile: ["textile"], |
| 2588 |
Toml: ["toml"], |
| 2589 |
TSX: ["tsx"], |
| 2590 |
Turtle: ["ttl"], |
| 2591 |
Twig: ["twig|swig"], |
| 2592 |
Typescript: ["ts|mts|cts|typescript|str"], |
| 2593 |
Vala: ["vala"], |
| 2594 |
VBScript: ["vbs|vb"], |
| 2595 |
Velocity: ["vm"], |
| 2596 |
Verilog: ["v|vh|sv|svh"], |
| 2597 |
VHDL: ["vhd|vhdl"], |
| 2598 |
Visualforce: ["vfp|component|page"], |
| 2599 |
Vue: ["vue"], |
| 2600 |
Wollok: ["wlk|wpgm|wtest"], |
| 2601 |
XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl|xaml"], |
| 2602 |
XQuery: ["xq"], |
| 2603 |
YAML: ["yaml|yml"], |
| 2604 |
Zeek: ["zeek|bro"], |
| 2605 |
Zig: ["zig"] |
| 2606 |
}; |
| 2607 |
var nameOverrides = { |
| 2608 |
ObjectiveC: "Objective-C", |
| 2609 |
CSharp: "C#", |
| 2610 |
golang: "Go", |
| 2611 |
C_Cpp: "C and C++", |
| 2612 |
Csound_Document: "Csound Document", |
| 2613 |
Csound_Orchestra: "Csound", |
| 2614 |
Csound_Score: "Csound Score", |
| 2615 |
coffee: "CoffeeScript", |
| 2616 |
HTML_Ruby: "HTML (Ruby)", |
| 2617 |
HTML_Elixir: "HTML (Elixir)", |
| 2618 |
FTL: "FreeMarker", |
| 2619 |
PHP_Laravel_blade: "PHP (Blade Template)", |
| 2620 |
Perl6: "Perl 6", |
| 2621 |
AutoHotKey: "AutoHotkey / AutoIt" |
| 2622 |
}; |
| 2623 |
var modesByName = {}; |
| 2624 |
for (var name in supportedModes) { |
| 2625 |
var data = supportedModes[name]; |
| 2626 |
var displayName = (nameOverrides[name] || name).replace(/_/g, " "); |
| 2627 |
var filename = name.toLowerCase(); |
| 2628 |
var mode = new Mode(filename, displayName, data[0]); |
| 2629 |
modesByName[filename] = mode; |
| 2630 |
modes.push(mode); |
| 2631 |
} |
| 2632 |
module.exports = { |
| 2633 |
getModeForPath: getModeForPath, |
| 2634 |
modes: modes, |
| 2635 |
modesByName: modesByName |
| 2636 |
}; |
| 2637 |
|
| 2638 |
}); |
| 2639 |
|
| 2640 |
ace.define("ace/ext/prompt",["require","exports","module","ace/config","ace/range","ace/lib/dom","ace/autocomplete","ace/autocomplete/popup","ace/autocomplete/popup","ace/undomanager","ace/tokenizer","ace/ext/menu_tools/overlay_page","ace/ext/modelist"], function(require, exports, module){ |
| 2641 |
|
| 2642 |
|
| 2643 |
"use strict"; |
| 2644 |
var nls = require("../config").nls; |
| 2645 |
var Range = require("../range").Range; |
| 2646 |
var dom = require("../lib/dom"); |
| 2647 |
var FilteredList = require("../autocomplete").FilteredList; |
| 2648 |
var AcePopup = require('../autocomplete/popup').AcePopup; |
| 2649 |
var $singleLineEditor = require('../autocomplete/popup').$singleLineEditor; |
| 2650 |
var UndoManager = require("../undomanager").UndoManager; |
| 2651 |
var Tokenizer = require("../tokenizer").Tokenizer; |
| 2652 |
var overlayPage = require("./menu_tools/overlay_page").overlayPage; |
| 2653 |
var modelist = require("./modelist"); |
| 2654 |
var openPrompt; |
| 2655 |
function prompt(editor, message, options, callback) { |
| 2656 |
if (typeof message == "object") { |
| 2657 |
return prompt(editor, "", message, options); |
| 2658 |
} |
| 2659 |
if (openPrompt) { |
| 2660 |
var lastPrompt = openPrompt; |
| 2661 |
editor = lastPrompt.editor; |
| 2662 |
lastPrompt.close(); |
| 2663 |
if (lastPrompt.name && lastPrompt.name == options.name) |
| 2664 |
return; |
| 2665 |
} |
| 2666 |
if (options.$type) |
| 2667 |
return prompt[options.$type](editor, callback); |
| 2668 |
var cmdLine = $singleLineEditor(); |
| 2669 |
cmdLine.session.setUndoManager(new UndoManager()); |
| 2670 |
var el = dom.buildDom(["div", { class: "ace_prompt_container" + (options.hasDescription ? " input-box-with-description" : "") }]); |
| 2671 |
var overlay = overlayPage(editor, el, done); |
| 2672 |
el.appendChild(cmdLine.container); |
| 2673 |
if (editor) { |
| 2674 |
editor.cmdLine = cmdLine; |
| 2675 |
cmdLine.setOption("fontSize", editor.getOption("fontSize")); |
| 2676 |
} |
| 2677 |
if (message) { |
| 2678 |
cmdLine.setValue(message, 1); |
| 2679 |
} |
| 2680 |
if (options.selection) { |
| 2681 |
cmdLine.selection.setRange({ |
| 2682 |
start: cmdLine.session.doc.indexToPosition(options.selection[0]), |
| 2683 |
end: cmdLine.session.doc.indexToPosition(options.selection[1]) |
| 2684 |
}); |
| 2685 |
} |
| 2686 |
if (options.getCompletions) { |
| 2687 |
var popup = new AcePopup(); |
| 2688 |
popup.renderer.setStyle("ace_autocomplete_inline"); |
| 2689 |
popup.container.style.display = "block"; |
| 2690 |
popup.container.style.maxWidth = "600px"; |
| 2691 |
popup.container.style.width = "100%"; |
| 2692 |
popup.container.style.marginTop = "3px"; |
| 2693 |
popup.renderer.setScrollMargin(2, 2, 0, 0); |
| 2694 |
popup.autoSelect = false; |
| 2695 |
popup.renderer.$maxLines = 15; |
| 2696 |
popup.setRow(-1); |
| 2697 |
popup.on("click", function (e) { |
| 2698 |
var data = popup.getData(popup.getRow()); |
| 2699 |
if (!data["error"]) { |
| 2700 |
cmdLine.setValue(data.value || data["name"] || data); |
| 2701 |
accept(); |
| 2702 |
e.stop(); |
| 2703 |
} |
| 2704 |
}); |
| 2705 |
el.appendChild(popup.container); |
| 2706 |
updateCompletions(); |
| 2707 |
} |
| 2708 |
if (options.$rules) { |
| 2709 |
var tokenizer = new Tokenizer(options.$rules); |
| 2710 |
cmdLine.session.bgTokenizer.setTokenizer(tokenizer); |
| 2711 |
} |
| 2712 |
if (options.placeholder) { |
| 2713 |
cmdLine.setOption("placeholder", options.placeholder); |
| 2714 |
} |
| 2715 |
if (options.hasDescription) { |
| 2716 |
var promptTextContainer = dom.buildDom(["div", { class: "ace_prompt_text_container" }]); |
| 2717 |
dom.buildDom(options.prompt || "Press 'Enter' to confirm or 'Escape' to cancel", promptTextContainer); |
| 2718 |
el.appendChild(promptTextContainer); |
| 2719 |
} |
| 2720 |
overlay.setIgnoreFocusOut(options.ignoreFocusOut); |
| 2721 |
function accept() { |
| 2722 |
var val; |
| 2723 |
if (popup && popup.getCursorPosition().row > 0) { |
| 2724 |
val = valueFromRecentList(); |
| 2725 |
} |
| 2726 |
else { |
| 2727 |
val = cmdLine.getValue(); |
| 2728 |
} |
| 2729 |
var curData = popup ? popup.getData(popup.getRow()) : val; |
| 2730 |
if (curData && !curData["error"]) { |
| 2731 |
done(); |
| 2732 |
options.onAccept && options.onAccept({ |
| 2733 |
value: val, |
| 2734 |
item: curData |
| 2735 |
}, cmdLine); |
| 2736 |
} |
| 2737 |
} |
| 2738 |
var keys = { |
| 2739 |
"Enter": accept, |
| 2740 |
"Esc|Shift-Esc": function () { |
| 2741 |
options.onCancel && options.onCancel(cmdLine.getValue(), cmdLine); |
| 2742 |
done(); |
| 2743 |
} |
| 2744 |
}; |
| 2745 |
if (popup) { |
| 2746 |
Object.assign(keys, { |
| 2747 |
"Up": function (editor) { popup.goTo("up"); valueFromRecentList(); }, |
| 2748 |
"Down": function (editor) { popup.goTo("down"); valueFromRecentList(); }, |
| 2749 |
"Ctrl-Up|Ctrl-Home": function (editor) { popup.goTo("start"); valueFromRecentList(); }, |
| 2750 |
"Ctrl-Down|Ctrl-End": function (editor) { popup.goTo("end"); valueFromRecentList(); }, |
| 2751 |
"Tab": function (editor) { |
| 2752 |
popup.goTo("down"); |
| 2753 |
valueFromRecentList(); |
| 2754 |
}, |
| 2755 |
"PageUp": function (editor) { popup.gotoPageUp(); valueFromRecentList(); }, |
| 2756 |
"PageDown": function (editor) { popup.gotoPageDown(); valueFromRecentList(); } |
| 2757 |
}); |
| 2758 |
} |
| 2759 |
cmdLine.commands.bindKeys(keys); |
| 2760 |
function done() { |
| 2761 |
overlay.close(); |
| 2762 |
callback && callback(); |
| 2763 |
openPrompt = null; |
| 2764 |
} |
| 2765 |
cmdLine.on("input", function () { |
| 2766 |
options.onInput && options.onInput(); |
| 2767 |
updateCompletions(); |
| 2768 |
}); |
| 2769 |
function updateCompletions() { |
| 2770 |
if (options.getCompletions) { |
| 2771 |
var prefix; |
| 2772 |
if (options.getPrefix) { |
| 2773 |
prefix = options.getPrefix(cmdLine); |
| 2774 |
} |
| 2775 |
var completions = options.getCompletions(cmdLine); |
| 2776 |
popup.setData(completions, prefix); |
| 2777 |
popup.resize(true); |
| 2778 |
} |
| 2779 |
} |
| 2780 |
function valueFromRecentList() { |
| 2781 |
var current = popup.getData(popup.getRow()); |
| 2782 |
if (current && !current["error"]) |
| 2783 |
return current.value || current.caption || current; |
| 2784 |
} |
| 2785 |
cmdLine.resize(true); |
| 2786 |
if (popup) { |
| 2787 |
popup.resize(true); |
| 2788 |
} |
| 2789 |
cmdLine.focus(); |
| 2790 |
openPrompt = { |
| 2791 |
close: done, |
| 2792 |
name: options.name, |
| 2793 |
editor: editor |
| 2794 |
}; |
| 2795 |
} |
| 2796 |
prompt.gotoLine = function (editor, callback) { |
| 2797 |
function stringifySelection(selection) { |
| 2798 |
if (!Array.isArray(selection)) |
| 2799 |
selection = [selection]; |
| 2800 |
return selection.map(function (r) { |
| 2801 |
var cursor = r.isBackwards ? r.start : r.end; |
| 2802 |
var anchor = r.isBackwards ? r.end : r.start; |
| 2803 |
var row = anchor.row; |
| 2804 |
var s = (row + 1) + ":" + anchor.column; |
| 2805 |
if (anchor.row == cursor.row) { |
| 2806 |
if (anchor.column != cursor.column) |
| 2807 |
s += ">" + ":" + cursor.column; |
| 2808 |
} |
| 2809 |
else { |
| 2810 |
s += ">" + (cursor.row + 1) + ":" + cursor.column; |
| 2811 |
} |
| 2812 |
return s; |
| 2813 |
}).reverse().join(", "); |
| 2814 |
} |
| 2815 |
prompt(editor, ":" + stringifySelection(editor.selection.toJSON()), { |
| 2816 |
name: "gotoLine", |
| 2817 |
selection: [1, Number.MAX_VALUE], |
| 2818 |
onAccept: function (data) { |
| 2819 |
var value = data.value; |
| 2820 |
var _history = prompt.gotoLine["_history"]; |
| 2821 |
if (!_history) |
| 2822 |
prompt.gotoLine["_history"] = _history = []; |
| 2823 |
if (_history.indexOf(value) != -1) |
| 2824 |
_history.splice(_history.indexOf(value), 1); |
| 2825 |
_history.unshift(value); |
| 2826 |
if (_history.length > 20) |
| 2827 |
_history.length = 20; |
| 2828 |
var pos = editor.getCursorPosition(); |
| 2829 |
var ranges = []; |
| 2830 |
value.replace(/^:/, "").split(/,/).map(function (str) { |
| 2831 |
var parts = str.split(/([<>:+-]|c?\d+)|[^c\d<>:+-]+/).filter(Boolean); |
| 2832 |
var i = 0; |
| 2833 |
function readPosition() { |
| 2834 |
var c = parts[i++]; |
| 2835 |
if (!c) |
| 2836 |
return; |
| 2837 |
if (c[0] == "c") { |
| 2838 |
var index = parseInt(c.slice(1)) || 0; |
| 2839 |
return editor.session.doc.indexToPosition(index); |
| 2840 |
} |
| 2841 |
var row = pos.row; |
| 2842 |
var column = 0; |
| 2843 |
if (/\d/.test(c)) { |
| 2844 |
row = parseInt(c) - 1; |
| 2845 |
c = parts[i++]; |
| 2846 |
} |
| 2847 |
if (c == ":") { |
| 2848 |
c = parts[i++]; |
| 2849 |
if (/\d/.test(c)) { |
| 2850 |
column = parseInt(c) || 0; |
| 2851 |
} |
| 2852 |
} |
| 2853 |
return { row: row, column: column }; |
| 2854 |
} |
| 2855 |
pos = readPosition(); |
| 2856 |
var range = Range.fromPoints(pos, pos); |
| 2857 |
if (parts[i] == ">") { |
| 2858 |
i++; |
| 2859 |
range.end = readPosition(); |
| 2860 |
} |
| 2861 |
else if (parts[i] == "<") { |
| 2862 |
i++; |
| 2863 |
range.start = readPosition(); |
| 2864 |
} |
| 2865 |
ranges.unshift(range); |
| 2866 |
}); |
| 2867 |
editor.selection.fromJSON(ranges); |
| 2868 |
var scrollTop = editor.renderer.scrollTop; |
| 2869 |
editor.renderer.scrollSelectionIntoView(editor.selection.anchor, editor.selection.cursor, 0.5); |
| 2870 |
editor.renderer.animateScrolling(scrollTop); |
| 2871 |
}, |
| 2872 |
history: function () { |
| 2873 |
if (!prompt.gotoLine["_history"]) |
| 2874 |
return []; |
| 2875 |
return prompt.gotoLine["_history"]; |
| 2876 |
}, |
| 2877 |
getCompletions: function (cmdLine) { |
| 2878 |
var value = cmdLine.getValue(); |
| 2879 |
var m = value.replace(/^:/, "").split(":"); |
| 2880 |
var row = Math.min(parseInt(m[0]) || 1, editor.session.getLength()) - 1; |
| 2881 |
var line = editor.session.getLine(row); |
| 2882 |
var current = value + " " + line; |
| 2883 |
return [current].concat(this.history()); |
| 2884 |
}, |
| 2885 |
$rules: { |
| 2886 |
start: [{ |
| 2887 |
regex: /\d+/, |
| 2888 |
token: "string" |
| 2889 |
}, { |
| 2890 |
regex: /[:,><+\-c]/, |
| 2891 |
token: "keyword" |
| 2892 |
}] |
| 2893 |
} |
| 2894 |
}); |
| 2895 |
}; |
| 2896 |
prompt.commands = function (editor, callback) { |
| 2897 |
function normalizeName(name) { |
| 2898 |
return (name || "").replace(/^./, function (x) { |
| 2899 |
return x.toUpperCase(x); |
| 2900 |
}).replace(/[a-z][A-Z]/g, function (x) { |
| 2901 |
return x[0] + " " + x[1].toLowerCase(x); |
| 2902 |
}); |
| 2903 |
} |
| 2904 |
function getEditorCommandsByName(excludeCommands) { |
| 2905 |
var commandsByName = []; |
| 2906 |
var commandMap = {}; |
| 2907 |
editor.keyBinding.$handlers.forEach(function (handler) { |
| 2908 |
var platform = handler["platform"]; |
| 2909 |
var cbn = handler["byName"]; |
| 2910 |
for (var i in cbn) { |
| 2911 |
var key = cbn[i].bindKey; |
| 2912 |
if (typeof key !== "string") { |
| 2913 |
key = key && key[platform] || ""; |
| 2914 |
} |
| 2915 |
var commands = cbn[i]; |
| 2916 |
var description = commands.description || normalizeName(commands.name); |
| 2917 |
if (!Array.isArray(commands)) |
| 2918 |
commands = [commands]; |
| 2919 |
commands.forEach(function (command) { |
| 2920 |
if (typeof command != "string") |
| 2921 |
command = command.name; |
| 2922 |
var needle = excludeCommands.find(function (el) { |
| 2923 |
return el === command; |
| 2924 |
}); |
| 2925 |
if (!needle) { |
| 2926 |
if (commandMap[command]) { |
| 2927 |
commandMap[command].key += "|" + key; |
| 2928 |
} |
| 2929 |
else { |
| 2930 |
commandMap[command] = { key: key, command: command, description: description }; |
| 2931 |
commandsByName.push(commandMap[command]); |
| 2932 |
} |
| 2933 |
} |
| 2934 |
}); |
| 2935 |
} |
| 2936 |
}); |
| 2937 |
return commandsByName; |
| 2938 |
} |
| 2939 |
var excludeCommandsList = ["insertstring", "inserttext", "setIndentation", "paste"]; |
| 2940 |
var shortcutsArray = getEditorCommandsByName(excludeCommandsList); |
| 2941 |
shortcutsArray = shortcutsArray.map(function (item) { |
| 2942 |
return { value: item.description, meta: item.key, command: item.command }; |
| 2943 |
}); |
| 2944 |
prompt(editor, "", { |
| 2945 |
name: "commands", |
| 2946 |
selection: [0, Number.MAX_VALUE], |
| 2947 |
maxHistoryCount: 5, |
| 2948 |
onAccept: function (data) { |
| 2949 |
if (data.item) { |
| 2950 |
var commandName = data.item.command; |
| 2951 |
this.addToHistory(data.item); |
| 2952 |
editor.execCommand(commandName); |
| 2953 |
} |
| 2954 |
}, |
| 2955 |
addToHistory: function (item) { |
| 2956 |
var history = this.history(); |
| 2957 |
history.unshift(item); |
| 2958 |
delete item.message; |
| 2959 |
for (var i = 1; i < history.length; i++) { |
| 2960 |
if (history[i]["command"] == item.command) { |
| 2961 |
history.splice(i, 1); |
| 2962 |
break; |
| 2963 |
} |
| 2964 |
} |
| 2965 |
if (this.maxHistoryCount > 0 && history.length > this.maxHistoryCount) { |
| 2966 |
history.splice(history.length - 1, 1); |
| 2967 |
} |
| 2968 |
prompt.commands["history"] = history; |
| 2969 |
}, |
| 2970 |
history: function () { |
| 2971 |
return prompt.commands["history"] || []; |
| 2972 |
}, |
| 2973 |
getPrefix: function (cmdLine) { |
| 2974 |
var currentPos = cmdLine.getCursorPosition(); |
| 2975 |
var filterValue = cmdLine.getValue(); |
| 2976 |
return filterValue.substring(0, currentPos.column); |
| 2977 |
}, |
| 2978 |
getCompletions: function (cmdLine) { |
| 2979 |
function getFilteredCompletions(commands, prefix) { |
| 2980 |
var resultCommands = JSON.parse(JSON.stringify(commands)); |
| 2981 |
var filtered = new FilteredList(resultCommands); |
| 2982 |
return filtered.filterCompletions(resultCommands, prefix); |
| 2983 |
} |
| 2984 |
function getUniqueCommandList(commands, usedCommands) { |
| 2985 |
if (!usedCommands || !usedCommands.length) { |
| 2986 |
return commands; |
| 2987 |
} |
| 2988 |
var excludeCommands = []; |
| 2989 |
usedCommands.forEach(function (item) { |
| 2990 |
excludeCommands.push(item.command); |
| 2991 |
}); |
| 2992 |
var resultCommands = []; |
| 2993 |
commands.forEach(function (item) { |
| 2994 |
if (excludeCommands.indexOf(item.command) === -1) { |
| 2995 |
resultCommands.push(item); |
| 2996 |
} |
| 2997 |
}); |
| 2998 |
return resultCommands; |
| 2999 |
} |
| 3000 |
var prefix = this.getPrefix(cmdLine); |
| 3001 |
var recentlyUsedCommands = getFilteredCompletions(this.history(), prefix); |
| 3002 |
var otherCommands = getUniqueCommandList(shortcutsArray, recentlyUsedCommands); |
| 3003 |
otherCommands = getFilteredCompletions(otherCommands, prefix); |
| 3004 |
if (recentlyUsedCommands.length && otherCommands.length) { |
| 3005 |
recentlyUsedCommands[0].message = nls("Recently used"); |
| 3006 |
otherCommands[0].message = nls("Other commands"); |
| 3007 |
} |
| 3008 |
var completions = recentlyUsedCommands.concat(otherCommands); |
| 3009 |
return completions.length > 0 ? completions : [{ |
| 3010 |
value: nls("No matching commands"), |
| 3011 |
error: 1 |
| 3012 |
}]; |
| 3013 |
} |
| 3014 |
}); |
| 3015 |
}; |
| 3016 |
prompt.modes = function (editor, callback) { |
| 3017 |
var modesArray = modelist.modes; |
| 3018 |
modesArray = modesArray.map(function (item) { |
| 3019 |
return { value: item.caption, mode: item.name }; |
| 3020 |
}); |
| 3021 |
prompt(editor, "", { |
| 3022 |
name: "modes", |
| 3023 |
selection: [0, Number.MAX_VALUE], |
| 3024 |
onAccept: function (data) { |
| 3025 |
if (data.item) { |
| 3026 |
var modeName = "ace/mode/" + data.item.mode; |
| 3027 |
editor.session.setMode(modeName); |
| 3028 |
} |
| 3029 |
}, |
| 3030 |
getPrefix: function (cmdLine) { |
| 3031 |
var currentPos = cmdLine.getCursorPosition(); |
| 3032 |
var filterValue = cmdLine.getValue(); |
| 3033 |
return filterValue.substring(0, currentPos.column); |
| 3034 |
}, |
| 3035 |
getCompletions: function (cmdLine) { |
| 3036 |
function getFilteredCompletions(modes, prefix) { |
| 3037 |
var resultCommands = JSON.parse(JSON.stringify(modes)); |
| 3038 |
var filtered = new FilteredList(resultCommands); |
| 3039 |
return filtered.filterCompletions(resultCommands, prefix); |
| 3040 |
} |
| 3041 |
var prefix = this.getPrefix(cmdLine); |
| 3042 |
var completions = getFilteredCompletions(modesArray, prefix); |
| 3043 |
return completions.length > 0 ? completions : [{ |
| 3044 |
"caption": "No mode matching", |
| 3045 |
"value": "No mode matching", |
| 3046 |
"error": 1 |
| 3047 |
}]; |
| 3048 |
} |
| 3049 |
}); |
| 3050 |
}; |
| 3051 |
dom.importCssString(".ace_prompt_container {\n max-width: 603px;\n width: 100%;\n margin: 20px auto;\n padding: 3px;\n background: white;\n border-radius: 2px;\n box-shadow: 0px 2px 3px 0px #555;\n}", "promtp.css", false); |
| 3052 |
exports.prompt = prompt; |
| 3053 |
|
| 3054 |
}); (function() { |
| 3055 |
ace.require(["ace/ext/prompt"], function(m) { |
| 3056 |
if (typeof module == "object" && typeof exports == "object" && module) { |
| 3057 |
module.exports = m; |
| 3058 |
} |
| 3059 |
}); |
| 3060 |
})(); |
| 3061 |
|