vendor/assets/javascripts/ace/ext-language_tools.js in ace-rails-ap-3.0.2 vs vendor/assets/javascripts/ace/ext-language_tools.js in ace-rails-ap-3.0.3

- old
+ new

@@ -1067,21 +1067,26 @@ } } if (data.meta) { var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth; - if (data.meta.length + data.caption.length < maxW - 2) - tokens.push({type: "rightAlignedText", value: data.meta}); + var metaData = data.meta; + if (metaData.length + data.caption.length > maxW - 2) { + metaData = metaData.substr(0, maxW - data.caption.length - 3) + "\u2026" + } + tokens.push({type: "rightAlignedText", value: metaData}); } return tokens; }; bgTokenizer.$updateOnChange = noop; bgTokenizer.start = noop; popup.session.$computeWidth = function() { return this.screenWidth = 0; }; + + popup.$blockScrolling = Infinity; popup.isOpen = false; popup.isTopdown = false; popup.data = []; popup.setData = function(list) { @@ -1109,10 +1114,11 @@ }; popup.on("changeSelection", function() { if (popup.isOpen) popup.setRow(popup.selection.lead.row); + popup.renderer.scrollCursorIntoView(); }); popup.hide = function() { this.container.style.display = "none"; this._signal("hide"); @@ -1261,12 +1267,14 @@ var lang = require("./lib/lang"); var dom = require("./lib/dom"); var snippetManager = require("./snippets").snippetManager; var Autocomplete = function() { - this.autoInsert = true; + this.autoInsert = false; this.autoSelect = true; + this.exactMatch = false; + this.gatherCompletionsId = 0; this.keyboardHandler = new HashHandler(); this.keyboardHandler.bindKeys(this.commands); this.blurListener = this.blurListener.bind(this); this.changeListener = this.changeListener.bind(this); @@ -1274,16 +1282,15 @@ this.mousewheelListener = this.mousewheelListener.bind(this); this.changeTimer = lang.delayedCall(function() { this.updateCompletions(true); }.bind(this)); - + this.tooltipTimer = lang.delayedCall(this.updateDocTooltip.bind(this), 50); }; (function() { - this.gatherCompletionsId = 0; this.$init = function() { this.popup = new AcePopup(document.body || document.documentElement); this.popup.on("click", function(e) { this.insertMatch(); @@ -1293,21 +1300,23 @@ this.popup.on("show", this.tooltipTimer.bind(null, null)); this.popup.on("select", this.tooltipTimer.bind(null, null)); this.popup.on("changeHoverMarker", this.tooltipTimer.bind(null, null)); return this.popup; }; - + this.getPopup = function() { return this.popup || this.$init(); }; this.openPopup = function(editor, prefix, keepPopupPosition) { if (!this.popup) this.$init(); this.popup.setData(this.completions.filtered); + editor.keyBinding.addKeyboardHandler(this.keyboardHandler); + var renderer = editor.renderer; this.popup.setRow(this.autoSelect ? 0 : -1); if (!keepPopupPosition) { this.popup.setTheme(editor.getTheme()); this.popup.setFontSize(editor.getFontSize()); @@ -1335,15 +1344,14 @@ this.editor.off("mousedown", this.mousedownListener); this.editor.off("mousewheel", this.mousewheelListener); this.changeTimer.cancel(); this.hideDocTooltip(); - if (this.popup && this.popup.isOpen) { - this.gatherCompletionsId += 1; + this.gatherCompletionsId += 1; + if (this.popup && this.popup.isOpen) this.popup.hide(); - } - + if (this.base) this.base.detach(); this.activated = false; this.completions = this.base = null; }; @@ -1360,11 +1368,11 @@ }; this.blurListener = function(e) { var el = document.activeElement; var text = this.editor.textInput.getElement() - if (el != text && el.parentNode != this.popup.container + if (el != text && ( !this.popup || el.parentNode != this.popup.container ) && el != this.tooltipNode && e.relatedTarget != this.tooltipNode && e.relatedTarget != text ) { this.detach(); } @@ -1422,11 +1430,10 @@ "Down": function(editor) { editor.completer.goTo("down"); }, "Ctrl-Up|Ctrl-Home": function(editor) { editor.completer.goTo("start"); }, "Ctrl-Down|Ctrl-End": function(editor) { editor.completer.goTo("end"); }, "Esc": function(editor) { editor.completer.detach(); }, - "Space": function(editor) { editor.completer.detach(); editor.insert(" ");}, "Return": function(editor) { return editor.completer.insertMatch(); }, "Shift-Return": function(editor) { editor.completer.insertMatch(true); }, "Tab": function(editor) { var result = editor.completer.insertMatch(); if (!result && !editor.tabstopManager) @@ -1446,11 +1453,11 @@ var line = session.getLine(pos.row); var prefix = util.retrievePrecedingIdentifier(line, pos.column); this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length); this.base.$insertRight = true; - + var matches = []; var total = editor.completers.length; editor.completers.forEach(function(completer, i) { completer.getCompletions(editor, session, pos, prefix, function(err, results) { if (!err) @@ -1478,11 +1485,10 @@ if (editor.completer) editor.completer.detach(); editor.completer = this; } - editor.keyBinding.addKeyboardHandler(this.keyboardHandler); editor.on("changeSelection", this.changeListener); editor.on("blur", this.blurListener); editor.on("mousedown", this.mousedownListener); editor.on("mousewheel", this.mousewheelListener); @@ -1512,17 +1518,21 @@ return this.detach(); }.bind(this); var prefix = results.prefix; var matches = results && results.matches; - + if (!matches || !matches.length) return detachIfFinished(); if (prefix.indexOf(results.prefix) !== 0 || _id != this.gatherCompletionsId) return; this.completions = new FilteredList(matches); + + if (this.exactMatch) + this.completions.exactMatch = true; + this.completions.setFilter(prefix); var filtered = this.completions.filtered; if (!filtered.length) return detachIfFinished(); if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet) @@ -1535,11 +1545,11 @@ }; this.cancelContextMenu = function() { this.editor.$mouseHandler.cancelContextMenu(); }; - + this.updateDocTooltip = function() { var popup = this.popup; var all = popup.data; var selected = all && (all[popup.getHoveredRow()] || all[popup.getRow()]); var doc = null; @@ -1550,71 +1560,71 @@ doc = completer.getDocTooltip(selected); return doc; }); if (!doc) doc = selected; - + if (typeof doc == "string") doc = {docText: doc} if (!doc || !(doc.docHTML || doc.docText)) return this.hideDocTooltip(); this.showDocTooltip(doc); }; - + this.showDocTooltip = function(item) { if (!this.tooltipNode) { this.tooltipNode = dom.createElement("div"); this.tooltipNode.className = "ace_tooltip ace_doc-tooltip"; this.tooltipNode.style.margin = 0; this.tooltipNode.style.pointerEvents = "auto"; this.tooltipNode.tabIndex = -1; this.tooltipNode.onblur = this.blurListener.bind(this); } - + var tooltipNode = this.tooltipNode; if (item.docHTML) { tooltipNode.innerHTML = item.docHTML; } else if (item.docText) { tooltipNode.textContent = item.docText; } - + if (!tooltipNode.parentNode) - document.body.appendChild(tooltipNode); + document.body.appendChild(tooltipNode); var popup = this.popup; var rect = popup.container.getBoundingClientRect(); tooltipNode.style.top = popup.container.style.top; tooltipNode.style.bottom = popup.container.style.bottom; - + if (window.innerWidth - rect.right < 320) { tooltipNode.style.right = window.innerWidth - rect.left + "px"; tooltipNode.style.left = ""; } else { tooltipNode.style.left = (rect.right + 1) + "px"; tooltipNode.style.right = ""; } tooltipNode.style.display = "block"; }; - + this.hideDocTooltip = function() { this.tooltipTimer.cancel(); if (!this.tooltipNode) return; var el = this.tooltipNode; if (!this.editor.isFocused() && document.activeElement == el) this.editor.focus(); this.tooltipNode = null; - if (el.parentNode) + if (el.parentNode) el.parentNode.removeChild(el); }; }).call(Autocomplete.prototype); Autocomplete.startCommand = { name: "startAutocomplete", exec: function(editor) { if (!editor.completer) editor.completer = new Autocomplete(); - editor.completer.autoInsert = + editor.completer.autoInsert = false; editor.completer.autoSelect = true; editor.completer.showPopup(editor); editor.completer.cancelContextMenu(); }, bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space" @@ -1622,10 +1632,11 @@ var FilteredList = function(array, filterText, mutateData) { this.all = array; this.filtered = array; this.filterText = filterText || ""; + this.exactMatch = false; }; (function(){ this.setFilter = function(str) { if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0) var matches = this.filtered; @@ -1656,24 +1667,30 @@ if (!caption) continue; var lastIndex = -1; var matchMask = 0; var penalty = 0; var index, distance; - for (var j = 0; j < needle.length; j++) { - var i1 = caption.indexOf(lower[j], lastIndex + 1); - var i2 = caption.indexOf(upper[j], lastIndex + 1); - index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2; - if (index < 0) + + if (this.exactMatch) { + if (needle !== caption.substr(0, needle.length)) continue loop; - distance = index - lastIndex - 1; - if (distance > 0) { - if (lastIndex === -1) - penalty += 10; - penalty += distance; + }else{ + for (var j = 0; j < needle.length; j++) { + var i1 = caption.indexOf(lower[j], lastIndex + 1); + var i2 = caption.indexOf(upper[j], lastIndex + 1); + index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2; + if (index < 0) + continue loop; + distance = index - lastIndex - 1; + if (distance > 0) { + if (lastIndex === -1) + penalty += 10; + penalty += distance; + } + matchMask = matchMask | (1 << index); + lastIndex = index; } - matchMask = matchMask | (1 << index); - lastIndex = index; } item.matchMask = matchMask; item.exactMatch = penalty ? 0 : 1; item.score = (item.score || 0) - penalty; results.push(item); @@ -1837,20 +1854,20 @@ }; function getCompletionPrefix(editor) { var pos = editor.getCursorPosition(); var line = editor.session.getLine(pos.row); - var prefix = util.retrievePrecedingIdentifier(line, pos.column); + var prefix; editor.completers.forEach(function(completer) { if (completer.identifierRegexps) { completer.identifierRegexps.forEach(function(identifierRegex) { if (!prefix && identifierRegex) prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex); }); } }); - return prefix; + return prefix || util.retrievePrecedingIdentifier(line, pos.column); } var doLiveAutocomplete = function(e) { var editor = e.editor; var text = e.args || ""; @@ -1863,10 +1880,9 @@ var prefix = getCompletionPrefix(editor); if (prefix && !hasCompleter) { if (!editor.completer) { editor.completer = new Autocomplete(); } - editor.completer.autoSelect = false; editor.completer.autoInsert = false; editor.completer.showPopup(editor); } } }; \ No newline at end of file