From 808bb955383e919d6766fd3bcb7514717309b768 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Fri, 21 Dec 2012 17:07:00 -0800 Subject: [PATCH 01/31] Let us begin --- lib/ace/autocomplete.js | 151 ++++++++++++++++++++++++++ lib/ace/css/editor.css | 9 ++ lib/ace/editor.js | 232 +++++++++++++++++++++------------------- 3 files changed, 282 insertions(+), 110 deletions(-) create mode 100644 lib/ace/autocomplete.js diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js new file mode 100644 index 00000000..dd53b684 --- /dev/null +++ b/lib/ace/autocomplete.js @@ -0,0 +1,151 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("./lib/oop"); +var EventEmitter = require("./lib/event_emitter").EventEmitter; + +var Autocomplete = function(editor) { + var self = this; + this.editor = editor; + + var originalOnTextInput = editor.onTextInput; + var originalSoftTabs = editor.session.getUseSoftTabs(); + + // Create the suggest list + this.autocompleteContainer = document.createElement('div'); + this.autocompleteContainer.className = 'ace_autocomplete'; + + this.selection = this.autocompleteContainer.appendChild(document.createElement("select")); +}; + + +(function() { + + oop.implement(this, EventEmitter); + + this.current = function() { + var children = element.childNodes; + for (var i = 0; i < children.length; i++) { + var li = children[i]; + if(li.className == 'ace_autocomplete_selected') { + return li; + } + }; + } + + this.focusNext = function() { + var curr = current(); + curr.className = ''; + var focus = curr.nextSibling || curr.parentNode.firstChild; + focus.className = 'ace_autocomplete_selected'; + } + + this.focusPrev = function() { + var curr = current(); + curr.className = ''; + var focus = curr.previousSibling || curr.parentNode.lastChild; + focus.className = 'ace_autocomplete_selected'; + } + + this.ensureFocus = function() { + if(!current()) { + element.firstChild.className = 'ace_autocomplete_selected'; + } + } + + this.replace = function() { + var Range = require('ace/range').Range; + var range = new Range(self.row, self.column, self.row, self.column + 1000); + // Firefox does not support innerText property, don't know about IE + // http://blog.coderlab.us/2005/09/22/using-the-innertext-property-with-firefox/ + var selectedValue; + if(document.all){ + selectedValue = current().innerText; + } else{ + selectedValue = current().textContent; + } + + editor.session.replace(range, selectedValue); + // Deactivate asynchrounously, so that in case of ENTER - we don't reactivate immediately. + setTimeout(function() { + deactivate(); + }, 0); + } + + this.deactivate = function() { + // Hide list + element.style.display = 'none'; + + // Restore keyboard + editor.session.setUseSoftTabs(originalSoftTabs); + editor.onTextInput = originalOnTextInput; + + self.active = false; + } + + // Shows the list and reassigns keys + this.activate = function(row, column) { + if(this.active) return; + this.active = true; + this.row = row; + this.column = column; + + // Position the list + var coords = this.editor.renderer.textToScreenCoordinates(row, column); + this.autocompleteContainer.style.top = coords.pageY + 18 + 'px'; + this.autocompleteContainer.style.left = coords.pageX + -2 + 'px'; + this.autocompleteContainer.style.display = 'block'; + }; + + // Sets the text the suggest should be based on. + // afterText indicates the position where the suggest box should start. + this.suggest = function(text) { + var options = ["FUNK", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk"];//matches(text); + if (options.length == 0) { + return deactivate(); + } + + for (var n = 0; n < options.length; n++) { + var opt = this.selection.appendChild(document.createElement("option")); + opt.appendChild(document.createTextNode(options[n])); + } + this.selection.firstChild.selected = true; + this.selection.size = Math.min(10, options.length); + + document.body.appendChild(this.autocompleteContainer); + //ensureFocus(); + }; +}).call(Autocomplete.prototype); + +exports.Autocomplete = Autocomplete; +}); diff --git a/lib/ace/css/editor.css b/lib/ace/css/editor.css index 4f32b905..0aeff4dc 100644 --- a/lib/ace/css/editor.css +++ b/lib/ace/css/editor.css @@ -386,3 +386,12 @@ .ace_italic { font-style: italic; } + +.ace_autocomplete { + position: fixed; + z-index: 9999; +} + +.ace_autocomplete li { + color: #000000; +} diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 62a4c37f..2e46aed0 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -46,15 +46,16 @@ var Search = require("./search").Search; var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; var CommandManager = require("./commands/command_manager").CommandManager; +var Autocomplete = require("./autocomplete").Autocomplete; var defaultCommands = require("./commands/default_commands").commands; var config = require("./config"); /** * * - * The main entry point into the Ace functionality. + * The main entry point into the Ace functionality. * - * The `Editor` manages the [[EditSession]] (which manages [[Document]]s), as well as the [[VirtualRenderer]], which draws everything to the screen. + * The `Editor` manages the [[EditSession]] (which manages [[Document]]s), as well as the [[VirtualRenderer]], which draws everything to the screen. * * Event sessions dealing with the mouse and keyboard are bubbled up from `Document` to the `Editor`, which decides what to do with them. * @class Editor @@ -89,6 +90,7 @@ var Editor = function(renderer, session) { }); this.setSession(session || new EditSession("")); + this.auto = new Autocomplete(this); config.resetOptions(this); config._emit("editor", this); }; @@ -101,7 +103,7 @@ var Editor = function(renderer, session) { * Sets a new key handler, such as "vim" or "windows". * @param {String} keyboardHandler The new key handler * - * + * **/ this.setKeyboardHandler = function(keyboardHandler) { if (!keyboardHandler) { @@ -119,11 +121,11 @@ var Editor = function(renderer, session) { } }; - /** + /** * Returns the keyboard handler, such as "vim" or "windows". * * @returns {String} - * + * **/ this.getKeyboardHandler = function() { return this.keyBinding.getKeyboardHandler(); @@ -250,7 +252,7 @@ var Editor = function(renderer, session) { return this.session; }; - /** + /** * Sets the current document to `val`. * @param {String} val The new value to set for the document * @param {Number} cursorPos Where to set the new value. `undefined` or 0 is selectAll, -1 is at the document start, and 1 is at the end @@ -271,7 +273,7 @@ var Editor = function(renderer, session) { return val; }; - /** + /** * Returns the current session's content. * * @returns {String} @@ -282,7 +284,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Returns the currently highlighted selection. * @returns {String} The highlighted selection **/ @@ -290,11 +292,11 @@ var Editor = function(renderer, session) { return this.selection; }; - /** + /** * {:VirtualRenderer.onResize} * @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed * - * + * * @related VirtualRenderer.onResize **/ this.resize = function(force) { @@ -311,9 +313,9 @@ var Editor = function(renderer, session) { this.renderer.setTheme(theme); }; - /** + /** * {:VirtualRenderer.getTheme} - * + * * @returns {String} The set theme * @related VirtualRenderer.getTheme **/ @@ -325,14 +327,14 @@ var Editor = function(renderer, session) { * {:VirtualRenderer.setStyle} * @param {String} style A class name * - * + * * @related VirtualRenderer.setStyle **/ this.setStyle = function(style) { this.renderer.setStyle(style); }; - /** + /** * {:VirtualRenderer.unsetStyle} * @related VirtualRenderer.unsetStyle **/ @@ -351,8 +353,8 @@ var Editor = function(renderer, session) { /** * Set a new font size (in pixels) for the editor text. * @param {String} size A font size ( _e.g._ "12px") - * - * + * + * **/ this.setFontSize = function(size) { this.setOption("fontSize", size); @@ -386,7 +388,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Brings the current `textInput` into focus. **/ this.focus = function() { @@ -409,7 +411,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Blurs the current `textInput`. **/ this.blur = function() { @@ -418,9 +420,9 @@ var Editor = function(renderer, session) { /** * Emitted once the editor comes into focus. - * @event focus - * - * + * @event focus + * + * **/ this.onFocus = function() { if (this.$isFocused) @@ -434,8 +436,8 @@ var Editor = function(renderer, session) { /** * Emitted once the editor has been blurred. * @event blur - * - * + * + * **/ this.onBlur = function() { if (!this.$isFocused) @@ -451,12 +453,12 @@ var Editor = function(renderer, session) { }; /** - * Emitted whenever the document is changed. + * Emitted whenever the document is changed. * @event change * @param {Object} e Contains a single property, `data`, which has the delta of changes * * - * + * **/ this.onDocumentChange = function(e) { var delta = e.data; @@ -471,6 +473,16 @@ var Editor = function(renderer, session) { this._emit("change", e); + var source = this.session.getValue(); + var _self = this; + setTimeout(function() { + var cursor = _self.getCursorPosition(); + var line = _self.session.getLine(cursor.row); + + _self.auto.activate(cursor.row, cursor.column); + _self.auto.suggest(name); + }, 0); + // update cursor because tab characters can influence the cursor position this.$cursorChange(); }; @@ -484,14 +496,14 @@ var Editor = function(renderer, session) { this.onScrollTopChange = function() { this.renderer.scrollToY(this.session.getScrollTop()); }; - + this.onScrollLeftChange = function() { this.renderer.scrollToX(this.session.getScrollLeft()); }; /** * Emitted when the selection changes. - * + * **/ this.onCursorChange = function() { this.$cursorChange(); @@ -547,7 +559,7 @@ var Editor = function(renderer, session) { var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp() this.session.highlight(re); - + this._emit("changeSelection"); }; @@ -627,10 +639,10 @@ var Editor = function(renderer, session) { /** * Emitted when text is copied. - * @event copy + * @event copy * @param {String} text The copied text * - * + * **/ /** * @@ -676,7 +688,7 @@ var Editor = function(renderer, session) { **/ this.onPaste = function(text) { // todo this should change when paste becomes a command - if (this.$readOnly) + if (this.$readOnly) return; this._emit("paste", text); this.insert(text); @@ -690,8 +702,8 @@ var Editor = function(renderer, session) { /** * Inserts `text` into wherever the cursor is pointing. * @param {String} text The new text to add - * - * + * + * **/ this.insert = function(text) { var session = this.session; @@ -791,10 +803,10 @@ var Editor = function(renderer, session) { this.keyBinding.onCommandKey(e, hashId, keyCode); }; - /** + /** * Pass in `true` to enable overwrites in your session, or `false` to disable. If overwrites is enabled, any text you enter will type over any text after it. If the value of `overwrite` changes, this function also emites the `changeOverwrite` event. * @param {Boolean} overwrite Defines wheter or not to set overwrites - * + * * * @related EditSession.setOverwrite **/ @@ -802,7 +814,7 @@ var Editor = function(renderer, session) { this.session.setOverwrite(overwrite); }; - /** + /** * Returns `true` if overwrites are enabled; `false` otherwise. * @returns {Boolean} * @related EditSession.getOverwrite @@ -811,7 +823,7 @@ var Editor = function(renderer, session) { return this.session.getOverwrite(); }; - /** + /** * Sets the value of overwrite to the opposite of whatever it currently is. * @related EditSession.toggleOverwrite **/ @@ -859,7 +871,7 @@ var Editor = function(renderer, session) { /** * Draw selection markers spanning whole line, or only over selected text. Default value is "line" * @param {String} style The new selection style "line"|"text" - * + * **/ this.setSelectionStyle = function(val) { this.setOption("selectionStyle", val); @@ -922,7 +934,7 @@ var Editor = function(renderer, session) { /** * If `showInvisibles` is set to `true`, invisible characters—like spaces or new lines—are show in the editor. * @param {Boolean} showInvisibles Specifies whether or not to show invisible characters - * + * **/ this.setShowInvisibles = function(showInvisibles) { this.renderer.setShowInvisibles(showInvisibles); @@ -947,7 +959,7 @@ var Editor = function(renderer, session) { /** * If `showPrintMargin` is set to `true`, the print margin is shown in the editor. * @param {Boolean} showPrintMargin Specifies whether or not to show the print margin - * + * **/ this.setShowPrintMargin = function(showPrintMargin) { this.renderer.setShowPrintMargin(showPrintMargin); @@ -981,7 +993,7 @@ var Editor = function(renderer, session) { /** * If `readOnly` is true, then the editor is set to read-only mode, and none of the content can change. * @param {Boolean} readOnly Specifies whether the editor can be modified or not - * + * **/ this.setReadOnly = function(readOnly) { this.setOption("readOnly", readOnly); @@ -998,7 +1010,7 @@ var Editor = function(renderer, session) { /** * Specifies whether to use behaviors or not. ["Behaviors" in this case is the auto-pairing of special characters, like quotation marks, parenthesis, or brackets.]{: #BehaviorsDef} * @param {Boolean} enabled Enables or disables behaviors - * + * **/ this.setBehavioursEnabled = function (enabled) { this.setOption("behavioursEnabled", enabled); @@ -1006,7 +1018,7 @@ var Editor = function(renderer, session) { /** * Returns `true` if the behaviors are currently enabled. {:BehaviorsDef} - * + * * @returns {Boolean} **/ this.getBehavioursEnabled = function () { @@ -1017,7 +1029,7 @@ var Editor = function(renderer, session) { * Specifies whether to use wrapping behaviors or not, i.e. automatically wrapping the selection with characters such as brackets * when such a character is typed in. * @param {Boolean} enabled Enables or disables wrapping behaviors - * + * **/ this.setWrapBehavioursEnabled = function (enabled) { this.setOption("wrapBehavioursEnabled", enabled); @@ -1057,7 +1069,7 @@ var Editor = function(renderer, session) { /** * Removes words of text from the editor. A "word" is defined as a string of characters bookended by whitespace. * @param {String} dir The direction of the deletion to occur, either "left" or "right" - * + * **/ this.remove = function(dir) { if (this.selection.isEmpty()){ @@ -1202,7 +1214,7 @@ var Editor = function(renderer, session) { /** * Inserts an indentation into the current cursor position or indents the selected lines. - * + * * @related EditSession.indentRows **/ this.indent = function() { @@ -1309,7 +1321,7 @@ var Editor = function(renderer, session) { } return null; }; - + /** * If the character before the cursor is a number, this functions changes its value by `amount`. * @param {Number} amount The value to change the numeral by (can be negative to decrease value) @@ -1334,14 +1346,14 @@ var Editor = function(renderer, session) { var t = parseFloat(nr.value); t *= Math.pow(10, decimals); - + if(fp !== nr.end && column < fp){ amount *= Math.pow(10, nr.end - column - 1); } else { amount *= Math.pow(10, nr.end - column); } - + t += amount; t /= Math.pow(10, decimals); var nnr = t.toFixed(decimals); @@ -1356,8 +1368,8 @@ var Editor = function(renderer, session) { } } }; - - /** + + /** * Removes all the lines in the current selection * @related EditSession.remove **/ @@ -1388,12 +1400,12 @@ var Editor = function(renderer, session) { var endPoint = doc.insert(point, doc.getTextRange(range), false); range.start = point; range.end = endPoint; - + sel.setSelectionRange(range, reverse) } }; - - /** + + /** * Shifts all the selected lines down one row. * * @returns {Number} On success, it returns -1. @@ -1405,7 +1417,7 @@ var Editor = function(renderer, session) { }); }; - /** + /** * Shifts all the selected lines up one row. * @returns {Number} On success, it returns -1. * @related EditSession.moveLinesDown @@ -1416,14 +1428,14 @@ var Editor = function(renderer, session) { }); }; - /** + /** * Moves a range of text from the given range to the given position. `toPosition` is an object that looks like this: * ```json * { row: newRowLocation, column: newColumnLocation } * ``` * @param {Range} fromRange The range of text you want moved within the document * @param {Object} toPosition The location (row and column) where you want to move the text to - * + * * @returns {Range} The new range where the text was moved to. * @related EditSession.moveText **/ @@ -1431,10 +1443,10 @@ var Editor = function(renderer, session) { return this.session.moveText(range, toPosition); }; - /** + /** * Copies all the selected lines up one row. * @returns {Number} On success, returns 0. - * + * **/ this.copyLinesUp = function() { this.$moveLines(function(firstRow, lastRow) { @@ -1443,7 +1455,7 @@ var Editor = function(renderer, session) { }); }; - /** + /** * Copies all the selected lines down one row. * @returns {Number} On success, returns the number of new rows added; in other words, `lastRow - firstRow + 1`. * @related EditSession.duplicateLines @@ -1458,7 +1470,7 @@ var Editor = function(renderer, session) { /** * Executes a specific function, which can be anything that manipulates selected lines, such as copying them, duplicating them, or shifting them. * @param {Function} mover A method to call on each selected row - * + * * **/ this.$moveLines = function(mover) { @@ -1466,7 +1478,7 @@ var Editor = function(renderer, session) { if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) { var range = selection.toOrientedRange(); var rows = this.$getSelectedRows(range); - var linesMoved = mover.call(this, rows.first, rows.last); + var linesMoved = mover.call(this, rows.first, rows.last); range.moveBy(linesMoved, 0); selection.fromOrientedRange(range); } else { @@ -1484,14 +1496,14 @@ var Editor = function(renderer, session) { first = rows.end.row; else break; - } + } i++; var linesMoved = mover.call(this, first, last); while (rangeIndex >= i) { ranges[rangeIndex].moveBy(linesMoved, 0); rangeIndex--; - } + } } selection.fromOrientedRange(selection.ranges[0]); selection.rangeList.attach(this.session); @@ -1528,7 +1540,7 @@ var Editor = function(renderer, session) { this.renderer.hideComposition(); }; - /** + /** * {:VirtualRenderer.getFirstVisibleRow} * * @returns {Number} @@ -1538,7 +1550,7 @@ var Editor = function(renderer, session) { return this.renderer.getFirstVisibleRow(); }; - /** + /** * {:VirtualRenderer.getLastVisibleRow} * * @returns {Number} @@ -1551,7 +1563,7 @@ var Editor = function(renderer, session) { /** * Indicates if the row is currently visible on the screen. * @param {Number} row The row to check - * + * * @returns {Boolean} **/ this.isRowVisible = function(row) { @@ -1561,8 +1573,8 @@ var Editor = function(renderer, session) { /** * Indicates if the entire row is currently visible on the screen. * @param {Number} row The row to check - * - * + * + * * @returns {Boolean} **/ this.isRowFullyVisible = function(row) { @@ -1644,7 +1656,7 @@ var Editor = function(renderer, session) { this.$moveByPage(-1); }; - /** + /** * Moves the editor to the specified row. * @related VirtualRenderer.scrollToRow **/ @@ -1652,14 +1664,14 @@ var Editor = function(renderer, session) { this.renderer.scrollToRow(row); }; - /** + /** * Scrolls to a line. If `center` is `true`, it puts the line in middle of screen (or attempts to). * @param {Number} line The line to scroll to - * @param {Boolean} center If `true` + * @param {Boolean} center If `true` * @param {Boolean} animate If `true` animates scrolling * @param {Function} callback Function to be called when the animation has finished * - * + * * @related VirtualRenderer.scrollToLine **/ this.scrollToLine = function(line, center, animate, callback) { @@ -1678,9 +1690,9 @@ var Editor = function(renderer, session) { this.renderer.alignCursor(pos, 0.5); }; - /** + /** * Gets the current position of the cursor. - * @returns {Object} An object that looks something like this: + * @returns {Object} An object that looks something like this: * * ```json * { row: currRow, column: currCol } @@ -1692,7 +1704,7 @@ var Editor = function(renderer, session) { return this.selection.getCursor(); }; - /** + /** * Returns the screen position of the cursor. * @returns {Number} * @related EditSession.documentToScreenPosition @@ -1701,7 +1713,7 @@ var Editor = function(renderer, session) { return this.session.documentToScreenPosition(this.getCursorPosition()); }; - /** + /** * {:Selection.getRange} * @returns {Range} * @related Selection.getRange @@ -1711,7 +1723,7 @@ var Editor = function(renderer, session) { }; - /** + /** * Selects all the text in editor. * @related Selection.selectAll **/ @@ -1721,7 +1733,7 @@ var Editor = function(renderer, session) { this.$blockScrolling -= 1; }; - /** + /** * {:Selection.clearSelection} * @related Selection.clearSelection **/ @@ -1729,7 +1741,7 @@ var Editor = function(renderer, session) { this.selection.clearSelection(); }; - /** + /** * Moves the cursor to the specified row and column. Note that this does not de-select the current selection. * @param {Number} row The new row number * @param {Number} column The new column number @@ -1741,10 +1753,10 @@ var Editor = function(renderer, session) { this.selection.moveCursorTo(row, column); }; - /** + /** * Moves the cursor to the position indicated by `pos.row` and `pos.column`. * @param {Object} pos An object with two properties, row and column - * + * * * @related Selection.moveCursorToPosition **/ @@ -1752,7 +1764,7 @@ var Editor = function(renderer, session) { this.selection.moveCursorToPosition(pos); }; - /** + /** * Moves the cursor's row and column to the next matching bracket. * **/ @@ -1772,7 +1784,7 @@ var Editor = function(renderer, session) { if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2) range = this.session.getBracketRange(pos); } - + pos = range && range.cursor || pos; if (pos) { if (select) { @@ -1792,7 +1804,7 @@ var Editor = function(renderer, session) { * @param {Number} lineNumber The line number to go to * @param {Number} column A column number to go to * @param {Boolean} animate If `true` animates scolling - * + * **/ this.gotoLine = function(lineNumber, column, animate) { this.selection.clearSelection(); @@ -1808,7 +1820,7 @@ var Editor = function(renderer, session) { this.scrollToLine(lineNumber - 1, true, animate); }; - /** + /** * Moves the cursor to the specified row and column. Note that this does de-select the current selection. * @param {Number} row The new row number * @param {Number} column The new column number @@ -1824,8 +1836,8 @@ var Editor = function(renderer, session) { /** * Moves the cursor up in the document the specified number of times. Note that this does de-select the current selection. * @param {Number} times The number of times to change navigation - * - * + * + * **/ this.navigateUp = function(times) { if (this.selection.isMultiLine() && !this.selection.isBackwards()) { @@ -1840,8 +1852,8 @@ var Editor = function(renderer, session) { /** * Moves the cursor down in the document the specified number of times. Note that this does de-select the current selection. * @param {Number} times The number of times to change navigation - * - * + * + * **/ this.navigateDown = function(times) { if (this.selection.isMultiLine() && this.selection.isBackwards()) { @@ -1856,8 +1868,8 @@ var Editor = function(renderer, session) { /** * Moves the cursor left in the document the specified number of times. Note that this does de-select the current selection. * @param {Number} times The number of times to change navigation - * - * + * + * **/ this.navigateLeft = function(times) { if (!this.selection.isEmpty()) { @@ -1876,8 +1888,8 @@ var Editor = function(renderer, session) { /** * Moves the cursor right in the document the specified number of times. Note that this does de-select the current selection. * @param {Number} times The number of times to change navigation - * - * + * + * **/ this.navigateRight = function(times) { if (!this.selection.isEmpty()) { @@ -1894,7 +1906,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the start of the current line. Note that this does de-select the current selection. **/ this.navigateLineStart = function() { @@ -1903,7 +1915,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the end of the current line. Note that this does de-select the current selection. **/ this.navigateLineEnd = function() { @@ -1912,7 +1924,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the end of the current file. Note that this does de-select the current selection. **/ this.navigateFileEnd = function() { @@ -1923,7 +1935,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the start of the current file. Note that this does de-select the current selection. **/ this.navigateFileStart = function() { @@ -1934,7 +1946,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the word immediately to the right of the current position. Note that this does de-select the current selection. **/ this.navigateWordRight = function() { @@ -1943,7 +1955,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the word immediately to the left of the current position. Note that this does de-select the current selection. **/ this.navigateWordLeft = function() { @@ -2024,7 +2036,7 @@ var Editor = function(renderer, session) { } }; - /** + /** * {:Search.getOptions} For more information on `options`, see [[Search `Search`]]. * @related Search.getOptions * @returns {Object} @@ -2033,7 +2045,7 @@ var Editor = function(renderer, session) { return this.$search.getOptions(); }; - /** + /** * Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]]. * @param {String} needle The text to search for (optional) * @param {Object} options An object defining various search properties @@ -2081,7 +2093,7 @@ var Editor = function(renderer, session) { this.selection.setRange(range); }; - /** + /** * Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]]. * @param {Object} options search options * @param {Boolean} animate If `true` animate scrolling @@ -2093,7 +2105,7 @@ var Editor = function(renderer, session) { this.find({skipCurrent: true, backwards: false}, options, animate); }; - /** + /** * Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]]. * @param {Object} options search options * @param {Boolean} animate If `true` animate scrolling @@ -2117,7 +2129,7 @@ var Editor = function(renderer, session) { this.renderer.animateScrolling(scrollTop); }; - /** + /** * {:UndoManager.undo} * @related UndoManager.undo **/ @@ -2128,7 +2140,7 @@ var Editor = function(renderer, session) { this.renderer.scrollCursorIntoView(null, 0.5); }; - /** + /** * {:UndoManager.redo} * @related UndoManager.redo **/ @@ -2139,8 +2151,8 @@ var Editor = function(renderer, session) { this.renderer.scrollCursorIntoView(null, 0.5); }; - /** - * + /** + * * Cleans up the entire editor. **/ this.destroy = function() { From dbca4444bfcb975c6b2f6699bd19d0469ae25f50 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sat, 22 Dec 2012 11:26:57 -0800 Subject: [PATCH 02/31] Implement keybindings and such --- lib/ace/autocomplete.js | 121 ++++++++++++++++----------- lib/ace/commands/command_manager.js | 7 +- lib/ace/commands/default_commands.js | 5 ++ lib/ace/editor.js | 12 ++- 4 files changed, 88 insertions(+), 57 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index dd53b684..25b2d73c 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -32,15 +32,17 @@ define(function(require, exports, module) { "use strict"; var oop = require("./lib/oop"); -var EventEmitter = require("./lib/event_emitter").EventEmitter; +var Range = require('ace/range').Range; var Autocomplete = function(editor) { var self = this; - this.editor = editor; + this.$editor = editor; + + this.originalGoLineUp = editor.commands.commands.golineup.exec; + this.originalGoLineDown = editor.commands.commands.golinedown.exec; + this.originalIndent = editor.commands.commands.indent.exec; + this.originalOnTextInput = editor.onTextInput; - var originalOnTextInput = editor.onTextInput; - var originalSoftTabs = editor.session.getUseSoftTabs(); - // Create the suggest list this.autocompleteContainer = document.createElement('div'); this.autocompleteContainer.className = 'ace_autocomplete'; @@ -50,87 +52,102 @@ var Autocomplete = function(editor) { (function() { - - oop.implement(this, EventEmitter); this.current = function() { - var children = element.childNodes; + var children = this.selection.childNodes; for (var i = 0; i < children.length; i++) { var li = children[i]; - if(li.className == 'ace_autocomplete_selected') { + if (li.className == 'ace_autocomplete_selected') { return li; } }; } this.focusNext = function() { - var curr = current(); + var curr = this.current(); curr.className = ''; var focus = curr.nextSibling || curr.parentNode.firstChild; focus.className = 'ace_autocomplete_selected'; + focus.selected = true; } this.focusPrev = function() { - var curr = current(); + var curr = this.current(); curr.className = ''; var focus = curr.previousSibling || curr.parentNode.lastChild; focus.className = 'ace_autocomplete_selected'; + focus.selected = true; } this.ensureFocus = function() { - if(!current()) { - element.firstChild.className = 'ace_autocomplete_selected'; + if(!this.current()) { + this.selection.firstChild.className = 'ace_autocomplete_selected'; } } this.replace = function() { - var Range = require('ace/range').Range; - var range = new Range(self.row, self.column, self.row, self.column + 1000); - // Firefox does not support innerText property, don't know about IE - // http://blog.coderlab.us/2005/09/22/using-the-innertext-property-with-firefox/ - var selectedValue; - if(document.all){ - selectedValue = current().innerText; - } else{ - selectedValue = current().textContent; - } + var _self = this; - editor.session.replace(range, selectedValue); - // Deactivate asynchrounously, so that in case of ENTER - we don't reactivate immediately. - setTimeout(function() { - deactivate(); - }, 0); - } + var range = new Range(this.row, this.column, this.row, this.column + 1000); + + var selectedValue; + if (document.all) { + selectedValue = this.current().innerText; + } else { + selectedValue = this.current().textContent; + } + + this.$editor.session.replace(range, selectedValue); + // Deactivate asynchrounously, so that in case of ENTER - we don't reactivate immediately. + setTimeout(function() { + _self.deactivate(); + }, 0); + }; this.deactivate = function() { - // Hide list - element.style.display = 'none'; - - // Restore keyboard - editor.session.setUseSoftTabs(originalSoftTabs); - editor.onTextInput = originalOnTextInput; + this.autocompleteContainer.parentNode.removeChild(this.autocompleteContainer); - self.active = false; - } + this.$editor.commands.commands.golineup.exec = this.originalGoLineUp; + this.$editor.commands.commands.golinedown.exec = this.originalGoLineDown; + this.$editor.commands.commands.indent.exec = this.originalIndent; + this.$editor.onTextInput = this.originalOnTextInput; + + this.active = false; + }; // Shows the list and reassigns keys this.activate = function(row, column) { - if(this.active) return; - this.active = true; - this.row = row; - this.column = column; + if (this.active) return; - // Position the list - var coords = this.editor.renderer.textToScreenCoordinates(row, column); - this.autocompleteContainer.style.top = coords.pageY + 18 + 'px'; - this.autocompleteContainer.style.left = coords.pageX + -2 + 'px'; - this.autocompleteContainer.style.display = 'block'; + var _self = this; + + this.active = true; + this.row = row; + this.column = column; + + // Position the list + var coords = this.$editor.renderer.textToScreenCoordinates(row, column); + this.autocompleteContainer.style.top = coords.pageY + 18 + "px"; + this.autocompleteContainer.style.left = coords.pageX + -2 + "px"; + this.autocompleteContainer.style.display = "block"; + + this.$editor.commands.commands.golinedown.exec = function(env, args, request) { _self.focusNext(); }; + this.$editor.commands.commands.golineup.exec = function(env, args, request) { _self.focusPrev(); }; + this.$editor.commands.commands.indent.exec = function(env, args, request) { _self.replace(); }; + + this.$editor.onTextInput = function(text) { + if (text == "\n") { + _self.replace(); + } else { + _self.originalOnTextInput.call(_self.$editor, text); + } + }; }; // Sets the text the suggest should be based on. // afterText indicates the position where the suggest box should start. this.suggest = function(text) { - var options = ["FUNK", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk"];//matches(text); + var options = ["FUNK", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk"]; if (options.length == 0) { return deactivate(); } @@ -139,12 +156,18 @@ var Autocomplete = function(editor) { var opt = this.selection.appendChild(document.createElement("option")); opt.appendChild(document.createTextNode(options[n])); } + this.selection.firstChild.selected = true; - this.selection.size = Math.min(10, options.length); + this.selection.size = Math.min(5, options.length); document.body.appendChild(this.autocompleteContainer); - //ensureFocus(); + this.ensureFocus(); }; + + this.isActive = function() { + return this.active; + }; + }).call(Autocomplete.prototype); exports.Autocomplete = Autocomplete; diff --git a/lib/ace/commands/command_manager.js b/lib/ace/commands/command_manager.js index b3e0fc6d..46a4b604 100644 --- a/lib/ace/commands/command_manager.js +++ b/lib/ace/commands/command_manager.js @@ -8,7 +8,7 @@ var EventEmitter = require("../lib/event_emitter").EventEmitter; /** * @class CommandManager * - * + * **/ /** @@ -16,9 +16,6 @@ var EventEmitter = require("../lib/event_emitter").EventEmitter; * @param {String} platform Identifier for the platform; must be either `'mac'` or `'win'` * @param {Array} commands A list of commands * - * - * - * **/ var CommandManager = function(platform, commands) { @@ -27,7 +24,7 @@ var CommandManager = function(platform, commands) { this.commmandKeyBinding = {}; this.addCommands(commands); - + this.setDefaultHandler("exec", function(e) { return e.command.exec(e.editor, e.args || {}); }); diff --git a/lib/ace/commands/default_commands.js b/lib/ace/commands/default_commands.js index 9d3bc401..bef4c0fc 100644 --- a/lib/ace/commands/default_commands.js +++ b/lib/ace/commands/default_commands.js @@ -307,6 +307,11 @@ exports.commands = [{ exec: function(editor) { editor.jumpToMatching(true); }, multiSelectAction: "forEach", readOnly: true +}, { + name: "hideautocomplete", + bindKey: bindKey("Esc", "Esc"), + exec: function(editor) { editor.$hideautocomplete(); }, + readOnly: true }, // commands disabled in readOnly mode diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 2e46aed0..08380311 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -90,7 +90,7 @@ var Editor = function(renderer, session) { }); this.setSession(session || new EditSession("")); - this.auto = new Autocomplete(this); + this.autocomplete = new Autocomplete(this); config.resetOptions(this); config._emit("editor", this); }; @@ -475,18 +475,24 @@ var Editor = function(renderer, session) { var source = this.session.getValue(); var _self = this; + setTimeout(function() { var cursor = _self.getCursorPosition(); var line = _self.session.getLine(cursor.row); - _self.auto.activate(cursor.row, cursor.column); - _self.auto.suggest(name); + _self.autocomplete.activate(cursor.row, cursor.column); + _self.autocomplete.suggest(name); }, 0); // update cursor because tab characters can influence the cursor position this.$cursorChange(); }; + this.$hideautocomplete = function() { + if (this.autocomplete.isActive()) + this.autocomplete.deactivate(); + }; + this.onTokenizerUpdate = function(e) { var rows = e.data; this.renderer.updateLines(rows.first, rows.last); From a640e4ce0566a145bd2dd26fea28d9b923ccdd33 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 22 Dec 2012 11:08:32 +0400 Subject: [PATCH 03/31] add autocompleter --- demo/kitchen-sink/autocompleter.js | 240 +++++++++++++++++++++++++++++ demo/kitchen-sink/demo.js | 7 +- 2 files changed, 245 insertions(+), 2 deletions(-) create mode 100644 demo/kitchen-sink/autocompleter.js diff --git a/demo/kitchen-sink/autocompleter.js b/demo/kitchen-sink/autocompleter.js new file mode 100644 index 00000000..61fd316e --- /dev/null +++ b/demo/kitchen-sink/autocompleter.js @@ -0,0 +1,240 @@ +define(function(require, exports, module) { +"use strict"; + +var dom = require("ace/lib/dom"); +var layout = require("./layout"); +var HashHandler = require("ace/keyboard/hash_handler").HashHandler; +var EditSession = require("ace/edit_session").EditSession; +var TextMode = require("ace/mode/text").Mode; + +var mode = new TextMode(); +mode.$tokenizer = { + getLineTokens: function(line) { + + } +}; +var Autocompleter = function() { + this.keyboardHandler = new HashHandler(); + this.keyboardHandler.bindKeys(this.commands); + + this.$blurListener = this.blurListener.bind(this); + this.$changeListener = this.changeListener.bind(this); +}; + +(function(){ + this.$init = function(e) { + var el = dom.createElement("div"); + var popup = new layout.singleLineEditor(el); + document.body.appendChild(el); + el.style.width="200px" + el.style.zIndex="20000" + el.style.background="white" + el.style.border="lightgray solid" + el.style.position="fixed" + el.style.display = "none" + popup.renderer.content.style.cursor="default" + + var nop = function(){}; + + popup.focus = nop; + popup.$isFocused = true; + + popup.renderer.$cursorLayer.restartTimer = nop + popup.renderer.$cursorLayer.update = nop + popup.renderer.$cursorLayer.element.style.display = "none"; + + popup.renderer.maxLines = 6 + popup.renderer.$keepTextAreaAtCursor=false + + + popup.setHighlightActiveLine(true) + popup.setSession(new EditSession("")) + + popup.on("mousedown", function(e) { + var pos = e.getDocumentPosition(); + popup.moveCursorToPosition(pos); + popup.selection.clearSelection(); + e.stop(); + }) + + /* popup.session.setMode({ + $ + }) */ + + popup.getRow = function() { + var line = this.getCursorPosition().row; + if (line == 0 && !this.getHighlightActiveLine()) + line = -1; + return line; + }; + popup.setRow = function(line) { + popup.setHighlightActiveLine(line != -1); + popup.gotoLine(line + 1); + }; + + popup.on("click", function(e) { + this.insertMatch(); + }.bind(this)); + + popup.setData = function(list) { + var value = "" + if (list) { + if (typeof list[0] == "string") + value = list.join("\n"); + else + value = list.map(function(x){return x.value}).join("\n"); + } + + this.setValue(value, -1); + }; + + popup.setHighlight = function(re) { + ace.session.highlight(re) + ace.session._emit("changeFrontMarker") + }; + + this.popup = popup; + }; + + this.openPopup = function(editor) { + if (!this.popup) + this.$init(); + + this.popup.setData(this.completions.filtered) + + var renderer = editor.renderer; + var lineHeight = renderer.layerConfig.lineHeight; + var pos = renderer.$cursorLayer.getPixelPosition(null, true) + var rect = editor.container.getBoundingClientRect() + pos.top += rect.top - renderer.layerConfig.offset; + pos.left += rect.left; + pos.left += renderer.$gutterLayer.gutterWidth; + + var el = this.popup.container; + if (pos.top > window.innerHeight / 2 + lineHeight) { + el.style.top = "" + el.style.bottom = window.innerHeight - pos.top + "px"; + } else { + pos.top += lineHeight; + el.style.top = pos.top + "px"; + el.style.bottom = "" + } + + el.style.left = pos.left + "px"; + el.style.display = ""; + }; + + this.attachToEditor = function(editor) { + if (this.editor) + this.detach(); + this.editor = editor; + if (editor.autocompleter != this) { + if (editor.autocompleter) + editor.autocompleter.detach(); + editor.autocompleter = this; + } + editor.keyBinding.addKeyboardHandler(this.keyboardHandler) + editor.on("changeSelection", this.$changeListener) + editor.on("blur", this.$blurListener) + }; + this.detach = function() { + this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler); + this.editor.removeEventListener("changeSelection", this.changeListener); + this.editor.removeEventListener("blur", this.changeListener); + this.popup.container.style.display = "none"; + }; + + this.changeListener = function(e) { + console.log(e) + }; + + this.blurListener = function() { + if (document.activeElement != this.editor.textInput.getElement()) + this.detach(); + }; + + this.goTo = function(where) { + var row = this.popup.getRow(); + var max = this.popup.session.getLength() - 1 + switch(where) { + case "up": row = row < 0 ? max : row-1; break; + case "down": row = row >= max ? -1 : row+1; break; + case "start": row = 0; break; + case "end": row = max; break + } + this.popup.setRow(row) + }; + + this.insertMatch = function(row) { + if (row == undefined) + row = this.popup.getRow(); + var text = this.completions.filtered[row]; + if (text.value) + text = text.value; + this.editor.insert(text); + this.detach(); + }; + + this.commands = { + "up": function(editor) { editor.autocompleter.goTo("up"); }, + "down": function(editor) { editor.autocompleter.goTo("down"); }, + "ctrl-up": function(editor) { editor.autocompleter.goTo("start"); }, + "ctrl-down": function(editor) { editor.autocompleter.goTo("end"); }, + + "esc": function(editor) { editor.autocompleter.detach(); }, + "Return": function(editor) { editor.autocompleter.insertMatch(); }, + "Shift-Return": function(editor) { editor.autocompleter.insertMatch(true); }, + "Tab": function(editor) {}, + "Shift-Tab": function(editor) {}, + }; + + this.complete = function(editor) { + this.attachToEditor(editor); + var data = this.gatherCompletions(editor); + this.completions = new FilteredList(data); + this.completions.setFilter("a") + if (data) { + if (data.length == 1) + this.insertMatch(0); + else + this.openPopup(editor); + } + }; + + this.gatherCompletions = function() { + return ["asdaf", "foo", "bar", "baz"] + } + + +}).call(Autocompleter.prototype); + +Autocompleter.startCommand = { + name: "startAutocomplete", + exec: function(editor) { + if (!editor.autocompleter) + editor.autocompleter = new Autocompleter(); + editor.autocompleter.complete(editor); + }, + bindKey: "Ctrl-Space|Shift-Space|Alt-Space" +} +Autocompleter.addTo = function(editor) { + editor.commands.addCommand(Autocompleter.startCommand); +} + +var FilteredList = function(array, mutateData) { + this.all = array; + this.filtered = array.concat(); + this.filterText = ""; +}; +(function(){ + this.setFilter = function(str) { + + }; + +}).call(FilteredList.prototype); + +exports.Autocompleter = Autocompleter; +exports.FilteredList = FilteredList; + +}); + diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index a2a7fbc8..0d8eb5da 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -196,7 +196,7 @@ commands.addCommand({ exec: function() {alert("Fake Save File");} }); -var keybindings = { +var keybindings = { ace: null, // Null = use "default" keymapping vim: require("ace/keyboard/vim").handler, emacs: "ace/keyboard/emacs", @@ -431,7 +431,7 @@ bindDropdown("split", function(value) { sp.setSplits(1); } else { var newEditor = (sp.getSplits() == 1); - sp.setOrientation(value == "below" ? sp.BELOW : sp.BESIDE); + sp.setOrientation(value == "below" ? sp.BELOW : sp.BESIDE); sp.setSplits(2); if (newEditor) { @@ -559,4 +559,7 @@ ace.commands.bindKey("Tab", function(editor) { editor.execCommand("indent"); }) +var Autocompleter = require("./autocompleter").Autocompleter; +Autocompleter.addTo(env.editor) + }); From 5fa87f83e7dbc475349475aca31d10815cbf4ea9 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 23 Dec 2012 01:14:55 -0800 Subject: [PATCH 04/31] Bring in Harutyun's code --- demo/kitchen-sink/autocompleter.js | 240 ------------------- lib/ace/autocomplete.js | 372 +++++++++++++++++------------ 2 files changed, 219 insertions(+), 393 deletions(-) delete mode 100644 demo/kitchen-sink/autocompleter.js diff --git a/demo/kitchen-sink/autocompleter.js b/demo/kitchen-sink/autocompleter.js deleted file mode 100644 index 61fd316e..00000000 --- a/demo/kitchen-sink/autocompleter.js +++ /dev/null @@ -1,240 +0,0 @@ -define(function(require, exports, module) { -"use strict"; - -var dom = require("ace/lib/dom"); -var layout = require("./layout"); -var HashHandler = require("ace/keyboard/hash_handler").HashHandler; -var EditSession = require("ace/edit_session").EditSession; -var TextMode = require("ace/mode/text").Mode; - -var mode = new TextMode(); -mode.$tokenizer = { - getLineTokens: function(line) { - - } -}; -var Autocompleter = function() { - this.keyboardHandler = new HashHandler(); - this.keyboardHandler.bindKeys(this.commands); - - this.$blurListener = this.blurListener.bind(this); - this.$changeListener = this.changeListener.bind(this); -}; - -(function(){ - this.$init = function(e) { - var el = dom.createElement("div"); - var popup = new layout.singleLineEditor(el); - document.body.appendChild(el); - el.style.width="200px" - el.style.zIndex="20000" - el.style.background="white" - el.style.border="lightgray solid" - el.style.position="fixed" - el.style.display = "none" - popup.renderer.content.style.cursor="default" - - var nop = function(){}; - - popup.focus = nop; - popup.$isFocused = true; - - popup.renderer.$cursorLayer.restartTimer = nop - popup.renderer.$cursorLayer.update = nop - popup.renderer.$cursorLayer.element.style.display = "none"; - - popup.renderer.maxLines = 6 - popup.renderer.$keepTextAreaAtCursor=false - - - popup.setHighlightActiveLine(true) - popup.setSession(new EditSession("")) - - popup.on("mousedown", function(e) { - var pos = e.getDocumentPosition(); - popup.moveCursorToPosition(pos); - popup.selection.clearSelection(); - e.stop(); - }) - - /* popup.session.setMode({ - $ - }) */ - - popup.getRow = function() { - var line = this.getCursorPosition().row; - if (line == 0 && !this.getHighlightActiveLine()) - line = -1; - return line; - }; - popup.setRow = function(line) { - popup.setHighlightActiveLine(line != -1); - popup.gotoLine(line + 1); - }; - - popup.on("click", function(e) { - this.insertMatch(); - }.bind(this)); - - popup.setData = function(list) { - var value = "" - if (list) { - if (typeof list[0] == "string") - value = list.join("\n"); - else - value = list.map(function(x){return x.value}).join("\n"); - } - - this.setValue(value, -1); - }; - - popup.setHighlight = function(re) { - ace.session.highlight(re) - ace.session._emit("changeFrontMarker") - }; - - this.popup = popup; - }; - - this.openPopup = function(editor) { - if (!this.popup) - this.$init(); - - this.popup.setData(this.completions.filtered) - - var renderer = editor.renderer; - var lineHeight = renderer.layerConfig.lineHeight; - var pos = renderer.$cursorLayer.getPixelPosition(null, true) - var rect = editor.container.getBoundingClientRect() - pos.top += rect.top - renderer.layerConfig.offset; - pos.left += rect.left; - pos.left += renderer.$gutterLayer.gutterWidth; - - var el = this.popup.container; - if (pos.top > window.innerHeight / 2 + lineHeight) { - el.style.top = "" - el.style.bottom = window.innerHeight - pos.top + "px"; - } else { - pos.top += lineHeight; - el.style.top = pos.top + "px"; - el.style.bottom = "" - } - - el.style.left = pos.left + "px"; - el.style.display = ""; - }; - - this.attachToEditor = function(editor) { - if (this.editor) - this.detach(); - this.editor = editor; - if (editor.autocompleter != this) { - if (editor.autocompleter) - editor.autocompleter.detach(); - editor.autocompleter = this; - } - editor.keyBinding.addKeyboardHandler(this.keyboardHandler) - editor.on("changeSelection", this.$changeListener) - editor.on("blur", this.$blurListener) - }; - this.detach = function() { - this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler); - this.editor.removeEventListener("changeSelection", this.changeListener); - this.editor.removeEventListener("blur", this.changeListener); - this.popup.container.style.display = "none"; - }; - - this.changeListener = function(e) { - console.log(e) - }; - - this.blurListener = function() { - if (document.activeElement != this.editor.textInput.getElement()) - this.detach(); - }; - - this.goTo = function(where) { - var row = this.popup.getRow(); - var max = this.popup.session.getLength() - 1 - switch(where) { - case "up": row = row < 0 ? max : row-1; break; - case "down": row = row >= max ? -1 : row+1; break; - case "start": row = 0; break; - case "end": row = max; break - } - this.popup.setRow(row) - }; - - this.insertMatch = function(row) { - if (row == undefined) - row = this.popup.getRow(); - var text = this.completions.filtered[row]; - if (text.value) - text = text.value; - this.editor.insert(text); - this.detach(); - }; - - this.commands = { - "up": function(editor) { editor.autocompleter.goTo("up"); }, - "down": function(editor) { editor.autocompleter.goTo("down"); }, - "ctrl-up": function(editor) { editor.autocompleter.goTo("start"); }, - "ctrl-down": function(editor) { editor.autocompleter.goTo("end"); }, - - "esc": function(editor) { editor.autocompleter.detach(); }, - "Return": function(editor) { editor.autocompleter.insertMatch(); }, - "Shift-Return": function(editor) { editor.autocompleter.insertMatch(true); }, - "Tab": function(editor) {}, - "Shift-Tab": function(editor) {}, - }; - - this.complete = function(editor) { - this.attachToEditor(editor); - var data = this.gatherCompletions(editor); - this.completions = new FilteredList(data); - this.completions.setFilter("a") - if (data) { - if (data.length == 1) - this.insertMatch(0); - else - this.openPopup(editor); - } - }; - - this.gatherCompletions = function() { - return ["asdaf", "foo", "bar", "baz"] - } - - -}).call(Autocompleter.prototype); - -Autocompleter.startCommand = { - name: "startAutocomplete", - exec: function(editor) { - if (!editor.autocompleter) - editor.autocompleter = new Autocompleter(); - editor.autocompleter.complete(editor); - }, - bindKey: "Ctrl-Space|Shift-Space|Alt-Space" -} -Autocompleter.addTo = function(editor) { - editor.commands.addCommand(Autocompleter.startCommand); -} - -var FilteredList = function(array, mutateData) { - this.all = array; - this.filtered = array.concat(); - this.filterText = ""; -}; -(function(){ - this.setFilter = function(str) { - - }; - -}).call(FilteredList.prototype); - -exports.Autocompleter = Autocompleter; -exports.FilteredList = FilteredList; - -}); - diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 25b2d73c..61fd316e 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -1,174 +1,240 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Distributed under the BSD license: - * - * Copyright (c) 2012, Ajax.org B.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Ajax.org B.V. nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * ***** END LICENSE BLOCK ***** */ - define(function(require, exports, module) { "use strict"; -var oop = require("./lib/oop"); -var Range = require('ace/range').Range; +var dom = require("ace/lib/dom"); +var layout = require("./layout"); +var HashHandler = require("ace/keyboard/hash_handler").HashHandler; +var EditSession = require("ace/edit_session").EditSession; +var TextMode = require("ace/mode/text").Mode; -var Autocomplete = function(editor) { - var self = this; - this.$editor = editor; +var mode = new TextMode(); +mode.$tokenizer = { + getLineTokens: function(line) { + + } +}; +var Autocompleter = function() { + this.keyboardHandler = new HashHandler(); + this.keyboardHandler.bindKeys(this.commands); - this.originalGoLineUp = editor.commands.commands.golineup.exec; - this.originalGoLineDown = editor.commands.commands.golinedown.exec; - this.originalIndent = editor.commands.commands.indent.exec; - this.originalOnTextInput = editor.onTextInput; - - // Create the suggest list - this.autocompleteContainer = document.createElement('div'); - this.autocompleteContainer.className = 'ace_autocomplete'; - - this.selection = this.autocompleteContainer.appendChild(document.createElement("select")); + this.$blurListener = this.blurListener.bind(this); + this.$changeListener = this.changeListener.bind(this); }; - -(function() { - - this.current = function() { - var children = this.selection.childNodes; - for (var i = 0; i < children.length; i++) { - var li = children[i]; - if (li.className == 'ace_autocomplete_selected') { - return li; - } - }; - } - - this.focusNext = function() { - var curr = this.current(); - curr.className = ''; - var focus = curr.nextSibling || curr.parentNode.firstChild; - focus.className = 'ace_autocomplete_selected'; - focus.selected = true; - } - - this.focusPrev = function() { - var curr = this.current(); - curr.className = ''; - var focus = curr.previousSibling || curr.parentNode.lastChild; - focus.className = 'ace_autocomplete_selected'; - focus.selected = true; - } - - this.ensureFocus = function() { - if(!this.current()) { - this.selection.firstChild.className = 'ace_autocomplete_selected'; - } - } - - this.replace = function() { - var _self = this; - - var range = new Range(this.row, this.column, this.row, this.column + 1000); - - var selectedValue; - if (document.all) { - selectedValue = this.current().innerText; - } else { - selectedValue = this.current().textContent; - } - - this.$editor.session.replace(range, selectedValue); - // Deactivate asynchrounously, so that in case of ENTER - we don't reactivate immediately. - setTimeout(function() { - _self.deactivate(); - }, 0); - }; - - this.deactivate = function() { - this.autocompleteContainer.parentNode.removeChild(this.autocompleteContainer); - - this.$editor.commands.commands.golineup.exec = this.originalGoLineUp; - this.$editor.commands.commands.golinedown.exec = this.originalGoLineDown; - this.$editor.commands.commands.indent.exec = this.originalIndent; - this.$editor.onTextInput = this.originalOnTextInput; +(function(){ + this.$init = function(e) { + var el = dom.createElement("div"); + var popup = new layout.singleLineEditor(el); + document.body.appendChild(el); + el.style.width="200px" + el.style.zIndex="20000" + el.style.background="white" + el.style.border="lightgray solid" + el.style.position="fixed" + el.style.display = "none" + popup.renderer.content.style.cursor="default" - this.active = false; - }; - - // Shows the list and reassigns keys - this.activate = function(row, column) { - if (this.active) return; + var nop = function(){}; + + popup.focus = nop; + popup.$isFocused = true; + + popup.renderer.$cursorLayer.restartTimer = nop + popup.renderer.$cursorLayer.update = nop + popup.renderer.$cursorLayer.element.style.display = "none"; - var _self = this; + popup.renderer.maxLines = 6 + popup.renderer.$keepTextAreaAtCursor=false + - this.active = true; - this.row = row; - this.column = column; + popup.setHighlightActiveLine(true) + popup.setSession(new EditSession("")) - // Position the list - var coords = this.$editor.renderer.textToScreenCoordinates(row, column); - this.autocompleteContainer.style.top = coords.pageY + 18 + "px"; - this.autocompleteContainer.style.left = coords.pageX + -2 + "px"; - this.autocompleteContainer.style.display = "block"; + popup.on("mousedown", function(e) { + var pos = e.getDocumentPosition(); + popup.moveCursorToPosition(pos); + popup.selection.clearSelection(); + e.stop(); + }) + + /* popup.session.setMode({ + $ + }) */ - this.$editor.commands.commands.golinedown.exec = function(env, args, request) { _self.focusNext(); }; - this.$editor.commands.commands.golineup.exec = function(env, args, request) { _self.focusPrev(); }; - this.$editor.commands.commands.indent.exec = function(env, args, request) { _self.replace(); }; - - this.$editor.onTextInput = function(text) { - if (text == "\n") { - _self.replace(); - } else { - _self.originalOnTextInput.call(_self.$editor, text); - } + popup.getRow = function() { + var line = this.getCursorPosition().row; + if (line == 0 && !this.getHighlightActiveLine()) + line = -1; + return line; }; + popup.setRow = function(line) { + popup.setHighlightActiveLine(line != -1); + popup.gotoLine(line + 1); + }; + + popup.on("click", function(e) { + this.insertMatch(); + }.bind(this)); + + popup.setData = function(list) { + var value = "" + if (list) { + if (typeof list[0] == "string") + value = list.join("\n"); + else + value = list.map(function(x){return x.value}).join("\n"); + } + + this.setValue(value, -1); + }; + + popup.setHighlight = function(re) { + ace.session.highlight(re) + ace.session._emit("changeFrontMarker") + }; + + this.popup = popup; + }; + + this.openPopup = function(editor) { + if (!this.popup) + this.$init(); + + this.popup.setData(this.completions.filtered) + + var renderer = editor.renderer; + var lineHeight = renderer.layerConfig.lineHeight; + var pos = renderer.$cursorLayer.getPixelPosition(null, true) + var rect = editor.container.getBoundingClientRect() + pos.top += rect.top - renderer.layerConfig.offset; + pos.left += rect.left; + pos.left += renderer.$gutterLayer.gutterWidth; + + var el = this.popup.container; + if (pos.top > window.innerHeight / 2 + lineHeight) { + el.style.top = "" + el.style.bottom = window.innerHeight - pos.top + "px"; + } else { + pos.top += lineHeight; + el.style.top = pos.top + "px"; + el.style.bottom = "" + } + + el.style.left = pos.left + "px"; + el.style.display = ""; + }; + + this.attachToEditor = function(editor) { + if (this.editor) + this.detach(); + this.editor = editor; + if (editor.autocompleter != this) { + if (editor.autocompleter) + editor.autocompleter.detach(); + editor.autocompleter = this; + } + editor.keyBinding.addKeyboardHandler(this.keyboardHandler) + editor.on("changeSelection", this.$changeListener) + editor.on("blur", this.$blurListener) + }; + this.detach = function() { + this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler); + this.editor.removeEventListener("changeSelection", this.changeListener); + this.editor.removeEventListener("blur", this.changeListener); + this.popup.container.style.display = "none"; + }; + + this.changeListener = function(e) { + console.log(e) }; - // Sets the text the suggest should be based on. - // afterText indicates the position where the suggest box should start. - this.suggest = function(text) { - var options = ["FUNK", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk", "frunk", "blunk"]; - if (options.length == 0) { - return deactivate(); - } - - for (var n = 0; n < options.length; n++) { - var opt = this.selection.appendChild(document.createElement("option")); - opt.appendChild(document.createTextNode(options[n])); - } - - this.selection.firstChild.selected = true; - this.selection.size = Math.min(5, options.length); - - document.body.appendChild(this.autocompleteContainer); - this.ensureFocus(); + this.blurListener = function() { + if (document.activeElement != this.editor.textInput.getElement()) + this.detach(); }; - this.isActive = function() { - return this.active; + this.goTo = function(where) { + var row = this.popup.getRow(); + var max = this.popup.session.getLength() - 1 + switch(where) { + case "up": row = row < 0 ? max : row-1; break; + case "down": row = row >= max ? -1 : row+1; break; + case "start": row = 0; break; + case "end": row = max; break + } + this.popup.setRow(row) + }; + + this.insertMatch = function(row) { + if (row == undefined) + row = this.popup.getRow(); + var text = this.completions.filtered[row]; + if (text.value) + text = text.value; + this.editor.insert(text); + this.detach(); + }; + + this.commands = { + "up": function(editor) { editor.autocompleter.goTo("up"); }, + "down": function(editor) { editor.autocompleter.goTo("down"); }, + "ctrl-up": function(editor) { editor.autocompleter.goTo("start"); }, + "ctrl-down": function(editor) { editor.autocompleter.goTo("end"); }, + + "esc": function(editor) { editor.autocompleter.detach(); }, + "Return": function(editor) { editor.autocompleter.insertMatch(); }, + "Shift-Return": function(editor) { editor.autocompleter.insertMatch(true); }, + "Tab": function(editor) {}, + "Shift-Tab": function(editor) {}, + }; + + this.complete = function(editor) { + this.attachToEditor(editor); + var data = this.gatherCompletions(editor); + this.completions = new FilteredList(data); + this.completions.setFilter("a") + if (data) { + if (data.length == 1) + this.insertMatch(0); + else + this.openPopup(editor); + } }; -}).call(Autocomplete.prototype); + this.gatherCompletions = function() { + return ["asdaf", "foo", "bar", "baz"] + } + + +}).call(Autocompleter.prototype); + +Autocompleter.startCommand = { + name: "startAutocomplete", + exec: function(editor) { + if (!editor.autocompleter) + editor.autocompleter = new Autocompleter(); + editor.autocompleter.complete(editor); + }, + bindKey: "Ctrl-Space|Shift-Space|Alt-Space" +} +Autocompleter.addTo = function(editor) { + editor.commands.addCommand(Autocompleter.startCommand); +} + +var FilteredList = function(array, mutateData) { + this.all = array; + this.filtered = array.concat(); + this.filterText = ""; +}; +(function(){ + this.setFilter = function(str) { + + }; + +}).call(FilteredList.prototype); + +exports.Autocompleter = Autocompleter; +exports.FilteredList = FilteredList; -exports.Autocomplete = Autocomplete; }); + From b1322002ab28692eb649175d01f4521d5303a06d Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 23 Dec 2012 01:15:44 -0800 Subject: [PATCH 05/31] Merge updates --- lib/ace/autocomplete.js | 196 +++++++++++++++++++++++++++++++++------- 1 file changed, 163 insertions(+), 33 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 61fd316e..47b38d7a 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -1,10 +1,42 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + define(function(require, exports, module) { "use strict"; -var dom = require("ace/lib/dom"); -var layout = require("./layout"); -var HashHandler = require("ace/keyboard/hash_handler").HashHandler; var EditSession = require("ace/edit_session").EditSession; +var Renderer = require("ace/virtual_renderer").VirtualRenderer; +var UndoManager = require("ace/undomanager").UndoManager; + +var dom = require("ace/lib/dom"); +var HashHandler = require("ace/keyboard/hash_handler").HashHandler; var TextMode = require("ace/mode/text").Mode; var mode = new TextMode(); @@ -13,7 +45,7 @@ mode.$tokenizer = { } }; -var Autocompleter = function() { +var Autocomplete = function() { this.keyboardHandler = new HashHandler(); this.keyboardHandler.bindKeys(this.commands); @@ -21,10 +53,12 @@ var Autocompleter = function() { this.$changeListener = this.changeListener.bind(this); }; -(function(){ + +(function() { + this.$init = function(e) { var el = dom.createElement("div"); - var popup = new layout.singleLineEditor(el); + var popup = new this.$singleLineEditor(el); document.body.appendChild(el); el.style.width="200px" el.style.zIndex="20000" @@ -128,15 +162,16 @@ var Autocompleter = function() { if (this.editor) this.detach(); this.editor = editor; - if (editor.autocompleter != this) { - if (editor.autocompleter) - editor.autocompleter.detach(); - editor.autocompleter = this; + if (editor.Autocomplete != this) { + if (editor.Autocomplete) + editor.Autocomplete.detach(); + editor.Autocomplete = this; } editor.keyBinding.addKeyboardHandler(this.keyboardHandler) editor.on("changeSelection", this.$changeListener) editor.on("blur", this.$blurListener) }; + this.detach = function() { this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler); this.editor.removeEventListener("changeSelection", this.changeListener); @@ -155,14 +190,20 @@ var Autocompleter = function() { this.goTo = function(where) { var row = this.popup.getRow(); - var max = this.popup.session.getLength() - 1 + var max = this.popup.session.getLength() - 1; + + var choices = this.popup.container.getElementsByClassName("ace_text-layer")[0].childNodes; + dom.removeCssClass(choices[row], "autocomplete_selected"); + switch(where) { case "up": row = row < 0 ? max : row-1; break; case "down": row = row >= max ? -1 : row+1; break; case "start": row = 0; break; case "end": row = max; break } - this.popup.setRow(row) + + dom.addCssClass(choices[row], "autocomplete_selected"); + this.popup.setRow(row); }; this.insertMatch = function(row) { @@ -176,15 +217,15 @@ var Autocompleter = function() { }; this.commands = { - "up": function(editor) { editor.autocompleter.goTo("up"); }, - "down": function(editor) { editor.autocompleter.goTo("down"); }, - "ctrl-up": function(editor) { editor.autocompleter.goTo("start"); }, - "ctrl-down": function(editor) { editor.autocompleter.goTo("end"); }, + "up": function(editor) { editor.Autocomplete.goTo("up"); }, + "down": function(editor) { editor.Autocomplete.goTo("down"); }, + "ctrl-up": function(editor) { editor.Autocomplete.goTo("start"); }, + "ctrl-down": function(editor) { editor.Autocomplete.goTo("end"); }, - "esc": function(editor) { editor.autocompleter.detach(); }, - "Return": function(editor) { editor.autocompleter.insertMatch(); }, - "Shift-Return": function(editor) { editor.autocompleter.insertMatch(true); }, - "Tab": function(editor) {}, + "esc": function(editor) { editor.Autocomplete.detach(); }, + "Return": function(editor) { editor.Autocomplete.insertMatch(); }, + "Shift-Return": function(editor) { editor.Autocomplete.insertMatch(true); }, + "Tab": function(editor) { editor.Autocomplete.insertMatch(); }, "Shift-Tab": function(editor) {}, }; @@ -202,23 +243,113 @@ var Autocompleter = function() { }; this.gatherCompletions = function() { - return ["asdaf", "foo", "bar", "baz"] - } + return ["asdaf", "foo", "bar", "baz"]; + }; - -}).call(Autocompleter.prototype); + this.$singleLineEditor = function(el) { + var renderer = new Renderer(el); + el.style.overflow = "hidden"; + renderer.scrollBar.element.style.top = "0"; + renderer.scrollBar.element.style.display = "none"; + renderer.scrollBar.orginalWidth = renderer.scrollBar.width; + renderer.scrollBar.width = 0; + renderer.content.style.height = "auto"; -Autocompleter.startCommand = { + renderer.screenToTextCoordinates = function(x, y) { + var pos = this.pixelToScreenCoordinates(x, y); + return this.session.screenToDocumentPosition( + Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)), + Math.max(pos.column, 0) + ); + }; + + renderer.maxLines = 4; + renderer.$computeLayerConfigWithScroll = renderer.$computeLayerConfig; + renderer.$computeLayerConfig = function() { + var config = this.layerConfig; + var height = this.session.getScreenLength() * this.lineHeight; + if (config.height != height) { + var vScroll = height > this.maxLines * this.lineHeight; + + if (vScroll != this.$vScroll) { + if (vScroll) { + this.scrollBar.element.style.display = ""; + this.scrollBar.width = this.scrollBar.orginalWidth; + this.container.style.height = config.height + "px"; + height = config.height; + this.scrollTop = height - this.maxLines * this.lineHeight; + } else { + this.scrollBar.element.style.display = "none"; + this.scrollBar.width = 0; + } + + this.onResize(); + this.$vScroll = vScroll; + } + + if (this.$vScroll) + return renderer.$computeLayerConfigWithScroll(); + + this.container.style.height = height + "px"; + this.scroller.style.height = height + "px"; + this.content.style.height = height + "px"; + this._emit("resize"); + } + + var longestLine = this.$getLongestLine(); + var firstRow = 0; + var lastRow = this.session.getLength(); + + this.scrollTop = 0; + config.width = longestLine; + config.padding = this.$padding; + config.firstRow = 0; + config.firstRowScreen = 0; + config.lastRow = lastRow; + config.lineHeight = this.lineHeight; + config.characterWidth = this.characterWidth; + config.minHeight = height; + config.maxHeight = height; + config.offset = 0; + config.height = height; + + this.$gutterLayer.element.style.marginTop = 0 + "px"; + this.content.style.marginTop = 0 + "px"; + this.content.style.width = longestLine + 2 * this.$padding + "px"; + }; + renderer.isScrollableBy=function(){return false}; + + renderer.setStyle("ace_one-line"); + + var Editor = require("ace/editor").Editor; + var editor = new Editor(renderer); + + //var MultiSelect = require("ace/multi_select").MultiSelect; + //new MultiSelect(editor); + editor.session.setUndoManager(new UndoManager()); + + editor.setHighlightActiveLine(false); + editor.setShowPrintMargin(false); + editor.renderer.setShowGutter(false); + editor.renderer.setHighlightGutterLine(false); + + editor.$mouseHandler.$focusWaitTimout = 0; + + return editor; + }; +}).call(Autocomplete.prototype); + +Autocomplete.startCommand = { name: "startAutocomplete", exec: function(editor) { - if (!editor.autocompleter) - editor.autocompleter = new Autocompleter(); - editor.autocompleter.complete(editor); + if (!editor.Autocomplete) + editor.Autocomplete = new Autocomplete(); + editor.Autocomplete.complete(editor); }, bindKey: "Ctrl-Space|Shift-Space|Alt-Space" } -Autocompleter.addTo = function(editor) { - editor.commands.addCommand(Autocompleter.startCommand); +Autocomplete.addTo = function(editor) { + editor.commands.addCommand(Autocomplete.startCommand); } var FilteredList = function(array, mutateData) { @@ -233,8 +364,7 @@ var FilteredList = function(array, mutateData) { }).call(FilteredList.prototype); -exports.Autocompleter = Autocompleter; +exports.Autocomplete = Autocomplete; exports.FilteredList = FilteredList; -}); - +}); \ No newline at end of file From dcdcd815840f1057b146eaab6f0b415dd41dff2a Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 23 Dec 2012 01:18:40 -0800 Subject: [PATCH 06/31] Fix it up --- lib/ace/autocomplete.js | 8 +++++--- lib/ace/editor.js | 18 +----------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 47b38d7a..8584b7a4 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -193,7 +193,8 @@ var Autocomplete = function() { var max = this.popup.session.getLength() - 1; var choices = this.popup.container.getElementsByClassName("ace_text-layer")[0].childNodes; - dom.removeCssClass(choices[row], "autocomplete_selected"); + if (choices[row]) + dom.removeCssClass(choices[row], "autocomplete_selected"); switch(where) { case "up": row = row < 0 ? max : row-1; break; @@ -202,7 +203,8 @@ var Autocomplete = function() { case "end": row = max; break } - dom.addCssClass(choices[row], "autocomplete_selected"); + if (choices[row]) + dom.addCssClass(choices[row], "autocomplete_selected"); this.popup.setRow(row); }; @@ -326,7 +328,7 @@ var Autocomplete = function() { //var MultiSelect = require("ace/multi_select").MultiSelect; //new MultiSelect(editor); - editor.session.setUndoManager(new UndoManager()); + //editor.session.setUndoManager(new UndoManager()); editor.setHighlightActiveLine(false); editor.setShowPrintMargin(false); diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 08380311..92d218f6 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -90,7 +90,7 @@ var Editor = function(renderer, session) { }); this.setSession(session || new EditSession("")); - this.autocomplete = new Autocomplete(this); + Autocomplete.addTo(this); config.resetOptions(this); config._emit("editor", this); }; @@ -473,26 +473,10 @@ var Editor = function(renderer, session) { this._emit("change", e); - var source = this.session.getValue(); - var _self = this; - - setTimeout(function() { - var cursor = _self.getCursorPosition(); - var line = _self.session.getLine(cursor.row); - - _self.autocomplete.activate(cursor.row, cursor.column); - _self.autocomplete.suggest(name); - }, 0); - // update cursor because tab characters can influence the cursor position this.$cursorChange(); }; - this.$hideautocomplete = function() { - if (this.autocomplete.isActive()) - this.autocomplete.deactivate(); - }; - this.onTokenizerUpdate = function(e) { var rows = e.data; this.renderer.updateLines(rows.first, rows.last); From e43bee07e29ebb9fa10d2f7e30ec14b2fcf22cd6 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 23 Dec 2012 01:20:50 -0800 Subject: [PATCH 07/31] Get rid of my junk --- lib/ace/autocomplete.js | 2 +- lib/ace/commands/default_commands.js | 5 ----- lib/ace/css/editor.css | 9 --------- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 8584b7a4..4c751d86 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -180,7 +180,7 @@ var Autocomplete = function() { }; this.changeListener = function(e) { - console.log(e) + //console.log(e) }; this.blurListener = function() { diff --git a/lib/ace/commands/default_commands.js b/lib/ace/commands/default_commands.js index bef4c0fc..9d3bc401 100644 --- a/lib/ace/commands/default_commands.js +++ b/lib/ace/commands/default_commands.js @@ -307,11 +307,6 @@ exports.commands = [{ exec: function(editor) { editor.jumpToMatching(true); }, multiSelectAction: "forEach", readOnly: true -}, { - name: "hideautocomplete", - bindKey: bindKey("Esc", "Esc"), - exec: function(editor) { editor.$hideautocomplete(); }, - readOnly: true }, // commands disabled in readOnly mode diff --git a/lib/ace/css/editor.css b/lib/ace/css/editor.css index 0aeff4dc..4f32b905 100644 --- a/lib/ace/css/editor.css +++ b/lib/ace/css/editor.css @@ -386,12 +386,3 @@ .ace_italic { font-style: italic; } - -.ace_autocomplete { - position: fixed; - z-index: 9999; -} - -.ace_autocomplete li { - color: #000000; -} From ef19fdbcb5af2e8b73fcefe243ba353fcaa00ee7 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Mon, 24 Dec 2012 00:21:19 -0800 Subject: [PATCH 08/31] First pass at Haurtyun UI + C9 doc parsing --- lib/ace/autocomplete.js | 75 +++++---- lib/ace/autocomplete/autocomplete_worker.js | 128 ++++++++++++++ lib/ace/autocomplete/complete_util.js | 85 ++++++++++ lib/ace/autocomplete/syntax_detector.js | 176 ++++++++++++++++++++ lib/ace/autocomplete/text_completer.js | 74 ++++++++ lib/ace/worker/mirror.js | 6 +- lib/ace/worker/worker_client.js | 6 +- 7 files changed, 511 insertions(+), 39 deletions(-) create mode 100644 lib/ace/autocomplete/autocomplete_worker.js create mode 100644 lib/ace/autocomplete/complete_util.js create mode 100644 lib/ace/autocomplete/syntax_detector.js create mode 100644 lib/ace/autocomplete/text_completer.js diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 4c751d86..df71dcc2 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -38,6 +38,7 @@ var UndoManager = require("ace/undomanager").UndoManager; var dom = require("ace/lib/dom"); var HashHandler = require("ace/keyboard/hash_handler").HashHandler; var TextMode = require("ace/mode/text").Mode; +var WorkerClient = require("./worker/worker_client").WorkerClient; var mode = new TextMode(); mode.$tokenizer = { @@ -45,6 +46,8 @@ mode.$tokenizer = { } }; +var worker = new WorkerClient(["ace"], "ace/autocomplete/autocomplete_worker", "AutocompleteWorker"); + var Autocomplete = function() { this.keyboardHandler = new HashHandler(); this.keyboardHandler.bindKeys(this.commands); @@ -68,28 +71,28 @@ var Autocomplete = function() { el.style.display = "none" popup.renderer.content.style.cursor="default" - var nop = function(){}; + var noop = function(){}; - popup.focus = nop; + popup.focus = noop; popup.$isFocused = true; - popup.renderer.$cursorLayer.restartTimer = nop - popup.renderer.$cursorLayer.update = nop + popup.renderer.$cursorLayer.restartTimer = noop; + popup.renderer.$cursorLayer.update = noop; popup.renderer.$cursorLayer.element.style.display = "none"; popup.renderer.maxLines = 6 popup.renderer.$keepTextAreaAtCursor=false - popup.setHighlightActiveLine(true) - popup.setSession(new EditSession("")) + popup.setHighlightActiveLine(true); + popup.setSession(new EditSession("")); popup.on("mousedown", function(e) { var pos = e.getDocumentPosition(); popup.moveCursorToPosition(pos); popup.selection.clearSelection(); e.stop(); - }) + }); /* popup.session.setMode({ $ @@ -158,20 +161,6 @@ var Autocomplete = function() { el.style.display = ""; }; - this.attachToEditor = function(editor) { - if (this.editor) - this.detach(); - this.editor = editor; - if (editor.Autocomplete != this) { - if (editor.Autocomplete) - editor.Autocomplete.detach(); - editor.Autocomplete = this; - } - editor.keyBinding.addKeyboardHandler(this.keyboardHandler) - editor.on("changeSelection", this.$changeListener) - editor.on("blur", this.$blurListener) - }; - this.detach = function() { this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler); this.editor.removeEventListener("changeSelection", this.changeListener); @@ -232,20 +221,38 @@ var Autocomplete = function() { }; this.complete = function(editor) { - this.attachToEditor(editor); - var data = this.gatherCompletions(editor); - this.completions = new FilteredList(data); - this.completions.setFilter("a") - if (data) { - if (data.length == 1) - this.insertMatch(0); - else - this.openPopup(editor); + if (this.editor) + this.detach(); + + var _self = this; + this.editor = editor; + if (editor.Autocomplete != this) { + if (editor.Autocomplete) + editor.Autocomplete.detach(); + editor.Autocomplete = this; } - }; - - this.gatherCompletions = function() { - return ["asdaf", "foo", "bar", "baz"]; + + editor.keyBinding.addKeyboardHandler(this.keyboardHandler); + editor.on("changeSelection", this.$changeListener); + editor.on("blur", this.$blurListener); + + worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition()}); + + worker.on("complete", function(data) { + _self.completions = new FilteredList(data.data.matches); + _self.completions.setFilter("a"); + + if (data) { + if (data.length == 1) + _self.insertMatch(0); + else + _self.openPopup(editor); + } + }); + + worker.on("terminate", function() { + console.log("term"); + }); }; this.$singleLineEditor = function(el) { diff --git a/lib/ace/autocomplete/autocomplete_worker.js b/lib/ace/autocomplete/autocomplete_worker.js new file mode 100644 index 00000000..2656b086 --- /dev/null +++ b/lib/ace/autocomplete/autocomplete_worker.js @@ -0,0 +1,128 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var Mirror = require("../worker/mirror").Mirror; + +var SyntaxDetector = require("./syntax_detector"); +var completer = require("./text_completer"); + +var AutocompleteWorker = exports.AutocompleteWorker = function(sender) { + Mirror.call(this, sender); +}; + +oop.inherits(AutocompleteWorker, Mirror); + +(function() { + // For code completion + function removeDuplicateMatches(matches) { + // First sort + matches.sort(function(a, b) { + if (a.name < b.name) + return 1; + else if (a.name > b.name) + return -1; + else + return 0; + }); + for (var i = 0; i < matches.length - 1; i++) { + var a = matches[i]; + var b = matches[i + 1]; + if (a.name === b.name) { + // Duplicate! + if (a.priority < b.priority) + matches.splice(i, 1); + else if (a.priority > b.priority) + matches.splice(i+1, 1); + else if (a.score < b.score) + matches.splice(i, 1); + else if (a.score > b.score) + matches.splice(i+1, 1); + else + matches.splice(i, 1); + i--; + } + } + }; + + this.onUpdate = function() { + var _self = this; + + var doc = this.doc.getValue(); + var pos = this.data.cursor; + var part = SyntaxDetector.getContextSyntaxPart(this.doc, this.data.cursor, "javascript"); + var language = part.language; + + var currentPos = { line: pos.row, col: pos.column }; + var currentNode = null; + var matches = [], ast = null; + + completer.complete(_self.doc, ast, this.data.cursor, currentNode, function(completions) { + if (completions) + matches = matches.concat(completions); + removeDuplicateMatches(matches); + // Sort by priority, score + matches.sort(function(a, b) { + if (a.priority < b.priority) + return 1; + else if (a.priority > b.priority) + return -1; + else if (a.score < b.score) + return 1; + else if (a.score > b.score) + return -1; + else if (a.id && a.id === b.id) { + if (a.isFunction) + return -1; + else if (b.isFunction) + return 1; + } + if (a.name < b.name) + return -1; + else if(a.name > b.name) + return 1; + else + return 0; + }); + _self.sender.emit("complete", { + pos: pos, + matches: matches, + line: _self.doc.getLine(pos.row) + }); + return; + }); + }; + +}).call(AutocompleteWorker.prototype); + +}); \ No newline at end of file diff --git a/lib/ace/autocomplete/complete_util.js b/lib/ace/autocomplete/complete_util.js new file mode 100644 index 00000000..4b7e6a16 --- /dev/null +++ b/lib/ace/autocomplete/complete_util.js @@ -0,0 +1,85 @@ +define(function(require, exports, module) { + +var ID_REGEX = /[a-zA-Z_0-9\$]/; + +function retrievePrecedingIdentifier(text, pos, regex) { + regex = regex || ID_REGEX; + var buf = []; + for (var i = pos-1; i >= 0; i--) { + if (regex.test(text[i])) + buf.push(text[i]); + else + break; + } + return buf.reverse().join(""); +} + +function retrieveFollowingIdentifier(text, pos, regex) { + regex = regex || ID_REGEX; + var buf = []; + for (var i = pos; i < text.length; i++) { + if (regex.test(text[i])) + buf.push(text[i]); + else + break; + } + return buf; +} + +function prefixBinarySearch(items, prefix) { + var startIndex = 0; + var stopIndex = items.length - 1; + var middle = Math.floor((stopIndex + startIndex) / 2); + + while (stopIndex > startIndex && middle >= 0 && items[middle].indexOf(prefix) !== 0) { + if (prefix < items[middle]) { + stopIndex = middle - 1; + } + else if (prefix > items[middle]) { + startIndex = middle + 1; + } + middle = Math.floor((stopIndex + stopIndex) / 2); + } + + // Look back to make sure we haven't skipped any + while (middle > 0 && items[middle-1].indexOf(prefix) === 0) + middle--; + return middle >= 0 ? middle : 0; // ensure we're not returning a negative index +} + +function findCompletions(prefix, allIdentifiers) { + allIdentifiers.sort(); + var startIdx = prefixBinarySearch(allIdentifiers, prefix); + var matches = []; + for (var i = startIdx; i < allIdentifiers.length && allIdentifiers[i].indexOf(prefix) === 0; i++) + matches.push(allIdentifiers[i]); + return matches; +} + +function fetchText(staticPrefix, path) { + var xhr = new XMLHttpRequest(); + xhr.open('GET', staticPrefix + "/" + path, false); + try { + xhr.send(); + } + // Likely we got a cross-script error (equivalent with a 404 in our cloud setup) + catch(e) { + return false; + } + if (xhr.status === 200) + return xhr.responseText; + else + return false; +} + +/** @deprecated Use retrievePrecedingIdentifier */ +exports.retrievePreceedingIdentifier = function() { + console.error("Deprecated: 'retrievePreceedingIdentifier' - use 'retrievePrecedingIdentifier' instead"); + return retrievePrecedingIdentifier.apply(null, arguments); +}; +exports.retrievePrecedingIdentifier = retrievePrecedingIdentifier; +exports.retrieveFollowingIdentifier = retrieveFollowingIdentifier; +exports.findCompletions = findCompletions; +exports.fetchText = fetchText; + +}); diff --git a/lib/ace/autocomplete/syntax_detector.js b/lib/ace/autocomplete/syntax_detector.js new file mode 100644 index 00000000..40cfd3f1 --- /dev/null +++ b/lib/ace/autocomplete/syntax_detector.js @@ -0,0 +1,176 @@ +/** + * Cloud9 Language Foundation + * + * @copyright 2011, Ajax.org B.V. + * @license GPLv3 + */ +define(function(require, exports, module) { + +var mixedLanguages = { + php: { + "default": "html", + "php-start": /<\?(?:php|\=)?/, + "php-end": /\?>/, + "css-start": /]*>/, + "css-end": /<\/style>/, + "javascript-start": /\/])*>/, + "javascript-end": /<\/script>/ + }, + html: { + "css-start": /]*>/, + "css-end": /<\/style>/, + "javascript-start": /\/])*>/, + "javascript-end": /<\/script>/ + } +}; + +/* Now: + * - One level syntax nesting supported + * Future: (if worth it) + * - Have a stack to repesent it + * - Maintain a syntax tree for an opened file + */ +function getSyntaxRegions(doc, originalSyntax) { + if (! mixedLanguages[originalSyntax]) + return [{ + syntax: originalSyntax, + sl: 0, + sc: 0, + el: doc.getLength()-1, + ec: doc.getLine(doc.getLength()-1).length + }]; + + var lines = doc.getAllLines(); + var type = mixedLanguages[originalSyntax]; + var defaultSyntax = type["default"] || originalSyntax; + var starters = Object.keys(type).filter(function (m) { + return m.indexOf("-start") === m.length - 6; + }); + var syntax = defaultSyntax; + var regions = [{syntax: syntax, sl: 0, sc: 0}]; + var starter, endLang; + var tempS, tempM; + var i, m, cut, inLine = 0; + + for (var row = 0; row < lines.length; row++) { + var line = lines[row]; + m = null; + if (endLang) { + m = endLang.exec(line); + if (m) { + endLang = null; + syntax = defaultSyntax; + regions[regions.length-1].el = row; + regions[regions.length-1].ec = m.index + inLine; + regions.push({ + syntax: syntax, + sl: row, + sc: m.index + inLine + }); + cut = m.index + m[0].length; + lines[row] = line.substring(cut); + inLine += cut; + row--; // continue processing of the line + } + else { + inLine = 0; + } + } + else { + for (i = 0; i < starters.length; i++) { + tempS = starters[i]; + tempM = type[tempS].exec(line); + if (tempM && (!m || m.index > tempM.index)) { + m = tempM; + starter = tempS; + } + } + if (m) { + syntax = starter.replace("-start", ""); + endLang = type[syntax+"-end"]; + regions[regions.length-1].el = row; + regions[regions.length-1].ec = inLine + m.index + m[0].length; + regions.push({ + syntax: syntax, + sl: row, + sc: inLine + m.index + m[0].length + }); + cut = m.index + m[0].length; + lines[row] = line.substring(m.index + m[0].length); + row--; // continue processing of the line + inLine += cut; + } + else { + inLine = 0; + } + } + } + regions[regions.length-1].el = lines.length; + regions[regions.length-1].ec = lines[lines.length-1].length; + return regions; +} + +function getContextSyntaxPart(doc, pos, originalSyntax) { + if (! mixedLanguages[originalSyntax]) + return { + language: originalSyntax, + value: doc.getValue(), + region: getSyntaxRegions(doc, originalSyntax)[0], + index: 0 + }; + var regions = getSyntaxRegions(doc, originalSyntax); + for (var i = 0; i < regions.length; i++) { + var region = regions[i]; + if ((pos.row > region.sl && pos.row < region.el) || + (pos.row === region.sl && pos.column >= region.sc) || + (pos.row === region.el && pos.column <= region.ec)) + return regionToCodePart(doc, region, i); + } + return null; // should never happen +} + +function getContextSyntax(doc, pos, originalSyntax) { + var part = getContextSyntaxPart(doc, pos, originalSyntax); + return part && part.language; // should never happen +} + +function regionToCodePart (doc, region, index) { + var lines = doc.getLines(region.sl, region.el); + return { + value: region.sl === region.el ? lines[0].substring(region.sc, region.ec) : + [lines[0].substring(region.sc)].concat(lines.slice(1, lines.length-1)).concat([lines[lines.length-1].substring(0, region.ec)]).join(doc.getNewLineCharacter()), + language: region.syntax, + region: region, + index: index + }; +} + +function getCodeParts (doc, originalSyntax) { + var regions = getSyntaxRegions(doc, originalSyntax); + return regions.map(function (region, i) { + return regionToCodePart(doc, region, i); + }); +} + +function posToRegion (region, pos) { + return { + row: pos.row - region.sl, + column: pos.column + }; +} + +function regionToPos (region, pos) { + return { + row: pos.row + region.sl, + column: pos.column + }; +} + +exports.getContextSyntax = getContextSyntax; +exports.getContextSyntaxPart = getContextSyntaxPart; +exports.getSyntaxRegions = getSyntaxRegions; +exports.getCodeParts = getCodeParts; +exports.posToRegion = posToRegion; +exports.regionToPos = regionToPos; + +}); diff --git a/lib/ace/autocomplete/text_completer.js b/lib/ace/autocomplete/text_completer.js new file mode 100644 index 00000000..d98ec95f --- /dev/null +++ b/lib/ace/autocomplete/text_completer.js @@ -0,0 +1,74 @@ +define(function(require, exports, module) { + var completeUtil = require("./complete_util"); + var SPLIT_REGEX = /[^a-zA-Z_0-9\$]+/; + + var completer = module.exports; + + this.handlesLanguage = function(language) { + return true; + }; + + // For the current document, gives scores to identifiers not on frequency, but on distance from the current prefix + function wordDistanceAnalyzer(doc, pos, prefix) { + var text = doc.getValue().trim(); + + // Determine cursor's word index + var textBefore = doc.getLines(0, pos.row-1).join("\n") + "\n"; + var currentLine = doc.getLine(pos.row); + textBefore += currentLine.substr(0, pos.column); + var prefixPosition = textBefore.trim().split(SPLIT_REGEX).length - 1; + + // Split entire document into words + var identifiers = text.split(SPLIT_REGEX); + var identDict = {}; + + // Find prefix to find other identifiers close it + for (var i = 0; i < identifiers.length; i++) { + if (i === prefixPosition) + continue; + var ident = identifiers[i]; + if (ident.length === 0) + continue; + var distance = Math.max(prefixPosition, i) - Math.min(prefixPosition, i); + // Score substracted from 100000 to force descending ordering + if (Object.prototype.hasOwnProperty.call(identDict, ident)) + identDict[ident] = Math.max(1000000-distance, identDict[ident]); + else + identDict[ident] = 1000000-distance; + + } + return identDict; + } + + function analyze(doc, pos) { + var line = doc.getLine(pos.row); + var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column); + + var analysisCache = wordDistanceAnalyzer(doc, pos, identifier); + return analysisCache; + } + + completer.complete = function(doc, fullAst, pos, currentNode, callback) { + var identDict = analyze(doc, pos); + var line = doc.getLine(pos.row); + var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column); + + var allIdentifiers = []; + for (var ident in identDict) { + allIdentifiers.push(ident); + } + var matches = completeUtil.findCompletions(identifier, allIdentifiers); + + callback(matches); + /*callback(matches.map(function(m) { + return { + name : m, + replaceText : m, + icon : null, + score : identDict[m], + meta : "", + priority : 1 + }; + }));*/ + }; +}); \ No newline at end of file diff --git a/lib/ace/worker/mirror.js b/lib/ace/worker/mirror.js index c521f8fd..47412452 100644 --- a/lib/ace/worker/mirror.js +++ b/lib/ace/worker/mirror.js @@ -7,7 +7,8 @@ var lang = require("../lib/lang"); var Mirror = exports.Mirror = function(sender) { this.sender = sender; var doc = this.doc = new Document(""); - + this.data = {}; + var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this)); var _self = this; @@ -25,8 +26,9 @@ var Mirror = exports.Mirror = function(sender) { this.$timeout = timeout; }; - this.setValue = function(value) { + this.setValue = function(value, data) { this.doc.setValue(value); + this.data = data; this.deferredUpdate.schedule(this.$timeout); }; diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index 5a682fe5..f48599c4 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -144,12 +144,12 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) { catch(ex) {} }; - this.attachToDocument = function(doc) { - if(this.$doc) + this.attachToDocument = function(doc, data) { + if (this.$doc) this.terminate(); this.$doc = doc; - this.call("setValue", [doc.getValue()]); + this.call("setValue", [doc.getValue(), data]); doc.on("change", this.changeListener); }; From 818dba5dbab8daf39415cf267138ffa2075ed99a Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Mon, 24 Dec 2012 02:07:33 -0800 Subject: [PATCH 09/31] Some added UX behaviors --- lib/ace/autocomplete.js | 30 +++++++++--------- lib/ace/autocomplete/autocomplete_worker.js | 35 ++++++++++----------- lib/ace/autocomplete/text_completer.js | 5 ++- lib/ace/worker/mirror.js | 12 +++++-- lib/ace/worker/worker_client.js | 4 +-- 5 files changed, 46 insertions(+), 40 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index df71dcc2..33c41f93 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -38,7 +38,9 @@ var UndoManager = require("ace/undomanager").UndoManager; var dom = require("ace/lib/dom"); var HashHandler = require("ace/keyboard/hash_handler").HashHandler; var TextMode = require("ace/mode/text").Mode; + var WorkerClient = require("./worker/worker_client").WorkerClient; +var worker = new WorkerClient(["ace"], "ace/autocomplete/autocomplete_worker", "AutocompleteWorker"); var mode = new TextMode(); mode.$tokenizer = { @@ -46,7 +48,6 @@ mode.$tokenizer = { } }; -var worker = new WorkerClient(["ace"], "ace/autocomplete/autocomplete_worker", "AutocompleteWorker"); var Autocomplete = function() { this.keyboardHandler = new HashHandler(); @@ -82,7 +83,6 @@ var Autocomplete = function() { popup.renderer.maxLines = 6 popup.renderer.$keepTextAreaAtCursor=false - popup.setHighlightActiveLine(true); popup.setSession(new EditSession("")); @@ -104,6 +104,7 @@ var Autocomplete = function() { line = -1; return line; }; + popup.setRow = function(line) { popup.setHighlightActiveLine(line != -1); popup.gotoLine(line + 1); @@ -165,7 +166,9 @@ var Autocomplete = function() { this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler); this.editor.removeEventListener("changeSelection", this.changeListener); this.editor.removeEventListener("blur", this.changeListener); - this.popup.container.style.display = "none"; + + if (this.popup) + this.popup.container.style.display = "none"; }; this.changeListener = function(e) { @@ -203,6 +206,9 @@ var Autocomplete = function() { var text = this.completions.filtered[row]; if (text.value) text = text.value; + + // should be good enough, otherwise we can use getDocument().removeInLine + this.editor.removeWordLeft(); this.editor.insert(text); this.detach(); }; @@ -214,6 +220,7 @@ var Autocomplete = function() { "ctrl-down": function(editor) { editor.Autocomplete.goTo("end"); }, "esc": function(editor) { editor.Autocomplete.detach(); }, + "space": function(editor) { editor.Autocomplete.detach(); editor.insert(" ");}, "Return": function(editor) { editor.Autocomplete.insertMatch(); }, "Shift-Return": function(editor) { editor.Autocomplete.insertMatch(true); }, "Tab": function(editor) { editor.Autocomplete.insertMatch(); }, @@ -236,22 +243,15 @@ var Autocomplete = function() { editor.on("changeSelection", this.$changeListener); editor.on("blur", this.$blurListener); - worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition()}); + worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition()}, true); worker.on("complete", function(data) { - _self.completions = new FilteredList(data.data.matches); + var matches = data.data.matches; + _self.completions = new FilteredList(matches); _self.completions.setFilter("a"); - if (data) { - if (data.length == 1) - _self.insertMatch(0); - else - _self.openPopup(editor); - } - }); - - worker.on("terminate", function() { - console.log("term"); + if (matches.length) + _self.openPopup(editor); }); }; diff --git a/lib/ace/autocomplete/autocomplete_worker.js b/lib/ace/autocomplete/autocomplete_worker.js index 2656b086..c85f2e8c 100644 --- a/lib/ace/autocomplete/autocomplete_worker.js +++ b/lib/ace/autocomplete/autocomplete_worker.js @@ -1,7 +1,7 @@ /* ***** BEGIN LICENSE BLOCK ***** * Distributed under the BSD license: * - * Copyright (c) 2010, Ajax.org B.V. + * Copyright (c) 2012, Ajax.org B.V. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,7 +38,9 @@ var SyntaxDetector = require("./syntax_detector"); var completer = require("./text_completer"); var AutocompleteWorker = exports.AutocompleteWorker = function(sender) { + this.setTimeout(0); Mirror.call(this, sender); + this.setDeferredUpdate(false); }; oop.inherits(AutocompleteWorker, Mirror); @@ -55,24 +57,16 @@ oop.inherits(AutocompleteWorker, Mirror); else return 0; }); - for (var i = 0; i < matches.length - 1; i++) { - var a = matches[i]; - var b = matches[i + 1]; - if (a.name === b.name) { - // Duplicate! - if (a.priority < b.priority) - matches.splice(i, 1); - else if (a.priority > b.priority) - matches.splice(i+1, 1); - else if (a.score < b.score) - matches.splice(i, 1); - else if (a.score > b.score) - matches.splice(i+1, 1); - else - matches.splice(i, 1); - i--; + + for(var i = 1; i < matches.length; ){ + if (matches[i - 1] == matches[i]){ + matches.splice(i, 1); + } else { + i++; } } + + return matches; }; this.onUpdate = function() { @@ -87,7 +81,7 @@ oop.inherits(AutocompleteWorker, Mirror); var currentNode = null; var matches = [], ast = null; - completer.complete(_self.doc, ast, this.data.cursor, currentNode, function(completions) { + completer.complete(_self.doc, ast, this.data.cursor, currentNode, function(identifier, completions) { if (completions) matches = matches.concat(completions); removeDuplicateMatches(matches); @@ -115,7 +109,10 @@ oop.inherits(AutocompleteWorker, Mirror); return 0; }); _self.sender.emit("complete", { - pos: pos, + startRow: pos.row, + startColumn: pos.column - identifier.length, + endRow: pos.row, + endColumn: Infinity, matches: matches, line: _self.doc.getLine(pos.row) }); diff --git a/lib/ace/autocomplete/text_completer.js b/lib/ace/autocomplete/text_completer.js index d98ec95f..9ffa9c67 100644 --- a/lib/ace/autocomplete/text_completer.js +++ b/lib/ace/autocomplete/text_completer.js @@ -53,13 +53,16 @@ define(function(require, exports, module) { var line = doc.getLine(pos.row); var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column); + if (identifier === "") + return callback(null); + var allIdentifiers = []; for (var ident in identDict) { allIdentifiers.push(ident); } var matches = completeUtil.findCompletions(identifier, allIdentifiers); - callback(matches); + callback(identifier, matches); /*callback(matches.map(function(m) { return { name : m, diff --git a/lib/ace/worker/mirror.js b/lib/ace/worker/mirror.js index 47412452..dd804865 100644 --- a/lib/ace/worker/mirror.js +++ b/lib/ace/worker/mirror.js @@ -10,22 +10,28 @@ var Mirror = exports.Mirror = function(sender) { this.data = {}; var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this)); - + var _self = this; sender.on("change", function(e) { doc.applyDeltas(e.data); - deferredUpdate.schedule(_self.$timeout); + if (_self.$defer) + deferredUpdate.schedule(_self.$timeout); }); }; (function() { this.$timeout = 500; - + this.$defer = true; + this.setTimeout = function(timeout) { this.$timeout = timeout; }; + this.setDeferredUpdate = function(defer) { + this.$defer = defer; + }; + this.setValue = function(value, data) { this.doc.setValue(value); this.data = data; diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index f48599c4..91dc6ca5 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -144,8 +144,8 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) { catch(ex) {} }; - this.attachToDocument = function(doc, data) { - if (this.$doc) + this.attachToDocument = function(doc, data, ignore) { + if (this.$doc && !ignore) this.terminate(); this.$doc = doc; From 69e41521e67faaf5943ff3a0e6fc34963525b09f Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Thu, 27 Dec 2012 01:51:11 -0800 Subject: [PATCH 10/31] Add autocompletion for language keywords Conflicts: lib/ace/edit_session.js --- lib/ace/autocomplete.js | 2 +- lib/ace/autocomplete/autocomplete_worker.js | 4 +- lib/ace/autocomplete/text_completer.js | 19 +++-- lib/ace/mode/abap.js | 4 +- lib/ace/mode/c_cpp.js | 6 +- lib/ace/mode/clojure.js | 4 +- lib/ace/mode/coffee.js | 4 +- lib/ace/mode/csharp.js | 4 +- lib/ace/mode/css.js | 4 +- lib/ace/mode/dart.js | 1 + lib/ace/mode/glsl.js | 5 +- lib/ace/mode/golang.js | 83 +++++++++++---------- lib/ace/mode/groovy.js | 4 +- lib/ace/mode/haxe.js | 5 +- lib/ace/mode/java.js | 4 +- lib/ace/mode/javascript.js | 5 +- lib/ace/mode/liquid.js | 5 +- lib/ace/mode/lisp.js | 1 + lib/ace/mode/lua.js | 5 +- lib/ace/mode/makefile.js | 1 + lib/ace/mode/ocaml.js | 5 +- lib/ace/mode/perl.js | 5 +- lib/ace/mode/pgsql.js | 39 +++++----- lib/ace/mode/powershell.js | 5 +- lib/ace/mode/python.js | 4 +- lib/ace/mode/ruby.js | 5 +- lib/ace/mode/scad.js | 5 +- lib/ace/mode/scala.js | 4 +- lib/ace/mode/sh.js | 5 +- lib/ace/mode/sql.js | 5 +- lib/ace/mode/stylus.js | 1 + lib/ace/mode/text.js | 18 +++++ lib/ace/mode/text_highlight_rules.js | 1 + 33 files changed, 182 insertions(+), 90 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 33c41f93..e0aa510e 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -243,7 +243,7 @@ var Autocomplete = function() { editor.on("changeSelection", this.$changeListener); editor.on("blur", this.$blurListener); - worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition()}, true); + worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition(), keywords: editor.session.getMode().$keywordList}, true); worker.on("complete", function(data) { var matches = data.data.matches; diff --git a/lib/ace/autocomplete/autocomplete_worker.js b/lib/ace/autocomplete/autocomplete_worker.js index c85f2e8c..6c5ec0d4 100644 --- a/lib/ace/autocomplete/autocomplete_worker.js +++ b/lib/ace/autocomplete/autocomplete_worker.js @@ -74,14 +74,14 @@ oop.inherits(AutocompleteWorker, Mirror); var doc = this.doc.getValue(); var pos = this.data.cursor; - var part = SyntaxDetector.getContextSyntaxPart(this.doc, this.data.cursor, "javascript"); + var part = SyntaxDetector.getContextSyntaxPart(this.doc, this.data.cursor); var language = part.language; var currentPos = { line: pos.row, col: pos.column }; var currentNode = null; var matches = [], ast = null; - completer.complete(_self.doc, ast, this.data.cursor, currentNode, function(identifier, completions) { + completer.complete(_self.doc, ast, this.data.cursor, this.data.keywords, currentNode, function(identifier, completions) { if (completions) matches = matches.concat(completions); removeDuplicateMatches(matches); diff --git a/lib/ace/autocomplete/text_completer.js b/lib/ace/autocomplete/text_completer.js index 9ffa9c67..0cef7aed 100644 --- a/lib/ace/autocomplete/text_completer.js +++ b/lib/ace/autocomplete/text_completer.js @@ -1,6 +1,7 @@ define(function(require, exports, module) { var completeUtil = require("./complete_util"); var SPLIT_REGEX = /[^a-zA-Z_0-9\$]+/; + var MAX_SCORE = 1000000; var completer = module.exports; @@ -9,7 +10,7 @@ define(function(require, exports, module) { }; // For the current document, gives scores to identifiers not on frequency, but on distance from the current prefix - function wordDistanceAnalyzer(doc, pos, prefix) { + function wordDistanceAnalyzer(doc, pos, prefix, keywords) { var text = doc.getValue().trim(); // Determine cursor's word index @@ -32,24 +33,28 @@ define(function(require, exports, module) { var distance = Math.max(prefixPosition, i) - Math.min(prefixPosition, i); // Score substracted from 100000 to force descending ordering if (Object.prototype.hasOwnProperty.call(identDict, ident)) - identDict[ident] = Math.max(1000000-distance, identDict[ident]); + identDict[ident] = Math.max(MAX_SCORE-distance, identDict[ident]); else - identDict[ident] = 1000000-distance; + identDict[ident] = MAX_SCORE-distance; } + + for (var k = 0, l = keywords.length; k < l; k++) { + identDict[keywords[k]] = MAX_SCORE; + } return identDict; } - function analyze(doc, pos) { + function analyze(doc, pos, keywords) { var line = doc.getLine(pos.row); var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column); - var analysisCache = wordDistanceAnalyzer(doc, pos, identifier); + var analysisCache = wordDistanceAnalyzer(doc, pos, identifier, keywords); return analysisCache; } - completer.complete = function(doc, fullAst, pos, currentNode, callback) { - var identDict = analyze(doc, pos); + completer.complete = function(doc, fullAst, pos, keywords, currentNode, callback) { + var identDict = analyze(doc, pos, keywords); var line = doc.getLine(pos.row); var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column); diff --git a/lib/ace/mode/abap.js b/lib/ace/mode/abap.js index b2ba82c4..53cd9532 100644 --- a/lib/ace/mode/abap.js +++ b/lib/ace/mode/abap.js @@ -39,7 +39,9 @@ var TextMode = require("./text").Mode; var oop = require("../lib/oop"); function Mode() { - this.$tokenizer = new Tokenizer(new Rules().getRules()); + var highlighter = new Rules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = new Rules(rules.$keywordList); this.foldingRules = new FoldMode(); } diff --git a/lib/ace/mode/c_cpp.js b/lib/ace/mode/c_cpp.js index c388dc0f..6b6f8c09 100644 --- a/lib/ace/mode/c_cpp.js +++ b/lib/ace/mode/c_cpp.js @@ -41,9 +41,13 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new c_cppHighlightRules().getRules()); + var highlighter = new c_cppHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$outdent = new MatchingBraceOutdent(); this.$behaviour = new CstyleBehaviour(); + this.$keywordList = highlighter.$keywordList; + this.foldingRules = new CStyleFoldMode(); }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/clojure.js b/lib/ace/mode/clojure.js index d1494e02..cbbaace5 100644 --- a/lib/ace/mode/clojure.js +++ b/lib/ace/mode/clojure.js @@ -39,7 +39,9 @@ var MatchingParensOutdent = require("./matching_parens_outdent").MatchingParensO var Range = require("../range").Range; var Mode = function() { - this.$tokenizer = new Tokenizer(new ClojureHighlightRules().getRules()); + var highlighter = new ClojureHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = new Rules(rules.$keywordList); this.$outdent = new MatchingParensOutdent(); }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/coffee.js b/lib/ace/mode/coffee.js index b2bb55ad..18799082 100644 --- a/lib/ace/mode/coffee.js +++ b/lib/ace/mode/coffee.js @@ -41,8 +41,10 @@ var WorkerClient = require("../worker/worker_client").WorkerClient; var oop = require("../lib/oop"); function Mode() { - this.$tokenizer = new Tokenizer(new Rules().getRules()); + var highlighter = new Rules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$outdent = new Outdent(); + this.$keywordList = new Rules(rules.$keywordList); this.foldingRules = new FoldMode(); } diff --git a/lib/ace/mode/csharp.js b/lib/ace/mode/csharp.js index 2e536294..66644b45 100644 --- a/lib/ace/mode/csharp.js +++ b/lib/ace/mode/csharp.js @@ -10,9 +10,11 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new CSharpHighlightRules().getRules()); + var highlighter = new CSharpHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$outdent = new MatchingBraceOutdent(); this.$behaviour = new CstyleBehaviour(); + this.$keywordList = highlighter.$keywordList; this.foldingRules = new CStyleFoldMode(); }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/css.js b/lib/ace/mode/css.js index 2c5807c7..fcaa298c 100644 --- a/lib/ace/mode/css.js +++ b/lib/ace/mode/css.js @@ -41,9 +41,11 @@ var CssBehaviour = require("./behaviour/css").CssBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new CssHighlightRules().getRules()); + var highlighter = new CssHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$outdent = new MatchingBraceOutdent(); this.$behaviour = new CssBehaviour(); + this.$keywordList = highlighter.$keywordList; this.foldingRules = new CStyleFoldMode(); }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/dart.js b/lib/ace/mode/dart.js index 114c79ab..cab31e08 100644 --- a/lib/ace/mode/dart.js +++ b/lib/ace/mode/dart.js @@ -52,6 +52,7 @@ var Mode = function() { this.foldingRules = new CStyleFoldMode(); this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, CMode); diff --git a/lib/ace/mode/glsl.js b/lib/ace/mode/glsl.js index 641f5ebc..ef2a2b44 100644 --- a/lib/ace/mode/glsl.js +++ b/lib/ace/mode/glsl.js @@ -41,9 +41,12 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new glslHighlightRules().getRules()); + var highlighter = new glslHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$outdent = new MatchingBraceOutdent(); this.$behaviour = new CstyleBehaviour(); + this.$keywordList = highlighter.$keywordList; this.foldingRules = new CStyleFoldMode(); }; oop.inherits(Mode, CMode); diff --git a/lib/ace/mode/golang.js b/lib/ace/mode/golang.js index f00ce9c7..72262022 100644 --- a/lib/ace/mode/golang.js +++ b/lib/ace/mode/golang.js @@ -1,55 +1,58 @@ define(function(require, exports, module) { -var oop = require("../lib/oop"); -var TextMode = require("./text").Mode; -var Tokenizer = require("../tokenizer").Tokenizer; -var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules; -var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; -var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; -var CStyleFoldMode = require("./folding/cstyle").FoldMode; - -var Mode = function() { - this.$tokenizer = new Tokenizer(new GolangHighlightRules().getRules()); - this.$outdent = new MatchingBraceOutdent(); - this.foldingRules = new CStyleFoldMode(); -}; -oop.inherits(Mode, TextMode); - -(function() { + var oop = require("../lib/oop"); + var TextMode = require("./text").Mode; + var Tokenizer = require("../tokenizer").Tokenizer; + var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules; + var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; + var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; + var CStyleFoldMode = require("./folding/cstyle").FoldMode; + var Mode = function() { + var highlighter = new GolangHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; + this.$outdent = new MatchingBraceOutdent(); + this.foldingRules = new CStyleFoldMode(); + }; + oop.inherits(Mode, TextMode); + + (function() { + this.lineCommentStart = "//"; this.blockComment = {start: "/*", end: "*/"}; - this.getNextLineIndent = function(state, line, tab) { - var indent = this.$getIndent(line); + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); - var tokenizedLine = this.$tokenizer.getLineTokens(line, state); - var tokens = tokenizedLine.tokens; - var endState = tokenizedLine.state; + var tokenizedLine = this.$tokenizer.getLineTokens(line, state); + var tokens = tokenizedLine.tokens; + var endState = tokenizedLine.state; - if (tokens.length && tokens[tokens.length-1].type == "comment") { - return indent; - } - - if (state == "start") { - var match = line.match(/^.*[\{\(\[]\s*$/); - if (match) { - indent += tab; + if (tokens.length && tokens[tokens.length-1].type == "comment") { + return indent; + } + + if (state == "start") { + var match = line.match(/^.*[\{\(\[]\s*$/); + if (match) { + indent += tab; + } } - } - return indent; - };//end getNextLineIndent + return indent; + };//end getNextLineIndent - this.checkOutdent = function(state, line, input) { - return this.$outdent.checkOutdent(line, input); - }; + this.checkOutdent = function(state, line, input) { + return this.$outdent.checkOutdent(line, input); + }; - this.autoOutdent = function(state, doc, row) { - this.$outdent.autoOutdent(doc, row); - }; + this.autoOutdent = function(state, doc, row) { + this.$outdent.autoOutdent(doc, row); + }; -}).call(Mode.prototype); + }).call(Mode.prototype); -exports.Mode = Mode; + exports.Mode = Mode; }); diff --git a/lib/ace/mode/groovy.js b/lib/ace/mode/groovy.js index fad038eb..65d87cd4 100644 --- a/lib/ace/mode/groovy.js +++ b/lib/ace/mode/groovy.js @@ -8,7 +8,9 @@ var GroovyHighlightRules = require("./groovy_highlight_rules").GroovyHighlightRu var Mode = function() { JavaScriptMode.call(this); - this.$tokenizer = new Tokenizer(new GroovyHighlightRules().getRules()); + var highlighter = new GroovyHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, JavaScriptMode); diff --git a/lib/ace/mode/haxe.js b/lib/ace/mode/haxe.js index edbfef6b..3933a769 100644 --- a/lib/ace/mode/haxe.js +++ b/lib/ace/mode/haxe.js @@ -10,9 +10,12 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new HaxeHighlightRules().getRules()); + var highlighter = new HaxeHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$outdent = new MatchingBraceOutdent(); this.$behaviour = new CstyleBehaviour(); + this.$keywordList = highlighter.$keywordList; this.foldingRules = new CStyleFoldMode(); }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/java.js b/lib/ace/mode/java.js index 1b7045ea..f132130b 100644 --- a/lib/ace/mode/java.js +++ b/lib/ace/mode/java.js @@ -8,8 +8,10 @@ var JavaHighlightRules = require("./java_highlight_rules").JavaHighlightRules; var Mode = function() { JavaScriptMode.call(this); + var highlighter = new JavaHighlightRules(); - this.$tokenizer = new Tokenizer(new JavaHighlightRules().getRules()); + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, JavaScriptMode); diff --git a/lib/ace/mode/javascript.js b/lib/ace/mode/javascript.js index a3e45bcc..00d8af1a 100644 --- a/lib/ace/mode/javascript.js +++ b/lib/ace/mode/javascript.js @@ -42,9 +42,12 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new JavaScriptHighlightRules().getRules()); + var highlighter = new JavaScriptHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$outdent = new MatchingBraceOutdent(); this.$behaviour = new CstyleBehaviour(); + this.$keywordList = highlighter.$keywordList; this.foldingRules = new CStyleFoldMode(); }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/liquid.js b/lib/ace/mode/liquid.js index 8555e6c5..247c02a1 100644 --- a/lib/ace/mode/liquid.js +++ b/lib/ace/mode/liquid.js @@ -38,7 +38,10 @@ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutd var Range = require("../range").Range; var Mode = function() { - this.$tokenizer = new Tokenizer(new LiquidHighlightRules().getRules()); + var highlighter = new LiquidHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; this.$outdent = new MatchingBraceOutdent(); }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/lisp.js b/lib/ace/mode/lisp.js index 5bae6689..46427d60 100644 --- a/lib/ace/mode/lisp.js +++ b/lib/ace/mode/lisp.js @@ -45,6 +45,7 @@ var Mode = function() { var highlighter = new LispHighlightRules(); this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/lua.js b/lib/ace/mode/lua.js index 2ef9031a..58a3c822 100644 --- a/lib/ace/mode/lua.js +++ b/lib/ace/mode/lua.js @@ -40,8 +40,11 @@ var Range = require("../range").Range; var WorkerClient = require("../worker/worker_client").WorkerClient; var Mode = function() { - this.$tokenizer = new Tokenizer(new LuaHighlightRules().getRules()); + var highlighter = new LuaHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); this.foldingRules = new LuaFoldMode(); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/makefile.js b/lib/ace/mode/makefile.js index 7f8f726b..a54171dd 100644 --- a/lib/ace/mode/makefile.js +++ b/lib/ace/mode/makefile.js @@ -51,6 +51,7 @@ var Mode = function() { this.foldingRules = new FoldMode(); this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/ocaml.js b/lib/ace/mode/ocaml.js index 6367b937..9aa6643d 100644 --- a/lib/ace/mode/ocaml.js +++ b/lib/ace/mode/ocaml.js @@ -39,8 +39,11 @@ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutd var Range = require("../range").Range; var Mode = function() { - this.$tokenizer = new Tokenizer(new OcamlHighlightRules().getRules()); + var highlighter = new OcamlHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$outdent = new MatchingBraceOutdent(); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/perl.js b/lib/ace/mode/perl.js index ff8eaa18..46d20065 100644 --- a/lib/ace/mode/perl.js +++ b/lib/ace/mode/perl.js @@ -40,9 +40,12 @@ var Range = require("../range").Range; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new PerlHighlightRules().getRules()); + var highlighter = new PerlHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$outdent = new MatchingBraceOutdent(); this.foldingRules = new CStyleFoldMode({start: "^=(begin|item)\\b", end: "^=(cut)\\b"}); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/pgsql.js b/lib/ace/mode/pgsql.js index 29c30311..4ebaec80 100755 --- a/lib/ace/mode/pgsql.js +++ b/lib/ace/mode/pgsql.js @@ -30,30 +30,33 @@ define(function(require, exports, module) { -var oop = require("../lib/oop"); -var TextMode = require("../mode/text").Mode; -var Tokenizer = require("../tokenizer").Tokenizer; -var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules; -var Range = require("../range").Range; + var oop = require("../lib/oop"); + var TextMode = require("../mode/text").Mode; + var Tokenizer = require("../tokenizer").Tokenizer; + var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules; + var Range = require("../range").Range; -var Mode = function() { - this.$tokenizer = new Tokenizer(new PgsqlHighlightRules().getRules()); -}; -oop.inherits(Mode, TextMode); + var Mode = function() { + var highlighter = new PgsqlHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; + }; + oop.inherits(Mode, TextMode); -(function() { + (function() { this.lineCommentStart = "--"; this.blockComment = {start: "/*", end: "*/"}; - this.getNextLineIndent = function(state, line, tab) { - if (state == "start" || state == "keyword.statementEnd") { - return ""; - } else { - return this.$getIndent(line); // Keep whatever indent the previous line has + this.getNextLineIndent = function(state, line, tab) { + if (state == "start" || state == "keyword.statementEnd") { + return ""; + } else { + return this.$getIndent(line); // Keep whatever indent the previous line has + } } - } -}).call(Mode.prototype); + }).call(Mode.prototype); -exports.Mode = Mode; + exports.Mode = Mode; }); diff --git a/lib/ace/mode/powershell.js b/lib/ace/mode/powershell.js index b0c12eb7..f3bfcdcc 100644 --- a/lib/ace/mode/powershell.js +++ b/lib/ace/mode/powershell.js @@ -10,7 +10,10 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new PowershellHighlightRules().getRules()); + var highlighter = new PowershellHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; this.$outdent = new MatchingBraceOutdent(); this.$behaviour = new CstyleBehaviour(); this.foldingRules = new CStyleFoldMode({start: "^\\s*(<#)", end: "^[#\\s]>\\s*$"}); diff --git a/lib/ace/mode/python.js b/lib/ace/mode/python.js index 5a38f2c4..7adaf918 100644 --- a/lib/ace/mode/python.js +++ b/lib/ace/mode/python.js @@ -39,7 +39,9 @@ var PythonFoldMode = require("./folding/pythonic").FoldMode; var Range = require("../range").Range; var Mode = function() { - this.$tokenizer = new Tokenizer(new PythonHighlightRules().getRules()); + var highlighter = new PythonHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; this.foldingRules = new PythonFoldMode("\\:"); }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/ruby.js b/lib/ace/mode/ruby.js index 073fa070..ca832137 100644 --- a/lib/ace/mode/ruby.js +++ b/lib/ace/mode/ruby.js @@ -40,7 +40,10 @@ var Range = require("../range").Range; var FoldMode = require("./folding/coffee").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new RubyHighlightRules().getRules()); + var highlighter = new RubyHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; this.$outdent = new MatchingBraceOutdent(); this.foldingRules = new FoldMode(); }; diff --git a/lib/ace/mode/scad.js b/lib/ace/mode/scad.js index c5c3e04b..6bd094bc 100644 --- a/lib/ace/mode/scad.js +++ b/lib/ace/mode/scad.js @@ -41,7 +41,10 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new scadHighlightRules().getRules()); + var highlighter = new scadHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; this.$outdent = new MatchingBraceOutdent(); this.$behaviour = new CstyleBehaviour(); this.foldingRules = new CStyleFoldMode(); diff --git a/lib/ace/mode/scala.js b/lib/ace/mode/scala.js index 407d41cc..97e891fd 100644 --- a/lib/ace/mode/scala.js +++ b/lib/ace/mode/scala.js @@ -9,7 +9,9 @@ var ScalaHighlightRules = require("./scala_highlight_rules").ScalaHighlightRules var Mode = function() { JavaScriptMode.call(this); - this.$tokenizer = new Tokenizer(new ScalaHighlightRules().getRules()); + var highlighter = new ScalaHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, JavaScriptMode); diff --git a/lib/ace/mode/sh.js b/lib/ace/mode/sh.js index d97b336a..84496fb3 100644 --- a/lib/ace/mode/sh.js +++ b/lib/ace/mode/sh.js @@ -38,7 +38,10 @@ var ShHighlightRules = require("./sh_highlight_rules").ShHighlightRules; var Range = require("../range").Range; var Mode = function() { - this.$tokenizer = new Tokenizer(new ShHighlightRules().getRules()); + var highlighter = new ShHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/sql.js b/lib/ace/mode/sql.js index 6d5c8372..6b4d9c6e 100644 --- a/lib/ace/mode/sql.js +++ b/lib/ace/mode/sql.js @@ -38,7 +38,10 @@ var SqlHighlightRules = require("./sql_highlight_rules").SqlHighlightRules; var Range = require("../range").Range; var Mode = function() { - this.$tokenizer = new Tokenizer(new SqlHighlightRules().getRules()); + var highlighter = new SqlHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/stylus.js b/lib/ace/mode/stylus.js index 879f35fb..065348c6 100644 --- a/lib/ace/mode/stylus.js +++ b/lib/ace/mode/stylus.js @@ -51,6 +51,7 @@ var Mode = function() { this.foldingRules = new FoldMode(); this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/text.js b/lib/ace/mode/text.js index e243ddbd..6763c602 100644 --- a/lib/ace/mode/text.js +++ b/lib/ace/mode/text.js @@ -325,7 +325,25 @@ var Mode = function() { } } }; + + this.getKeywords = function() { + var rules = this.$tokenizer.rules; + var keywords = []; + for (var rule in rules) { + var ruleItr = rules[rule]; + for (var r = 0, l = ruleItr.length; r < l; r++) { + if (typeof ruleItr[r].token === "string") { + if (/keyword/.test(ruleItr[r].token)) + keywords.push(ruleItr[r].regex); + else if (/support/.test(ruleItr[r].token)) + keywords.push(ruleItr[r].regex); + } + } + } + return keywords.concat(this.$keywordList || []); + }; + }).call(Mode.prototype); exports.Mode = Mode; diff --git a/lib/ace/mode/text_highlight_rules.js b/lib/ace/mode/text_highlight_rules.js index 5d418ec8..d6dbd794 100644 --- a/lib/ace/mode/text_highlight_rules.js +++ b/lib/ace/mode/text_highlight_rules.js @@ -204,6 +204,7 @@ var TextHighlightRules = function() { for (var i = list.length; i--; ) keywords[list[i]] = className; }); + this.$keywordList = Object.keys(keywords); map = null; return ignoreCase ? function(value) {return keywords[value.toLowerCase()] || defaultToken } From cd19233b3182e5f74afa83d456d870471d9b5a4c Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Thu, 3 Jan 2013 23:44:54 -0800 Subject: [PATCH 11/31] Improve UX, drop dead code --- lib/ace/autocomplete.js | 41 ++++- lib/ace/autocomplete/autocomplete_worker.js | 10 +- lib/ace/autocomplete/complete_util.js | 22 --- lib/ace/autocomplete/syntax_detector.js | 176 -------------------- lib/ace/autocomplete/text_completer.js | 23 +-- lib/ace/mode/javascript_highlight_rules.js | 2 +- lib/ace/mode/text.js | 41 +++-- lib/ace/multi_select.js | 2 +- tool/mode.tmpl.js | 1 + 9 files changed, 72 insertions(+), 246 deletions(-) delete mode 100644 lib/ace/autocomplete/syntax_detector.js diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index e0aa510e..c91cb7c1 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -55,6 +55,7 @@ var Autocomplete = function() { this.$blurListener = this.blurListener.bind(this); this.$changeListener = this.changeListener.bind(this); + this.$mousedownListener = this.mousedownListener.bind(this); }; @@ -127,8 +128,10 @@ var Autocomplete = function() { }; popup.setHighlight = function(re) { - ace.session.highlight(re) - ace.session._emit("changeFrontMarker") + ace.session.highlight(re); + ace.session._emit("changeFrontMarker"); + // select first item + dom.addCssClass(_self.popup.container.getElementsByClassName("ace_autocomplete")[0].childNodes[0], "autocomplete_selected"); }; this.popup = popup; @@ -166,6 +169,7 @@ var Autocomplete = function() { this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler); this.editor.removeEventListener("changeSelection", this.changeListener); this.editor.removeEventListener("blur", this.changeListener); + this.editor.removeEventListener("mousedown", this.changeListener); if (this.popup) this.popup.container.style.display = "none"; @@ -179,6 +183,16 @@ var Autocomplete = function() { if (document.activeElement != this.editor.textInput.getElement()) this.detach(); }; + + this.mousedownListener = function(e) { + var mouseX = e.clientX, mouseY = e.clientY; + var newRow = this.editor.renderer.pixelToScreenCoordinates(mouseX, mouseY).row; + var currentRow = e.editor.getCursorPosition().row; + + if (newRow !== currentRow) { + this.detach(); + } + }; this.goTo = function(where) { var row = this.popup.getRow(); @@ -189,8 +203,8 @@ var Autocomplete = function() { dom.removeCssClass(choices[row], "autocomplete_selected"); switch(where) { - case "up": row = row < 0 ? max : row-1; break; - case "down": row = row >= max ? -1 : row+1; break; + case "up": row = row <= 0 ? max : row - 1; break; + case "down": row = row >= max ? 0 : row + 1; break; case "start": row = 0; break; case "end": row = max; break } @@ -224,7 +238,15 @@ var Autocomplete = function() { "Return": function(editor) { editor.Autocomplete.insertMatch(); }, "Shift-Return": function(editor) { editor.Autocomplete.insertMatch(true); }, "Tab": function(editor) { editor.Autocomplete.insertMatch(); }, - "Shift-Tab": function(editor) {}, + "backspace": function(editor) { + var doc = editor.session.getDocument(), + cursor = editor.getCursorPosition(); + + editor.Autocomplete.detach(); + // delete one char, and reevaluate + editor.remove("left"); + editor.Autocomplete.complete(editor); + } }; this.complete = function(editor) { @@ -242,16 +264,17 @@ var Autocomplete = function() { editor.keyBinding.addKeyboardHandler(this.keyboardHandler); editor.on("changeSelection", this.$changeListener); editor.on("blur", this.$blurListener); + editor.on("mousedown", this.$mousedownListener); - worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition(), keywords: editor.session.getMode().$keywordList}, true); + worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition(), keywords: editor.session.getMode().getKeywords(true)}, true); worker.on("complete", function(data) { var matches = data.data.matches; _self.completions = new FilteredList(matches); _self.completions.setFilter("a"); - if (matches.length) - _self.openPopup(editor); + if (matches.length) { + _self.openPopup(editor); } }); }; @@ -328,7 +351,7 @@ var Autocomplete = function() { }; renderer.isScrollableBy=function(){return false}; - renderer.setStyle("ace_one-line"); + renderer.setStyle("ace_autocomplete"); var Editor = require("ace/editor").Editor; var editor = new Editor(renderer); diff --git a/lib/ace/autocomplete/autocomplete_worker.js b/lib/ace/autocomplete/autocomplete_worker.js index 6c5ec0d4..cbcbbc05 100644 --- a/lib/ace/autocomplete/autocomplete_worker.js +++ b/lib/ace/autocomplete/autocomplete_worker.js @@ -34,7 +34,6 @@ define(function(require, exports, module) { var oop = require("../lib/oop"); var Mirror = require("../worker/mirror").Mirror; -var SyntaxDetector = require("./syntax_detector"); var completer = require("./text_completer"); var AutocompleteWorker = exports.AutocompleteWorker = function(sender) { @@ -72,16 +71,13 @@ oop.inherits(AutocompleteWorker, Mirror); this.onUpdate = function() { var _self = this; - var doc = this.doc.getValue(); + var doc = this.doc.getValue(); var pos = this.data.cursor; - var part = SyntaxDetector.getContextSyntaxPart(this.doc, this.data.cursor); - var language = part.language; var currentPos = { line: pos.row, col: pos.column }; - var currentNode = null; - var matches = [], ast = null; + var matches = []; - completer.complete(_self.doc, ast, this.data.cursor, this.data.keywords, currentNode, function(identifier, completions) { + completer.complete(_self.doc, this.data.cursor, this.data.keywords, function(identifier, completions) { if (completions) matches = matches.concat(completions); removeDuplicateMatches(matches); diff --git a/lib/ace/autocomplete/complete_util.js b/lib/ace/autocomplete/complete_util.js index 4b7e6a16..b094fb74 100644 --- a/lib/ace/autocomplete/complete_util.js +++ b/lib/ace/autocomplete/complete_util.js @@ -56,30 +56,8 @@ function findCompletions(prefix, allIdentifiers) { return matches; } -function fetchText(staticPrefix, path) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', staticPrefix + "/" + path, false); - try { - xhr.send(); - } - // Likely we got a cross-script error (equivalent with a 404 in our cloud setup) - catch(e) { - return false; - } - if (xhr.status === 200) - return xhr.responseText; - else - return false; -} - -/** @deprecated Use retrievePrecedingIdentifier */ -exports.retrievePreceedingIdentifier = function() { - console.error("Deprecated: 'retrievePreceedingIdentifier' - use 'retrievePrecedingIdentifier' instead"); - return retrievePrecedingIdentifier.apply(null, arguments); -}; exports.retrievePrecedingIdentifier = retrievePrecedingIdentifier; exports.retrieveFollowingIdentifier = retrieveFollowingIdentifier; exports.findCompletions = findCompletions; -exports.fetchText = fetchText; }); diff --git a/lib/ace/autocomplete/syntax_detector.js b/lib/ace/autocomplete/syntax_detector.js deleted file mode 100644 index 40cfd3f1..00000000 --- a/lib/ace/autocomplete/syntax_detector.js +++ /dev/null @@ -1,176 +0,0 @@ -/** - * Cloud9 Language Foundation - * - * @copyright 2011, Ajax.org B.V. - * @license GPLv3 - */ -define(function(require, exports, module) { - -var mixedLanguages = { - php: { - "default": "html", - "php-start": /<\?(?:php|\=)?/, - "php-end": /\?>/, - "css-start": /]*>/, - "css-end": /<\/style>/, - "javascript-start": /\/])*>/, - "javascript-end": /<\/script>/ - }, - html: { - "css-start": /]*>/, - "css-end": /<\/style>/, - "javascript-start": /\/])*>/, - "javascript-end": /<\/script>/ - } -}; - -/* Now: - * - One level syntax nesting supported - * Future: (if worth it) - * - Have a stack to repesent it - * - Maintain a syntax tree for an opened file - */ -function getSyntaxRegions(doc, originalSyntax) { - if (! mixedLanguages[originalSyntax]) - return [{ - syntax: originalSyntax, - sl: 0, - sc: 0, - el: doc.getLength()-1, - ec: doc.getLine(doc.getLength()-1).length - }]; - - var lines = doc.getAllLines(); - var type = mixedLanguages[originalSyntax]; - var defaultSyntax = type["default"] || originalSyntax; - var starters = Object.keys(type).filter(function (m) { - return m.indexOf("-start") === m.length - 6; - }); - var syntax = defaultSyntax; - var regions = [{syntax: syntax, sl: 0, sc: 0}]; - var starter, endLang; - var tempS, tempM; - var i, m, cut, inLine = 0; - - for (var row = 0; row < lines.length; row++) { - var line = lines[row]; - m = null; - if (endLang) { - m = endLang.exec(line); - if (m) { - endLang = null; - syntax = defaultSyntax; - regions[regions.length-1].el = row; - regions[regions.length-1].ec = m.index + inLine; - regions.push({ - syntax: syntax, - sl: row, - sc: m.index + inLine - }); - cut = m.index + m[0].length; - lines[row] = line.substring(cut); - inLine += cut; - row--; // continue processing of the line - } - else { - inLine = 0; - } - } - else { - for (i = 0; i < starters.length; i++) { - tempS = starters[i]; - tempM = type[tempS].exec(line); - if (tempM && (!m || m.index > tempM.index)) { - m = tempM; - starter = tempS; - } - } - if (m) { - syntax = starter.replace("-start", ""); - endLang = type[syntax+"-end"]; - regions[regions.length-1].el = row; - regions[regions.length-1].ec = inLine + m.index + m[0].length; - regions.push({ - syntax: syntax, - sl: row, - sc: inLine + m.index + m[0].length - }); - cut = m.index + m[0].length; - lines[row] = line.substring(m.index + m[0].length); - row--; // continue processing of the line - inLine += cut; - } - else { - inLine = 0; - } - } - } - regions[regions.length-1].el = lines.length; - regions[regions.length-1].ec = lines[lines.length-1].length; - return regions; -} - -function getContextSyntaxPart(doc, pos, originalSyntax) { - if (! mixedLanguages[originalSyntax]) - return { - language: originalSyntax, - value: doc.getValue(), - region: getSyntaxRegions(doc, originalSyntax)[0], - index: 0 - }; - var regions = getSyntaxRegions(doc, originalSyntax); - for (var i = 0; i < regions.length; i++) { - var region = regions[i]; - if ((pos.row > region.sl && pos.row < region.el) || - (pos.row === region.sl && pos.column >= region.sc) || - (pos.row === region.el && pos.column <= region.ec)) - return regionToCodePart(doc, region, i); - } - return null; // should never happen -} - -function getContextSyntax(doc, pos, originalSyntax) { - var part = getContextSyntaxPart(doc, pos, originalSyntax); - return part && part.language; // should never happen -} - -function regionToCodePart (doc, region, index) { - var lines = doc.getLines(region.sl, region.el); - return { - value: region.sl === region.el ? lines[0].substring(region.sc, region.ec) : - [lines[0].substring(region.sc)].concat(lines.slice(1, lines.length-1)).concat([lines[lines.length-1].substring(0, region.ec)]).join(doc.getNewLineCharacter()), - language: region.syntax, - region: region, - index: index - }; -} - -function getCodeParts (doc, originalSyntax) { - var regions = getSyntaxRegions(doc, originalSyntax); - return regions.map(function (region, i) { - return regionToCodePart(doc, region, i); - }); -} - -function posToRegion (region, pos) { - return { - row: pos.row - region.sl, - column: pos.column - }; -} - -function regionToPos (region, pos) { - return { - row: pos.row + region.sl, - column: pos.column - }; -} - -exports.getContextSyntax = getContextSyntax; -exports.getContextSyntaxPart = getContextSyntaxPart; -exports.getSyntaxRegions = getSyntaxRegions; -exports.getCodeParts = getCodeParts; -exports.posToRegion = posToRegion; -exports.regionToPos = regionToPos; - -}); diff --git a/lib/ace/autocomplete/text_completer.js b/lib/ace/autocomplete/text_completer.js index 0cef7aed..44a72c9b 100644 --- a/lib/ace/autocomplete/text_completer.js +++ b/lib/ace/autocomplete/text_completer.js @@ -4,10 +4,6 @@ define(function(require, exports, module) { var MAX_SCORE = 1000000; var completer = module.exports; - - this.handlesLanguage = function(language) { - return true; - }; // For the current document, gives scores to identifiers not on frequency, but on distance from the current prefix function wordDistanceAnalyzer(doc, pos, prefix, keywords) { @@ -42,6 +38,7 @@ define(function(require, exports, module) { for (var k = 0, l = keywords.length; k < l; k++) { identDict[keywords[k]] = MAX_SCORE; } + return identDict; } @@ -53,30 +50,24 @@ define(function(require, exports, module) { return analysisCache; } - completer.complete = function(doc, fullAst, pos, keywords, currentNode, callback) { - var identDict = analyze(doc, pos, keywords); + completer.complete = function(doc, pos, keywords, callback) { var line = doc.getLine(pos.row); var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column); + // there's nothing to autocomplete if (identifier === "") return callback(null); + var identDict = analyze(doc, pos, keywords); + var allIdentifiers = []; for (var ident in identDict) { allIdentifiers.push(ident); } + + // find matches based on text in doc var matches = completeUtil.findCompletions(identifier, allIdentifiers); callback(identifier, matches); - /*callback(matches.map(function(m) { - return { - name : m, - replaceText : m, - icon : null, - score : identDict[m], - meta : "", - priority : 1 - }; - }));*/ }; }); \ No newline at end of file diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 638ef6b3..3984f2c3 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -168,7 +168,7 @@ var JavaScriptHighlightRules = function() { next : "start" }, { token : ["punctuation.operator", "support.function"], - regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:opzzzz|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ + regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ }, { token : ["punctuation.operator", "support.function.dom"], regex : /(\.)(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ diff --git a/lib/ace/mode/text.js b/lib/ace/mode/text.js index 6763c602..6bf36018 100644 --- a/lib/ace/mode/text.js +++ b/lib/ace/mode/text.js @@ -326,22 +326,35 @@ var Mode = function() { } }; - this.getKeywords = function() { - var rules = this.$tokenizer.rules; - var keywords = []; - for (var rule in rules) { - var ruleItr = rules[rule]; - for (var r = 0, l = ruleItr.length; r < l; r++) { - if (typeof ruleItr[r].token === "string") { - if (/keyword/.test(ruleItr[r].token)) - keywords.push(ruleItr[r].regex); - else if (/support/.test(ruleItr[r].token)) - keywords.push(ruleItr[r].regex); - } + this.getKeywords = function(append) { + // this is for autocompletion to pick up regexp'ed keywords + if (!this.completionKeywords) { + var rules = this.$tokenizer.rules; + var completionKeywords = []; + for (var rule in rules) { + var ruleItr = rules[rule]; + for (var r = 0, l = ruleItr.length; r < l; r++) { + if (typeof ruleItr[r].token === "string") { + if (/keyword|support|storage/.test(ruleItr[r].token)) + completionKeywords.push(ruleItr[r].regex); + } + else if (typeof ruleItr[r].token === "object") { + for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) { + if (/keyword|support|storage/.test(ruleItr[r].token[a])) { + // drop surrounding parens + var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a]; + completionKeywords.push(rule.substr(1, rule.length - 2)); + } + } + } + } } + this.completionKeywords = completionKeywords; } - - return keywords.concat(this.$keywordList || []); + // this is for highlighting embed rules, like HAML/Ruby or Obj-C/C + if (!append) + return this.$keywordList; + return completionKeywords.concat(this.$keywordList || []); }; }).call(Mode.prototype); diff --git a/lib/ace/multi_select.js b/lib/ace/multi_select.js index 2de7fc1d..41ca9b89 100644 --- a/lib/ace/multi_select.js +++ b/lib/ace/multi_select.js @@ -374,7 +374,7 @@ var Editor = require("./editor").Editor; /** * Removes the selection marker. - * @param {Range} The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. + * @param {Range} range The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. * @method Editor.removeSelectionMarker **/ this.removeSelectionMarker = function(range) { diff --git a/tool/mode.tmpl.js b/tool/mode.tmpl.js index 054cb7e6..bdf8065e 100644 --- a/tool/mode.tmpl.js +++ b/tool/mode.tmpl.js @@ -51,6 +51,7 @@ var Mode = function() { var highlighter = new %language%HighlightRules(); this.foldingRules = new FoldMode(); this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; }; oop.inherits(Mode, TextMode); From b811f1dc3fba71f25bedb8342b7ef55cdc262397 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Fri, 4 Jan 2013 15:07:23 -0800 Subject: [PATCH 12/31] Fix rerender on text insertion --- lib/ace/autocomplete.js | 36 +++--- lib/ace/autocomplete/autocomplete_worker.js | 75 +++---------- lib/ace/autocomplete/complete_util.js | 117 +++++++++++++++----- lib/ace/autocomplete/text_completer.js | 54 ++++++--- 4 files changed, 167 insertions(+), 115 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index c91cb7c1..705fa978 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -163,6 +163,8 @@ var Autocomplete = function() { el.style.left = pos.left + "px"; el.style.display = ""; + + renderer.updateText(); }; this.detach = function() { @@ -173,10 +175,15 @@ var Autocomplete = function() { if (this.popup) this.popup.container.style.display = "none"; + + this.editor.Autocomplete.activated = false; }; this.changeListener = function(e) { - //console.log(e) + if (this.editor.Autocomplete.activated) + Autocomplete.startCommand.exec(this.editor); + else + this.detach(); }; this.blurListener = function() { @@ -215,6 +222,8 @@ var Autocomplete = function() { }; this.insertMatch = function(row) { + this.detach(); + if (row == undefined) row = this.popup.getRow(); var text = this.completions.filtered[row]; @@ -224,7 +233,6 @@ var Autocomplete = function() { // should be good enough, otherwise we can use getDocument().removeInLine this.editor.removeWordLeft(); this.editor.insert(text); - this.detach(); }; this.commands = { @@ -237,16 +245,7 @@ var Autocomplete = function() { "space": function(editor) { editor.Autocomplete.detach(); editor.insert(" ");}, "Return": function(editor) { editor.Autocomplete.insertMatch(); }, "Shift-Return": function(editor) { editor.Autocomplete.insertMatch(true); }, - "Tab": function(editor) { editor.Autocomplete.insertMatch(); }, - "backspace": function(editor) { - var doc = editor.session.getDocument(), - cursor = editor.getCursorPosition(); - - editor.Autocomplete.detach(); - // delete one char, and reevaluate - editor.remove("left"); - editor.Autocomplete.complete(editor); - } + "Tab": function(editor) { editor.Autocomplete.insertMatch(); } }; this.complete = function(editor) { @@ -266,15 +265,19 @@ var Autocomplete = function() { editor.on("blur", this.$blurListener); editor.on("mousedown", this.$mousedownListener); - worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition(), keywords: editor.session.getMode().getKeywords(true)}, true); + worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition(), keywords: editor.session.getMode().getKeywords()}, true); worker.on("complete", function(data) { var matches = data.data.matches; - _self.completions = new FilteredList(matches); - _self.completions.setFilter("a"); if (matches.length) { - _self.openPopup(editor); } + _self.completions = new FilteredList(matches); + _self.completions.setFilter("a"); + _self.openPopup(editor); + } + else { + _self.detach(); + } }); }; @@ -377,6 +380,7 @@ Autocomplete.startCommand = { if (!editor.Autocomplete) editor.Autocomplete = new Autocomplete(); editor.Autocomplete.complete(editor); + editor.Autocomplete.activated = true; }, bindKey: "Ctrl-Space|Shift-Space|Alt-Space" } diff --git a/lib/ace/autocomplete/autocomplete_worker.js b/lib/ace/autocomplete/autocomplete_worker.js index cbcbbc05..39a3ba89 100644 --- a/lib/ace/autocomplete/autocomplete_worker.js +++ b/lib/ace/autocomplete/autocomplete_worker.js @@ -45,29 +45,6 @@ var AutocompleteWorker = exports.AutocompleteWorker = function(sender) { oop.inherits(AutocompleteWorker, Mirror); (function() { - // For code completion - function removeDuplicateMatches(matches) { - // First sort - matches.sort(function(a, b) { - if (a.name < b.name) - return 1; - else if (a.name > b.name) - return -1; - else - return 0; - }); - - for(var i = 1; i < matches.length; ){ - if (matches[i - 1] == matches[i]){ - matches.splice(i, 1); - } else { - i++; - } - } - - return matches; - }; - this.onUpdate = function() { var _self = this; @@ -75,43 +52,25 @@ oop.inherits(AutocompleteWorker, Mirror); var pos = this.data.cursor; var currentPos = { line: pos.row, col: pos.column }; - var matches = []; completer.complete(_self.doc, this.data.cursor, this.data.keywords, function(identifier, completions) { - if (completions) - matches = matches.concat(completions); - removeDuplicateMatches(matches); - // Sort by priority, score - matches.sort(function(a, b) { - if (a.priority < b.priority) - return 1; - else if (a.priority > b.priority) - return -1; - else if (a.score < b.score) - return 1; - else if (a.score > b.score) - return -1; - else if (a.id && a.id === b.id) { - if (a.isFunction) - return -1; - else if (b.isFunction) - return 1; - } - if (a.name < b.name) - return -1; - else if(a.name > b.name) - return 1; - else - return 0; - }); - _self.sender.emit("complete", { - startRow: pos.row, - startColumn: pos.column - identifier.length, - endRow: pos.row, - endColumn: Infinity, - matches: matches, - line: _self.doc.getLine(pos.row) - }); + if (!identifier) { + _self.sender.emit("complete", { + matches: [] + }); + } + + else { + _self.sender.emit("complete", { + startRow: pos.row, + startColumn: pos.column - identifier.length, + endRow: pos.row, + endColumn: Infinity, + matches: completions, + line: _self.doc.getLine(pos.row) + }); + } + return; }); }; diff --git a/lib/ace/autocomplete/complete_util.js b/lib/ace/autocomplete/complete_util.js index b094fb74..ad62393e 100644 --- a/lib/ace/autocomplete/complete_util.js +++ b/lib/ace/autocomplete/complete_util.js @@ -1,3 +1,33 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + define(function(require, exports, module) { var ID_REGEX = /[a-zA-Z_0-9\$]/; @@ -26,36 +56,71 @@ function retrieveFollowingIdentifier(text, pos, regex) { return buf; } -function prefixBinarySearch(items, prefix) { - var startIndex = 0; - var stopIndex = items.length - 1; - var middle = Math.floor((stopIndex + startIndex) / 2); - - while (stopIndex > startIndex && middle >= 0 && items[middle].indexOf(prefix) !== 0) { - if (prefix < items[middle]) { - stopIndex = middle - 1; - } - else if (prefix > items[middle]) { - startIndex = middle + 1; - } - middle = Math.floor((stopIndex + stopIndex) / 2); - } - - // Look back to make sure we haven't skipped any - while (middle > 0 && items[middle-1].indexOf(prefix) === 0) - middle--; - return middle >= 0 ? middle : 0; // ensure we're not returning a negative index -} +// filched from jQuery +function grep( elems, callback, inv ) { + var retVal, + ret = [], + i = 0, + length = elems.length; + inv = !!inv; + + // Go through the array, only saving the items + // that pass the validator function + for ( ; i < length; i++ ) { + retVal = !!callback( elems[ i ], i ); + if ( inv !== retVal ) { + ret.push( elems[ i ] ); + } + } + + return ret; +}; + +function sortByScore(items, identDict) { + + return items.sort(function(a, b) { + var scoreA = identDict[a], + scoreB = identDict[b]; + + if (a < b) + return 1; + else if (a > b) + return -1; + else + return 0; + }); +}; + +function findCompletions(prefix, identDict, allIdentifiers) { + var _self = this, + fuzzyMatcher = function (prefix, item) { + return ~item.toLowerCase().indexOf(prefix.toLowerCase()); + }; + + var matches = grep(allIdentifiers, function (item) { + return fuzzyMatcher(prefix, item); + }); + + matches = sortByScore(matches, identDict); -function findCompletions(prefix, allIdentifiers) { - allIdentifiers.sort(); - var startIdx = prefixBinarySearch(allIdentifiers, prefix); - var matches = []; - for (var i = startIdx; i < allIdentifiers.length && allIdentifiers[i].indexOf(prefix) === 0; i++) - matches.push(allIdentifiers[i]); return matches; } +exports.removeDuplicateWords = function(matches) { + // First, sort + matches = matches.sort(); + + for (var i = 1; i < matches.length; ){ + if (matches[i - 1] == matches[i]){ + matches.splice(i, 1); + } else { + i++; + } + } + + return matches; +}; + exports.retrievePrecedingIdentifier = retrievePrecedingIdentifier; exports.retrieveFollowingIdentifier = retrieveFollowingIdentifier; exports.findCompletions = findCompletions; diff --git a/lib/ace/autocomplete/text_completer.js b/lib/ace/autocomplete/text_completer.js index 44a72c9b..d8d5673f 100644 --- a/lib/ace/autocomplete/text_completer.js +++ b/lib/ace/autocomplete/text_completer.js @@ -1,3 +1,33 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + define(function(require, exports, module) { var completeUtil = require("./complete_util"); var SPLIT_REGEX = /[^a-zA-Z_0-9\$]+/; @@ -10,7 +40,7 @@ define(function(require, exports, module) { var text = doc.getValue().trim(); // Determine cursor's word index - var textBefore = doc.getLines(0, pos.row-1).join("\n") + "\n"; + var textBefore = doc.getLines(0, pos.row - 1).join("\n") + "\n"; var currentLine = doc.getLine(pos.row); textBefore += currentLine.substr(0, pos.column); var prefixPosition = textBefore.trim().split(SPLIT_REGEX).length - 1; @@ -27,11 +57,11 @@ define(function(require, exports, module) { if (ident.length === 0) continue; var distance = Math.max(prefixPosition, i) - Math.min(prefixPosition, i); - // Score substracted from 100000 to force descending ordering + // Score substracted from MAX to force descending ordering if (Object.prototype.hasOwnProperty.call(identDict, ident)) - identDict[ident] = Math.max(MAX_SCORE-distance, identDict[ident]); + identDict[ident] = Math.max(MAX_SCORE - distance, identDict[ident]); else - identDict[ident] = MAX_SCORE-distance; + identDict[ident] = MAX_SCORE - distance; } @@ -42,14 +72,6 @@ define(function(require, exports, module) { return identDict; } - function analyze(doc, pos, keywords) { - var line = doc.getLine(pos.row); - var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column); - - var analysisCache = wordDistanceAnalyzer(doc, pos, identifier, keywords); - return analysisCache; - } - completer.complete = function(doc, pos, keywords, callback) { var line = doc.getLine(pos.row); var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column); @@ -58,15 +80,17 @@ define(function(require, exports, module) { if (identifier === "") return callback(null); - var identDict = analyze(doc, pos, keywords); + var identDict = wordDistanceAnalyzer(doc, pos, identifier, keywords); var allIdentifiers = []; for (var ident in identDict) { allIdentifiers.push(ident); } - // find matches based on text in doc - var matches = completeUtil.findCompletions(identifier, allIdentifiers); + allIdentifiers = completeUtil.removeDuplicateWords(allIdentifiers); + + // find fuzzy matches based on text in doc, as well as mode keywords + var matches = completeUtil.findCompletions(identifier, identDict, allIdentifiers); callback(identifier, matches); }; From 6f17611ebf2114b8a242a92eb7b99041e529f790 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Fri, 4 Jan 2013 15:13:13 -0800 Subject: [PATCH 13/31] Fix failing test --- lib/ace/mode/coffee.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/mode/coffee.js b/lib/ace/mode/coffee.js index 18799082..4a6d2201 100644 --- a/lib/ace/mode/coffee.js +++ b/lib/ace/mode/coffee.js @@ -44,7 +44,7 @@ function Mode() { var highlighter = new Rules(); this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$outdent = new Outdent(); - this.$keywordList = new Rules(rules.$keywordList); + this.$keywordList = highlighter.$keywordList; this.foldingRules = new FoldMode(); } From 06c10fb9342e9b92f7e83005de35fa605a306423 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Fri, 4 Jan 2013 15:49:39 -0800 Subject: [PATCH 14/31] One more test fix --- lib/ace/autocomplete.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 705fa978..c5a4b7fc 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -31,13 +31,13 @@ define(function(require, exports, module) { "use strict"; -var EditSession = require("ace/edit_session").EditSession; -var Renderer = require("ace/virtual_renderer").VirtualRenderer; -var UndoManager = require("ace/undomanager").UndoManager; +var EditSession = require("./edit_session").EditSession; +var Renderer = require("./virtual_renderer").VirtualRenderer; +var UndoManager = require("./undomanager").UndoManager; -var dom = require("ace/lib/dom"); -var HashHandler = require("ace/keyboard/hash_handler").HashHandler; -var TextMode = require("ace/mode/text").Mode; +var dom = require("./lib/dom"); +var HashHandler = require("./keyboard/hash_handler").HashHandler; +var TextMode = require("./mode/text").Mode; var WorkerClient = require("./worker/worker_client").WorkerClient; var worker = new WorkerClient(["ace"], "ace/autocomplete/autocomplete_worker", "AutocompleteWorker"); From 7293bb142f25bfffdacea43e09c54332b0f69632 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 7 Jan 2013 17:57:43 +0400 Subject: [PATCH 15/31] fix popup --- lib/ace/autocomplete.js | 363 +++++++++++++++++++++------------------- 1 file changed, 189 insertions(+), 174 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index c5a4b7fc..432fd4e9 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -33,7 +33,8 @@ define(function(require, exports, module) { var EditSession = require("./edit_session").EditSession; var Renderer = require("./virtual_renderer").VirtualRenderer; -var UndoManager = require("./undomanager").UndoManager; +var Range = require("./range").Range; +var event = require("./lib/event"); var dom = require("./lib/dom"); var HashHandler = require("./keyboard/hash_handler").HashHandler; @@ -60,87 +61,17 @@ var Autocomplete = function() { (function() { - - this.$init = function(e) { - var el = dom.createElement("div"); - var popup = new this.$singleLineEditor(el); - document.body.appendChild(el); - el.style.width="200px" - el.style.zIndex="20000" - el.style.background="white" - el.style.border="lightgray solid" - el.style.position="fixed" - el.style.display = "none" - popup.renderer.content.style.cursor="default" - - var noop = function(){}; - - popup.focus = noop; - popup.$isFocused = true; - - popup.renderer.$cursorLayer.restartTimer = noop; - popup.renderer.$cursorLayer.update = noop; - popup.renderer.$cursorLayer.element.style.display = "none"; - - popup.renderer.maxLines = 6 - popup.renderer.$keepTextAreaAtCursor=false - - popup.setHighlightActiveLine(true); - popup.setSession(new EditSession("")); - - popup.on("mousedown", function(e) { - var pos = e.getDocumentPosition(); - popup.moveCursorToPosition(pos); - popup.selection.clearSelection(); - e.stop(); - }); - - /* popup.session.setMode({ - $ - }) */ - - popup.getRow = function() { - var line = this.getCursorPosition().row; - if (line == 0 && !this.getHighlightActiveLine()) - line = -1; - return line; - }; - - popup.setRow = function(line) { - popup.setHighlightActiveLine(line != -1); - popup.gotoLine(line + 1); - }; - - popup.on("click", function(e) { + this.$init = function() { + this.popup = new AcePopup(); + this.popup.on("click", function(e) { this.insertMatch(); }.bind(this)); - - popup.setData = function(list) { - var value = "" - if (list) { - if (typeof list[0] == "string") - value = list.join("\n"); - else - value = list.map(function(x){return x.value}).join("\n"); - } - - this.setValue(value, -1); - }; - - popup.setHighlight = function(re) { - ace.session.highlight(re); - ace.session._emit("changeFrontMarker"); - // select first item - dom.addCssClass(_self.popup.container.getElementsByClassName("ace_autocomplete")[0].childNodes[0], "autocomplete_selected"); - }; - - this.popup = popup; }; - + this.openPopup = function(editor) { if (!this.popup) this.$init(); - + this.popup.setData(this.completions.filtered) var renderer = editor.renderer; @@ -205,19 +136,13 @@ var Autocomplete = function() { var row = this.popup.getRow(); var max = this.popup.session.getLength() - 1; - var choices = this.popup.container.getElementsByClassName("ace_text-layer")[0].childNodes; - if (choices[row]) - dom.removeCssClass(choices[row], "autocomplete_selected"); - switch(where) { case "up": row = row <= 0 ? max : row - 1; break; case "down": row = row >= max ? 0 : row + 1; break; case "start": row = 0; break; case "end": row = max; break } - - if (choices[row]) - dom.addCssClass(choices[row], "autocomplete_selected"); + this.popup.setRow(row); }; @@ -281,97 +206,6 @@ var Autocomplete = function() { }); }; - this.$singleLineEditor = function(el) { - var renderer = new Renderer(el); - el.style.overflow = "hidden"; - renderer.scrollBar.element.style.top = "0"; - renderer.scrollBar.element.style.display = "none"; - renderer.scrollBar.orginalWidth = renderer.scrollBar.width; - renderer.scrollBar.width = 0; - renderer.content.style.height = "auto"; - - renderer.screenToTextCoordinates = function(x, y) { - var pos = this.pixelToScreenCoordinates(x, y); - return this.session.screenToDocumentPosition( - Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)), - Math.max(pos.column, 0) - ); - }; - - renderer.maxLines = 4; - renderer.$computeLayerConfigWithScroll = renderer.$computeLayerConfig; - renderer.$computeLayerConfig = function() { - var config = this.layerConfig; - var height = this.session.getScreenLength() * this.lineHeight; - if (config.height != height) { - var vScroll = height > this.maxLines * this.lineHeight; - - if (vScroll != this.$vScroll) { - if (vScroll) { - this.scrollBar.element.style.display = ""; - this.scrollBar.width = this.scrollBar.orginalWidth; - this.container.style.height = config.height + "px"; - height = config.height; - this.scrollTop = height - this.maxLines * this.lineHeight; - } else { - this.scrollBar.element.style.display = "none"; - this.scrollBar.width = 0; - } - - this.onResize(); - this.$vScroll = vScroll; - } - - if (this.$vScroll) - return renderer.$computeLayerConfigWithScroll(); - - this.container.style.height = height + "px"; - this.scroller.style.height = height + "px"; - this.content.style.height = height + "px"; - this._emit("resize"); - } - - var longestLine = this.$getLongestLine(); - var firstRow = 0; - var lastRow = this.session.getLength(); - - this.scrollTop = 0; - config.width = longestLine; - config.padding = this.$padding; - config.firstRow = 0; - config.firstRowScreen = 0; - config.lastRow = lastRow; - config.lineHeight = this.lineHeight; - config.characterWidth = this.characterWidth; - config.minHeight = height; - config.maxHeight = height; - config.offset = 0; - config.height = height; - - this.$gutterLayer.element.style.marginTop = 0 + "px"; - this.content.style.marginTop = 0 + "px"; - this.content.style.width = longestLine + 2 * this.$padding + "px"; - }; - renderer.isScrollableBy=function(){return false}; - - renderer.setStyle("ace_autocomplete"); - - var Editor = require("ace/editor").Editor; - var editor = new Editor(renderer); - - //var MultiSelect = require("ace/multi_select").MultiSelect; - //new MultiSelect(editor); - //editor.session.setUndoManager(new UndoManager()); - - editor.setHighlightActiveLine(false); - editor.setShowPrintMargin(false); - editor.renderer.setShowGutter(false); - editor.renderer.setHighlightGutterLine(false); - - editor.$mouseHandler.$focusWaitTimout = 0; - - return editor; - }; }).call(Autocomplete.prototype); Autocomplete.startCommand = { @@ -400,6 +234,187 @@ var FilteredList = function(array, mutateData) { }).call(FilteredList.prototype); + +var $singleLineEditor = function(el) { + var renderer = new Renderer(el); + el.style.overflow = "hidden"; + renderer.scrollBar.element.style.top = "0"; + renderer.scrollBar.element.style.display = "none"; + renderer.scrollBar.orginalWidth = renderer.scrollBar.width; + renderer.scrollBar.width = 0; + renderer.content.style.height = "auto"; + + renderer.screenToTextCoordinates = function(x, y) { + var pos = this.pixelToScreenCoordinates(x, y); + return this.session.screenToDocumentPosition( + Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)), + Math.max(pos.column, 0) + ); + }; + + renderer.maxLines = 4; + renderer.$computeLayerConfigWithScroll = renderer.$computeLayerConfig; + renderer.$computeLayerConfig = function() { + var config = this.layerConfig; + var height = this.session.getScreenLength() * this.lineHeight; + if (config.height != height) { + var maxHeight = this.maxLines * this.lineHeight + var vScroll = height > maxHeight; + + if (vScroll != this.$vScroll || this.lineHeight != config.lineHeight) { + if (vScroll) { + this.scrollBar.element.style.display = ""; + this.scrollBar.width = this.scrollBar.orginalWidth; + this.container.style.height = maxHeight + "px"; + height = maxHeight; + this.scrollTop = height - this.maxLines * this.lineHeight; + } else { + this.scrollBar.element.style.display = "none"; + this.scrollBar.width = 0; + } + + this.$size.height = 0; + this.$size.width = 0; + this.onResize(); + this.$vScroll = vScroll; + } + + if (this.$vScroll) + return renderer.$computeLayerConfigWithScroll(); + + this.container.style.height = height + "px"; + this.scroller.style.height = height + "px"; + this.content.style.height = height + "px"; + this._emit("resize"); + } + + var longestLine = this.$getLongestLine(); + var firstRow = 0; + var lastRow = this.session.getLength(); + + this.scrollTop = 0; + config.width = longestLine; + config.padding = this.$padding; + config.firstRow = 0; + config.firstRowScreen = 0; + config.lastRow = lastRow; + config.lineHeight = this.lineHeight; + config.characterWidth = this.characterWidth; + config.minHeight = height; + config.maxHeight = height; + config.offset = 0; + config.height = height; + + this.$gutterLayer.element.style.marginTop = 0 + "px"; + this.content.style.marginTop = 0 + "px"; + this.content.style.width = longestLine + 2 * this.$padding + "px"; + }; + + + var Editor = require("ace/editor").Editor; + var editor = new Editor(renderer); + + editor.setHighlightActiveLine(false); + editor.setShowPrintMargin(false); + editor.renderer.setShowGutter(false); + editor.renderer.setHighlightGutterLine(false); + + editor.$mouseHandler.$focusWaitTimout = 0; + + return editor; +}; + +var AcePopup = function(e) { + var el = dom.createElement("div"); + var popup = new $singleLineEditor(el); + document.body.appendChild(el); + el.style.display = "none"; + popup.renderer.content.style.cursor = "default"; + popup.renderer.setStyle("ace_autocomplete"); + + var noop = function(){}; + + popup.focus = noop; + popup.$isFocused = true; + + popup.renderer.$cursorLayer.restartTimer = noop; + popup.renderer.$cursorLayer.element.style.opacity = 0; + + popup.renderer.maxLines = 8 + popup.renderer.$keepTextAreaAtCursor = false; + + popup.setHighlightActiveLine(true); + popup.setSession(new EditSession("")); + + popup.on("mousedown", function(e) { + var pos = e.getDocumentPosition(); + popup.moveCursorToPosition(pos); + popup.selection.clearSelection(); + e.stop(); + }); + + popup.getRow = function() { + var line = this.getCursorPosition().row; + if (line == 0 && !this.getHighlightActiveLine()) + line = -1; + return line; + }; + + popup.setRow = function(line) { + popup.setHighlightActiveLine(line != -1); + popup.gotoLine(line + 1); + }; + + var hoverMarker = new Range(0,0,0,Infinity); + hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine"); + popup.on("mousemove", function(e) { + var row = e.getDocumentPosition().row; + hoverMarker.start.row = hoverMarker.end.row = row; + popup.session._emit("changeBackMarker"); + }); + event.addListener(popup.container, "mouseout", function(e) { + hoverMarker.start.row = hoverMarker.end.row = -1; + popup.session._emit("changeBackMarker"); + }); + + popup.setData = function(list) { + var value = "" + if (list) { + if (typeof list[0] == "string") + value = list.join("\n"); + else + value = list.map(function(x){return x.value}).join("\n"); + } + + this.setValue(value, -1); + }; + + popup.setHighlight = function(re) { + ace.session.highlight(re); + ace.session._emit("changeFrontMarker"); + }; + + return popup; +}; + +dom.importCssString("\ +.ace_autocomplete.ace-tm .ace_marker-layer .ace_active-line {\ + background-color: #abbffe;\ +}\ +.ace_autocomplete.ace-tm .ace_line-hover {\ + border: 1px solid #abbffe;\ + position: absolute;\ + background: rgb(233,233,232);\ + z-index: 2;\ +}\ +.ace_autocomplete {\ + width: 200px;\ + z-index: 200000;\ + background: #f8f8f8;\ + border: 1px lightgray solid;\ + position: fixed;\ +}"); + exports.Autocomplete = Autocomplete; exports.FilteredList = FilteredList; From 5c1db2dbcca702a0bee2171f5659a303a1e62c4b Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 12 Apr 2013 00:29:24 +0400 Subject: [PATCH 16/31] tweak the popup some more --- demo/kitchen-sink/demo.js | 2 +- lib/ace/autocomplete.js | 234 +++++++++++++----------- lib/ace/mouse/default_gutter_handler.js | 2 +- 3 files changed, 134 insertions(+), 104 deletions(-) diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index 0d8eb5da..1db21a9e 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -559,7 +559,7 @@ ace.commands.bindKey("Tab", function(editor) { editor.execCommand("indent"); }) -var Autocompleter = require("./autocompleter").Autocompleter; +var Autocompleter = require("ace/autocomplete").Autocomplete; Autocompleter.addTo(env.editor) }); diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 432fd4e9..face3889 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -3,7 +3,7 @@ * * Copyright (c) 2012, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -35,6 +35,7 @@ var EditSession = require("./edit_session").EditSession; var Renderer = require("./virtual_renderer").VirtualRenderer; var Range = require("./range").Range; var event = require("./lib/event"); +var lang = require("./lib/lang"); var dom = require("./lib/dom"); var HashHandler = require("./keyboard/hash_handler").HashHandler; @@ -46,7 +47,7 @@ var worker = new WorkerClient(["ace"], "ace/autocomplete/autocomplete_worker", " var mode = new TextMode(); mode.$tokenizer = { getLineTokens: function(line) { - + } }; @@ -59,7 +60,6 @@ var Autocomplete = function() { this.$mousedownListener = this.mousedownListener.bind(this); }; - (function() { this.$init = function() { this.popup = new AcePopup(); @@ -67,7 +67,7 @@ var Autocomplete = function() { this.insertMatch(); }.bind(this)); }; - + this.openPopup = function(editor) { if (!this.popup) this.$init(); @@ -81,19 +81,8 @@ var Autocomplete = function() { pos.top += rect.top - renderer.layerConfig.offset; pos.left += rect.left; pos.left += renderer.$gutterLayer.gutterWidth; - - var el = this.popup.container; - if (pos.top > window.innerHeight / 2 + lineHeight) { - el.style.top = "" - el.style.bottom = window.innerHeight - pos.top + "px"; - } else { - pos.top += lineHeight; - el.style.top = pos.top + "px"; - el.style.bottom = "" - } - el.style.left = pos.left + "px"; - el.style.display = ""; + this.popup.show(pos, lineHeight); renderer.updateText(); }; @@ -105,23 +94,23 @@ var Autocomplete = function() { this.editor.removeEventListener("mousedown", this.changeListener); if (this.popup) - this.popup.container.style.display = "none"; + this.popup.hide(); - this.editor.Autocomplete.activated = false; + this.editor.completer.activated = false; }; this.changeListener = function(e) { - if (this.editor.Autocomplete.activated) + if (this.editor.completer.activated) Autocomplete.startCommand.exec(this.editor); else this.detach(); }; - + this.blurListener = function() { if (document.activeElement != this.editor.textInput.getElement()) this.detach(); }; - + this.mousedownListener = function(e) { var mouseX = e.clientX, mouseY = e.clientY; var newRow = this.editor.renderer.pixelToScreenCoordinates(mouseX, mouseY).row; @@ -142,7 +131,7 @@ var Autocomplete = function() { case "start": row = 0; break; case "end": row = max; break } - + this.popup.setRow(row); }; @@ -161,16 +150,16 @@ var Autocomplete = function() { }; this.commands = { - "up": function(editor) { editor.Autocomplete.goTo("up"); }, - "down": function(editor) { editor.Autocomplete.goTo("down"); }, - "ctrl-up": function(editor) { editor.Autocomplete.goTo("start"); }, - "ctrl-down": function(editor) { editor.Autocomplete.goTo("end"); }, + "up": function(editor) { editor.completer.goTo("up"); }, + "down": function(editor) { editor.completer.goTo("down"); }, + "ctrl-up": function(editor) { editor.completer.goTo("start"); }, + "ctrl-down": function(editor) { editor.completer.goTo("end"); }, - "esc": function(editor) { editor.Autocomplete.detach(); }, - "space": function(editor) { editor.Autocomplete.detach(); editor.insert(" ");}, - "Return": function(editor) { editor.Autocomplete.insertMatch(); }, - "Shift-Return": function(editor) { editor.Autocomplete.insertMatch(true); }, - "Tab": function(editor) { editor.Autocomplete.insertMatch(); } + "esc": function(editor) { editor.completer.detach(); }, + "space": function(editor) { editor.completer.detach(); editor.insert(" ");}, + "Return": function(editor) { editor.completer.insertMatch(); }, + "Shift-Return": function(editor) { editor.completer.insertMatch(true); }, + "Tab": function(editor) { editor.completer.insertMatch(); } }; this.complete = function(editor) { @@ -179,10 +168,10 @@ var Autocomplete = function() { var _self = this; this.editor = editor; - if (editor.Autocomplete != this) { - if (editor.Autocomplete) - editor.Autocomplete.detach(); - editor.Autocomplete = this; + if (editor.completer != this) { + if (editor.completer) + editor.completer.detach(); + editor.completer = this; } editor.keyBinding.addKeyboardHandler(this.keyboardHandler); @@ -198,23 +187,23 @@ var Autocomplete = function() { if (matches.length) { _self.completions = new FilteredList(matches); _self.completions.setFilter("a"); - _self.openPopup(editor); + _self.openPopup(editor); } else { _self.detach(); } }); }; - + }).call(Autocomplete.prototype); Autocomplete.startCommand = { name: "startAutocomplete", exec: function(editor) { - if (!editor.Autocomplete) - editor.Autocomplete = new Autocomplete(); - editor.Autocomplete.complete(editor); - editor.Autocomplete.activated = true; + if (!editor.completer) + editor.completer = new Autocomplete(); + editor.completer.complete(editor); + editor.completer.activated = true; }, bindKey: "Ctrl-Space|Shift-Space|Alt-Space" } @@ -229,9 +218,9 @@ var FilteredList = function(array, mutateData) { }; (function(){ this.setFilter = function(str) { - + }; - + }).call(FilteredList.prototype); @@ -257,15 +246,15 @@ var $singleLineEditor = function(el) { renderer.$computeLayerConfig = function() { var config = this.layerConfig; var height = this.session.getScreenLength() * this.lineHeight; - if (config.height != height) { - var maxHeight = this.maxLines * this.lineHeight - var vScroll = height > maxHeight; - - if (vScroll != this.$vScroll || this.lineHeight != config.lineHeight) { + var maxHeight = this.maxLines * this.lineHeight + var desiredHeight = Math.max(this.lineHeight, Math.min(maxHeight, height)) + var vScroll = height > maxHeight; + if (desiredHeight != this.desiredHeight || vScroll != this.$vScroll) { + if (vScroll != this.$vScroll) { if (vScroll) { this.scrollBar.element.style.display = ""; this.scrollBar.width = this.scrollBar.orginalWidth; - this.container.style.height = maxHeight + "px"; + height = maxHeight; this.scrollTop = height - this.maxLines * this.lineHeight; } else { @@ -275,41 +264,19 @@ var $singleLineEditor = function(el) { this.$size.height = 0; this.$size.width = 0; - this.onResize(); + this.$vScroll = vScroll; } - if (this.$vScroll) - return renderer.$computeLayerConfigWithScroll(); - - this.container.style.height = height + "px"; - this.scroller.style.height = height + "px"; - this.content.style.height = height + "px"; - this._emit("resize"); + this.container.style.height = desiredHeight + "px"; + this.onResize(); + this.$loop.changes = 0 + this.desiredHeight = desiredHeight; + this.scroller.style.overflowX="hidden" } - - var longestLine = this.$getLongestLine(); - var firstRow = 0; - var lastRow = this.session.getLength(); - - this.scrollTop = 0; - config.width = longestLine; - config.padding = this.$padding; - config.firstRow = 0; - config.firstRowScreen = 0; - config.lastRow = lastRow; - config.lineHeight = this.lineHeight; - config.characterWidth = this.characterWidth; - config.minHeight = height; - config.maxHeight = height; - config.offset = 0; - config.height = height; - - this.$gutterLayer.element.style.marginTop = 0 + "px"; - this.content.style.marginTop = 0 + "px"; - this.content.style.width = longestLine + 2 * this.$padding + "px"; + return renderer.$computeLayerConfigWithScroll(); }; - + var Editor = require("ace/editor").Editor; var editor = new Editor(renderer); @@ -331,12 +298,12 @@ var AcePopup = function(e) { el.style.display = "none"; popup.renderer.content.style.cursor = "default"; popup.renderer.setStyle("ace_autocomplete"); - + var noop = function(){}; - + popup.focus = noop; popup.$isFocused = true; - + popup.renderer.$cursorLayer.restartTimer = noop; popup.renderer.$cursorLayer.element.style.opacity = 0; @@ -362,38 +329,92 @@ var AcePopup = function(e) { popup.setRow = function(line) { popup.setHighlightActiveLine(line != -1); - popup.gotoLine(line + 1); + popup.selection.clearSelection(); + popup.moveCursorTo(line, 0 || 0); }; - - var hoverMarker = new Range(0,0,0,Infinity); + + var hoverMarker = new Range(-1,0,-1,Infinity); hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine"); popup.on("mousemove", function(e) { + //if (popup.lastOpened) var row = e.getDocumentPosition().row; hoverMarker.start.row = hoverMarker.end.row = row; popup.session._emit("changeBackMarker"); }); - event.addListener(popup.container, "mouseout", function(e) { + var hideHoverMarker = function() { hoverMarker.start.row = hoverMarker.end.row = -1; popup.session._emit("changeBackMarker"); + }; + event.addListener(popup.container, "mouseout", hideHoverMarker); + popup.on("hide", hideHoverMarker); + popup.on("changeSelection", hideHoverMarker); + popup.on("mousewheel", function(e) { + setTimeout(function() { + popup._signal("mousemove", e); + }) }); - + + popup.data = [] popup.setData = function(list) { - var value = "" - if (list) { - if (typeof list[0] == "string") - value = list.join("\n"); - else - value = list.map(function(x){return x.value}).join("\n"); - } - - this.setValue(value, -1); + popup.data = list || []; + popup.setValue(lang.stringRepeat("\n", list.length), -1); }; - + popup.session.doc.getLength = function() { + return popup.data.length; + }; + popup.session.doc.getLine = function(i) { + var data = popup.data[i]; + if (typeof data == "string") + return data; + return (data && data.value) || ""; + }; + + var bgTokenizer = popup.session.bgTokenizer + bgTokenizer.$tokenizeRow = function(i) { + var data = popup.data[i]; + var tokens = []; + if (!data) + return tokens; + if (typeof data == "string") + data = {type: data, value: data}//return [{type: "", value: data}]; + + tokens.push({type: "", value: data.value}); + if (data.type) { + var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth; + if (data.type.length + data.value.length < maxW - 2) + tokens.push({type: "rightAlignedText", value: data.type}); + } + return tokens; + }; + bgTokenizer.$updateOnChange = noop + + // highlight popup.setHighlight = function(re) { - ace.session.highlight(re); - ace.session._emit("changeFrontMarker"); + popup.session.highlight(re); + popup.session._emit("changeFrontMarker"); }; - + + popup.hide = function() { + this.container.style.display = "none"; + this._signal("hide"); + } + + popup.show = function(pos, lineHeight) { + var el = this.container; + if (pos.top > window.innerHeight / 2 + lineHeight) { + el.style.top = "" + el.style.bottom = window.innerHeight - pos.top + "px"; + } else { + pos.top += lineHeight; + el.style.top = pos.top + "px"; + el.style.bottom = "" + } + + el.style.left = pos.left + "px"; + el.style.display = ""; + + this._signal("show"); + } return popup; }; @@ -404,8 +425,17 @@ dom.importCssString("\ .ace_autocomplete.ace-tm .ace_line-hover {\ border: 1px solid #abbffe;\ position: absolute;\ - background: rgb(233,233,232);\ + background: rgba(233,233,253,0.4);\ z-index: 2;\ + margin-top: -1px;\ +}\ +.ace_rightAlignedText {\ + color: gray;\ + display: inline-block;\ + position: absolute;\ + right: 4px;\ + text-align: right;\ + z-index: -1;\ }\ .ace_autocomplete {\ width: 200px;\ diff --git a/lib/ace/mouse/default_gutter_handler.js b/lib/ace/mouse/default_gutter_handler.js index fc971da6..55fcf108 100644 --- a/lib/ace/mouse/default_gutter_handler.js +++ b/lib/ace/mouse/default_gutter_handler.js @@ -38,7 +38,7 @@ function GutterHandler(mouseHandler) { var gutter = editor.renderer.$gutterLayer; mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) { - if (!editor.isFocused()) + if (!editor.isFocused() || e.getButton() != 0) return; var gutterRegion = gutter.getRegion(e); From dc198344d51d218d0c06f4e51a89ebe98549467a Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 12 Apr 2013 12:09:15 +0400 Subject: [PATCH 17/31] revert changes to worker --- lib/ace/commands/command_manager.js | 4 +- lib/ace/editor.js | 222 ++++++++++++++-------------- lib/ace/mode/golang.js | 88 +++++------ lib/ace/mode/pgsql.js | 42 +++--- lib/ace/mode/text.js | 2 +- lib/ace/worker/mirror.js | 18 +-- lib/ace/worker/worker_client.js | 6 +- 7 files changed, 186 insertions(+), 196 deletions(-) diff --git a/lib/ace/commands/command_manager.js b/lib/ace/commands/command_manager.js index 46a4b604..e8a581ad 100644 --- a/lib/ace/commands/command_manager.js +++ b/lib/ace/commands/command_manager.js @@ -8,7 +8,7 @@ var EventEmitter = require("../lib/event_emitter").EventEmitter; /** * @class CommandManager * - * + * **/ /** @@ -24,7 +24,7 @@ var CommandManager = function(platform, commands) { this.commmandKeyBinding = {}; this.addCommands(commands); - + this.setDefaultHandler("exec", function(e) { return e.command.exec(e.editor, e.args || {}); }); diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 92d218f6..62a4c37f 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -46,16 +46,15 @@ var Search = require("./search").Search; var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; var CommandManager = require("./commands/command_manager").CommandManager; -var Autocomplete = require("./autocomplete").Autocomplete; var defaultCommands = require("./commands/default_commands").commands; var config = require("./config"); /** * * - * The main entry point into the Ace functionality. + * The main entry point into the Ace functionality. * - * The `Editor` manages the [[EditSession]] (which manages [[Document]]s), as well as the [[VirtualRenderer]], which draws everything to the screen. + * The `Editor` manages the [[EditSession]] (which manages [[Document]]s), as well as the [[VirtualRenderer]], which draws everything to the screen. * * Event sessions dealing with the mouse and keyboard are bubbled up from `Document` to the `Editor`, which decides what to do with them. * @class Editor @@ -90,7 +89,6 @@ var Editor = function(renderer, session) { }); this.setSession(session || new EditSession("")); - Autocomplete.addTo(this); config.resetOptions(this); config._emit("editor", this); }; @@ -103,7 +101,7 @@ var Editor = function(renderer, session) { * Sets a new key handler, such as "vim" or "windows". * @param {String} keyboardHandler The new key handler * - * + * **/ this.setKeyboardHandler = function(keyboardHandler) { if (!keyboardHandler) { @@ -121,11 +119,11 @@ var Editor = function(renderer, session) { } }; - /** + /** * Returns the keyboard handler, such as "vim" or "windows". * * @returns {String} - * + * **/ this.getKeyboardHandler = function() { return this.keyBinding.getKeyboardHandler(); @@ -252,7 +250,7 @@ var Editor = function(renderer, session) { return this.session; }; - /** + /** * Sets the current document to `val`. * @param {String} val The new value to set for the document * @param {Number} cursorPos Where to set the new value. `undefined` or 0 is selectAll, -1 is at the document start, and 1 is at the end @@ -273,7 +271,7 @@ var Editor = function(renderer, session) { return val; }; - /** + /** * Returns the current session's content. * * @returns {String} @@ -284,7 +282,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Returns the currently highlighted selection. * @returns {String} The highlighted selection **/ @@ -292,11 +290,11 @@ var Editor = function(renderer, session) { return this.selection; }; - /** + /** * {:VirtualRenderer.onResize} * @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed * - * + * * @related VirtualRenderer.onResize **/ this.resize = function(force) { @@ -313,9 +311,9 @@ var Editor = function(renderer, session) { this.renderer.setTheme(theme); }; - /** + /** * {:VirtualRenderer.getTheme} - * + * * @returns {String} The set theme * @related VirtualRenderer.getTheme **/ @@ -327,14 +325,14 @@ var Editor = function(renderer, session) { * {:VirtualRenderer.setStyle} * @param {String} style A class name * - * + * * @related VirtualRenderer.setStyle **/ this.setStyle = function(style) { this.renderer.setStyle(style); }; - /** + /** * {:VirtualRenderer.unsetStyle} * @related VirtualRenderer.unsetStyle **/ @@ -353,8 +351,8 @@ var Editor = function(renderer, session) { /** * Set a new font size (in pixels) for the editor text. * @param {String} size A font size ( _e.g._ "12px") - * - * + * + * **/ this.setFontSize = function(size) { this.setOption("fontSize", size); @@ -388,7 +386,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Brings the current `textInput` into focus. **/ this.focus = function() { @@ -411,7 +409,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Blurs the current `textInput`. **/ this.blur = function() { @@ -420,9 +418,9 @@ var Editor = function(renderer, session) { /** * Emitted once the editor comes into focus. - * @event focus - * - * + * @event focus + * + * **/ this.onFocus = function() { if (this.$isFocused) @@ -436,8 +434,8 @@ var Editor = function(renderer, session) { /** * Emitted once the editor has been blurred. * @event blur - * - * + * + * **/ this.onBlur = function() { if (!this.$isFocused) @@ -453,12 +451,12 @@ var Editor = function(renderer, session) { }; /** - * Emitted whenever the document is changed. + * Emitted whenever the document is changed. * @event change * @param {Object} e Contains a single property, `data`, which has the delta of changes * * - * + * **/ this.onDocumentChange = function(e) { var delta = e.data; @@ -486,14 +484,14 @@ var Editor = function(renderer, session) { this.onScrollTopChange = function() { this.renderer.scrollToY(this.session.getScrollTop()); }; - + this.onScrollLeftChange = function() { this.renderer.scrollToX(this.session.getScrollLeft()); }; /** * Emitted when the selection changes. - * + * **/ this.onCursorChange = function() { this.$cursorChange(); @@ -549,7 +547,7 @@ var Editor = function(renderer, session) { var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp() this.session.highlight(re); - + this._emit("changeSelection"); }; @@ -629,10 +627,10 @@ var Editor = function(renderer, session) { /** * Emitted when text is copied. - * @event copy + * @event copy * @param {String} text The copied text * - * + * **/ /** * @@ -678,7 +676,7 @@ var Editor = function(renderer, session) { **/ this.onPaste = function(text) { // todo this should change when paste becomes a command - if (this.$readOnly) + if (this.$readOnly) return; this._emit("paste", text); this.insert(text); @@ -692,8 +690,8 @@ var Editor = function(renderer, session) { /** * Inserts `text` into wherever the cursor is pointing. * @param {String} text The new text to add - * - * + * + * **/ this.insert = function(text) { var session = this.session; @@ -793,10 +791,10 @@ var Editor = function(renderer, session) { this.keyBinding.onCommandKey(e, hashId, keyCode); }; - /** + /** * Pass in `true` to enable overwrites in your session, or `false` to disable. If overwrites is enabled, any text you enter will type over any text after it. If the value of `overwrite` changes, this function also emites the `changeOverwrite` event. * @param {Boolean} overwrite Defines wheter or not to set overwrites - * + * * * @related EditSession.setOverwrite **/ @@ -804,7 +802,7 @@ var Editor = function(renderer, session) { this.session.setOverwrite(overwrite); }; - /** + /** * Returns `true` if overwrites are enabled; `false` otherwise. * @returns {Boolean} * @related EditSession.getOverwrite @@ -813,7 +811,7 @@ var Editor = function(renderer, session) { return this.session.getOverwrite(); }; - /** + /** * Sets the value of overwrite to the opposite of whatever it currently is. * @related EditSession.toggleOverwrite **/ @@ -861,7 +859,7 @@ var Editor = function(renderer, session) { /** * Draw selection markers spanning whole line, or only over selected text. Default value is "line" * @param {String} style The new selection style "line"|"text" - * + * **/ this.setSelectionStyle = function(val) { this.setOption("selectionStyle", val); @@ -924,7 +922,7 @@ var Editor = function(renderer, session) { /** * If `showInvisibles` is set to `true`, invisible characters—like spaces or new lines—are show in the editor. * @param {Boolean} showInvisibles Specifies whether or not to show invisible characters - * + * **/ this.setShowInvisibles = function(showInvisibles) { this.renderer.setShowInvisibles(showInvisibles); @@ -949,7 +947,7 @@ var Editor = function(renderer, session) { /** * If `showPrintMargin` is set to `true`, the print margin is shown in the editor. * @param {Boolean} showPrintMargin Specifies whether or not to show the print margin - * + * **/ this.setShowPrintMargin = function(showPrintMargin) { this.renderer.setShowPrintMargin(showPrintMargin); @@ -983,7 +981,7 @@ var Editor = function(renderer, session) { /** * If `readOnly` is true, then the editor is set to read-only mode, and none of the content can change. * @param {Boolean} readOnly Specifies whether the editor can be modified or not - * + * **/ this.setReadOnly = function(readOnly) { this.setOption("readOnly", readOnly); @@ -1000,7 +998,7 @@ var Editor = function(renderer, session) { /** * Specifies whether to use behaviors or not. ["Behaviors" in this case is the auto-pairing of special characters, like quotation marks, parenthesis, or brackets.]{: #BehaviorsDef} * @param {Boolean} enabled Enables or disables behaviors - * + * **/ this.setBehavioursEnabled = function (enabled) { this.setOption("behavioursEnabled", enabled); @@ -1008,7 +1006,7 @@ var Editor = function(renderer, session) { /** * Returns `true` if the behaviors are currently enabled. {:BehaviorsDef} - * + * * @returns {Boolean} **/ this.getBehavioursEnabled = function () { @@ -1019,7 +1017,7 @@ var Editor = function(renderer, session) { * Specifies whether to use wrapping behaviors or not, i.e. automatically wrapping the selection with characters such as brackets * when such a character is typed in. * @param {Boolean} enabled Enables or disables wrapping behaviors - * + * **/ this.setWrapBehavioursEnabled = function (enabled) { this.setOption("wrapBehavioursEnabled", enabled); @@ -1059,7 +1057,7 @@ var Editor = function(renderer, session) { /** * Removes words of text from the editor. A "word" is defined as a string of characters bookended by whitespace. * @param {String} dir The direction of the deletion to occur, either "left" or "right" - * + * **/ this.remove = function(dir) { if (this.selection.isEmpty()){ @@ -1204,7 +1202,7 @@ var Editor = function(renderer, session) { /** * Inserts an indentation into the current cursor position or indents the selected lines. - * + * * @related EditSession.indentRows **/ this.indent = function() { @@ -1311,7 +1309,7 @@ var Editor = function(renderer, session) { } return null; }; - + /** * If the character before the cursor is a number, this functions changes its value by `amount`. * @param {Number} amount The value to change the numeral by (can be negative to decrease value) @@ -1336,14 +1334,14 @@ var Editor = function(renderer, session) { var t = parseFloat(nr.value); t *= Math.pow(10, decimals); - + if(fp !== nr.end && column < fp){ amount *= Math.pow(10, nr.end - column - 1); } else { amount *= Math.pow(10, nr.end - column); } - + t += amount; t /= Math.pow(10, decimals); var nnr = t.toFixed(decimals); @@ -1358,8 +1356,8 @@ var Editor = function(renderer, session) { } } }; - - /** + + /** * Removes all the lines in the current selection * @related EditSession.remove **/ @@ -1390,12 +1388,12 @@ var Editor = function(renderer, session) { var endPoint = doc.insert(point, doc.getTextRange(range), false); range.start = point; range.end = endPoint; - + sel.setSelectionRange(range, reverse) } }; - - /** + + /** * Shifts all the selected lines down one row. * * @returns {Number} On success, it returns -1. @@ -1407,7 +1405,7 @@ var Editor = function(renderer, session) { }); }; - /** + /** * Shifts all the selected lines up one row. * @returns {Number} On success, it returns -1. * @related EditSession.moveLinesDown @@ -1418,14 +1416,14 @@ var Editor = function(renderer, session) { }); }; - /** + /** * Moves a range of text from the given range to the given position. `toPosition` is an object that looks like this: * ```json * { row: newRowLocation, column: newColumnLocation } * ``` * @param {Range} fromRange The range of text you want moved within the document * @param {Object} toPosition The location (row and column) where you want to move the text to - * + * * @returns {Range} The new range where the text was moved to. * @related EditSession.moveText **/ @@ -1433,10 +1431,10 @@ var Editor = function(renderer, session) { return this.session.moveText(range, toPosition); }; - /** + /** * Copies all the selected lines up one row. * @returns {Number} On success, returns 0. - * + * **/ this.copyLinesUp = function() { this.$moveLines(function(firstRow, lastRow) { @@ -1445,7 +1443,7 @@ var Editor = function(renderer, session) { }); }; - /** + /** * Copies all the selected lines down one row. * @returns {Number} On success, returns the number of new rows added; in other words, `lastRow - firstRow + 1`. * @related EditSession.duplicateLines @@ -1460,7 +1458,7 @@ var Editor = function(renderer, session) { /** * Executes a specific function, which can be anything that manipulates selected lines, such as copying them, duplicating them, or shifting them. * @param {Function} mover A method to call on each selected row - * + * * **/ this.$moveLines = function(mover) { @@ -1468,7 +1466,7 @@ var Editor = function(renderer, session) { if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) { var range = selection.toOrientedRange(); var rows = this.$getSelectedRows(range); - var linesMoved = mover.call(this, rows.first, rows.last); + var linesMoved = mover.call(this, rows.first, rows.last); range.moveBy(linesMoved, 0); selection.fromOrientedRange(range); } else { @@ -1486,14 +1484,14 @@ var Editor = function(renderer, session) { first = rows.end.row; else break; - } + } i++; var linesMoved = mover.call(this, first, last); while (rangeIndex >= i) { ranges[rangeIndex].moveBy(linesMoved, 0); rangeIndex--; - } + } } selection.fromOrientedRange(selection.ranges[0]); selection.rangeList.attach(this.session); @@ -1530,7 +1528,7 @@ var Editor = function(renderer, session) { this.renderer.hideComposition(); }; - /** + /** * {:VirtualRenderer.getFirstVisibleRow} * * @returns {Number} @@ -1540,7 +1538,7 @@ var Editor = function(renderer, session) { return this.renderer.getFirstVisibleRow(); }; - /** + /** * {:VirtualRenderer.getLastVisibleRow} * * @returns {Number} @@ -1553,7 +1551,7 @@ var Editor = function(renderer, session) { /** * Indicates if the row is currently visible on the screen. * @param {Number} row The row to check - * + * * @returns {Boolean} **/ this.isRowVisible = function(row) { @@ -1563,8 +1561,8 @@ var Editor = function(renderer, session) { /** * Indicates if the entire row is currently visible on the screen. * @param {Number} row The row to check - * - * + * + * * @returns {Boolean} **/ this.isRowFullyVisible = function(row) { @@ -1646,7 +1644,7 @@ var Editor = function(renderer, session) { this.$moveByPage(-1); }; - /** + /** * Moves the editor to the specified row. * @related VirtualRenderer.scrollToRow **/ @@ -1654,14 +1652,14 @@ var Editor = function(renderer, session) { this.renderer.scrollToRow(row); }; - /** + /** * Scrolls to a line. If `center` is `true`, it puts the line in middle of screen (or attempts to). * @param {Number} line The line to scroll to - * @param {Boolean} center If `true` + * @param {Boolean} center If `true` * @param {Boolean} animate If `true` animates scrolling * @param {Function} callback Function to be called when the animation has finished * - * + * * @related VirtualRenderer.scrollToLine **/ this.scrollToLine = function(line, center, animate, callback) { @@ -1680,9 +1678,9 @@ var Editor = function(renderer, session) { this.renderer.alignCursor(pos, 0.5); }; - /** + /** * Gets the current position of the cursor. - * @returns {Object} An object that looks something like this: + * @returns {Object} An object that looks something like this: * * ```json * { row: currRow, column: currCol } @@ -1694,7 +1692,7 @@ var Editor = function(renderer, session) { return this.selection.getCursor(); }; - /** + /** * Returns the screen position of the cursor. * @returns {Number} * @related EditSession.documentToScreenPosition @@ -1703,7 +1701,7 @@ var Editor = function(renderer, session) { return this.session.documentToScreenPosition(this.getCursorPosition()); }; - /** + /** * {:Selection.getRange} * @returns {Range} * @related Selection.getRange @@ -1713,7 +1711,7 @@ var Editor = function(renderer, session) { }; - /** + /** * Selects all the text in editor. * @related Selection.selectAll **/ @@ -1723,7 +1721,7 @@ var Editor = function(renderer, session) { this.$blockScrolling -= 1; }; - /** + /** * {:Selection.clearSelection} * @related Selection.clearSelection **/ @@ -1731,7 +1729,7 @@ var Editor = function(renderer, session) { this.selection.clearSelection(); }; - /** + /** * Moves the cursor to the specified row and column. Note that this does not de-select the current selection. * @param {Number} row The new row number * @param {Number} column The new column number @@ -1743,10 +1741,10 @@ var Editor = function(renderer, session) { this.selection.moveCursorTo(row, column); }; - /** + /** * Moves the cursor to the position indicated by `pos.row` and `pos.column`. * @param {Object} pos An object with two properties, row and column - * + * * * @related Selection.moveCursorToPosition **/ @@ -1754,7 +1752,7 @@ var Editor = function(renderer, session) { this.selection.moveCursorToPosition(pos); }; - /** + /** * Moves the cursor's row and column to the next matching bracket. * **/ @@ -1774,7 +1772,7 @@ var Editor = function(renderer, session) { if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2) range = this.session.getBracketRange(pos); } - + pos = range && range.cursor || pos; if (pos) { if (select) { @@ -1794,7 +1792,7 @@ var Editor = function(renderer, session) { * @param {Number} lineNumber The line number to go to * @param {Number} column A column number to go to * @param {Boolean} animate If `true` animates scolling - * + * **/ this.gotoLine = function(lineNumber, column, animate) { this.selection.clearSelection(); @@ -1810,7 +1808,7 @@ var Editor = function(renderer, session) { this.scrollToLine(lineNumber - 1, true, animate); }; - /** + /** * Moves the cursor to the specified row and column. Note that this does de-select the current selection. * @param {Number} row The new row number * @param {Number} column The new column number @@ -1826,8 +1824,8 @@ var Editor = function(renderer, session) { /** * Moves the cursor up in the document the specified number of times. Note that this does de-select the current selection. * @param {Number} times The number of times to change navigation - * - * + * + * **/ this.navigateUp = function(times) { if (this.selection.isMultiLine() && !this.selection.isBackwards()) { @@ -1842,8 +1840,8 @@ var Editor = function(renderer, session) { /** * Moves the cursor down in the document the specified number of times. Note that this does de-select the current selection. * @param {Number} times The number of times to change navigation - * - * + * + * **/ this.navigateDown = function(times) { if (this.selection.isMultiLine() && this.selection.isBackwards()) { @@ -1858,8 +1856,8 @@ var Editor = function(renderer, session) { /** * Moves the cursor left in the document the specified number of times. Note that this does de-select the current selection. * @param {Number} times The number of times to change navigation - * - * + * + * **/ this.navigateLeft = function(times) { if (!this.selection.isEmpty()) { @@ -1878,8 +1876,8 @@ var Editor = function(renderer, session) { /** * Moves the cursor right in the document the specified number of times. Note that this does de-select the current selection. * @param {Number} times The number of times to change navigation - * - * + * + * **/ this.navigateRight = function(times) { if (!this.selection.isEmpty()) { @@ -1896,7 +1894,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the start of the current line. Note that this does de-select the current selection. **/ this.navigateLineStart = function() { @@ -1905,7 +1903,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the end of the current line. Note that this does de-select the current selection. **/ this.navigateLineEnd = function() { @@ -1914,7 +1912,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the end of the current file. Note that this does de-select the current selection. **/ this.navigateFileEnd = function() { @@ -1925,7 +1923,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the start of the current file. Note that this does de-select the current selection. **/ this.navigateFileStart = function() { @@ -1936,7 +1934,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the word immediately to the right of the current position. Note that this does de-select the current selection. **/ this.navigateWordRight = function() { @@ -1945,7 +1943,7 @@ var Editor = function(renderer, session) { }; /** - * + * * Moves the cursor to the word immediately to the left of the current position. Note that this does de-select the current selection. **/ this.navigateWordLeft = function() { @@ -2026,7 +2024,7 @@ var Editor = function(renderer, session) { } }; - /** + /** * {:Search.getOptions} For more information on `options`, see [[Search `Search`]]. * @related Search.getOptions * @returns {Object} @@ -2035,7 +2033,7 @@ var Editor = function(renderer, session) { return this.$search.getOptions(); }; - /** + /** * Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]]. * @param {String} needle The text to search for (optional) * @param {Object} options An object defining various search properties @@ -2083,7 +2081,7 @@ var Editor = function(renderer, session) { this.selection.setRange(range); }; - /** + /** * Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]]. * @param {Object} options search options * @param {Boolean} animate If `true` animate scrolling @@ -2095,7 +2093,7 @@ var Editor = function(renderer, session) { this.find({skipCurrent: true, backwards: false}, options, animate); }; - /** + /** * Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]]. * @param {Object} options search options * @param {Boolean} animate If `true` animate scrolling @@ -2119,7 +2117,7 @@ var Editor = function(renderer, session) { this.renderer.animateScrolling(scrollTop); }; - /** + /** * {:UndoManager.undo} * @related UndoManager.undo **/ @@ -2130,7 +2128,7 @@ var Editor = function(renderer, session) { this.renderer.scrollCursorIntoView(null, 0.5); }; - /** + /** * {:UndoManager.redo} * @related UndoManager.redo **/ @@ -2141,8 +2139,8 @@ var Editor = function(renderer, session) { this.renderer.scrollCursorIntoView(null, 0.5); }; - /** - * + /** + * * Cleans up the entire editor. **/ this.destroy = function() { diff --git a/lib/ace/mode/golang.js b/lib/ace/mode/golang.js index 72262022..91b3e085 100644 --- a/lib/ace/mode/golang.js +++ b/lib/ace/mode/golang.js @@ -1,58 +1,58 @@ define(function(require, exports, module) { - var oop = require("../lib/oop"); - var TextMode = require("./text").Mode; - var Tokenizer = require("../tokenizer").Tokenizer; - var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules; - var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; - var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; - var CStyleFoldMode = require("./folding/cstyle").FoldMode; +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules; +var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; +var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; +var CStyleFoldMode = require("./folding/cstyle").FoldMode; + +var Mode = function() { + var highlighter = new GolangHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; + this.$outdent = new MatchingBraceOutdent(); + this.foldingRules = new CStyleFoldMode(); +}; +oop.inherits(Mode, TextMode); + +(function() { - var Mode = function() { - var highlighter = new GolangHighlightRules(); - - this.$tokenizer = new Tokenizer(highlighter.getRules()); - this.$keywordList = highlighter.$keywordList; - this.$outdent = new MatchingBraceOutdent(); - this.foldingRules = new CStyleFoldMode(); - }; - oop.inherits(Mode, TextMode); - - (function() { - this.lineCommentStart = "//"; this.blockComment = {start: "/*", end: "*/"}; - this.getNextLineIndent = function(state, line, tab) { - var indent = this.$getIndent(line); + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); - var tokenizedLine = this.$tokenizer.getLineTokens(line, state); - var tokens = tokenizedLine.tokens; - var endState = tokenizedLine.state; - - if (tokens.length && tokens[tokens.length-1].type == "comment") { - return indent; - } - - if (state == "start") { - var match = line.match(/^.*[\{\(\[]\s*$/); - if (match) { - indent += tab; - } - } + var tokenizedLine = this.$tokenizer.getLineTokens(line, state); + var tokens = tokenizedLine.tokens; + var endState = tokenizedLine.state; + if (tokens.length && tokens[tokens.length-1].type == "comment") { return indent; - };//end getNextLineIndent + } + + if (state == "start") { + var match = line.match(/^.*[\{\(\[]\s*$/); + if (match) { + indent += tab; + } + } - this.checkOutdent = function(state, line, input) { - return this.$outdent.checkOutdent(line, input); - }; + return indent; + };//end getNextLineIndent - this.autoOutdent = function(state, doc, row) { - this.$outdent.autoOutdent(doc, row); - }; + this.checkOutdent = function(state, line, input) { + return this.$outdent.checkOutdent(line, input); + }; - }).call(Mode.prototype); + this.autoOutdent = function(state, doc, row) { + this.$outdent.autoOutdent(doc, row); + }; - exports.Mode = Mode; +}).call(Mode.prototype); + +exports.Mode = Mode; }); diff --git a/lib/ace/mode/pgsql.js b/lib/ace/mode/pgsql.js index 4ebaec80..2398ea83 100755 --- a/lib/ace/mode/pgsql.js +++ b/lib/ace/mode/pgsql.js @@ -30,33 +30,33 @@ define(function(require, exports, module) { - var oop = require("../lib/oop"); - var TextMode = require("../mode/text").Mode; - var Tokenizer = require("../tokenizer").Tokenizer; - var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules; - var Range = require("../range").Range; +var oop = require("../lib/oop"); +var TextMode = require("../mode/text").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules; +var Range = require("../range").Range; - var Mode = function() { - var highlighter = new PgsqlHighlightRules(); - - this.$tokenizer = new Tokenizer(highlighter.getRules()); - this.$keywordList = highlighter.$keywordList; - }; - oop.inherits(Mode, TextMode); +var Mode = function() { + var highlighter = new PgsqlHighlightRules(); - (function() { + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; +}; +oop.inherits(Mode, TextMode); + +(function() { this.lineCommentStart = "--"; this.blockComment = {start: "/*", end: "*/"}; - this.getNextLineIndent = function(state, line, tab) { - if (state == "start" || state == "keyword.statementEnd") { - return ""; - } else { - return this.$getIndent(line); // Keep whatever indent the previous line has - } + this.getNextLineIndent = function(state, line, tab) { + if (state == "start" || state == "keyword.statementEnd") { + return ""; + } else { + return this.$getIndent(line); // Keep whatever indent the previous line has } + } - }).call(Mode.prototype); +}).call(Mode.prototype); - exports.Mode = Mode; +exports.Mode = Mode; }); diff --git a/lib/ace/mode/text.js b/lib/ace/mode/text.js index 6bf36018..1af608a5 100644 --- a/lib/ace/mode/text.js +++ b/lib/ace/mode/text.js @@ -347,7 +347,7 @@ var Mode = function() { } } } - } + } } this.completionKeywords = completionKeywords; } diff --git a/lib/ace/worker/mirror.js b/lib/ace/worker/mirror.js index dd804865..c521f8fd 100644 --- a/lib/ace/worker/mirror.js +++ b/lib/ace/worker/mirror.js @@ -7,34 +7,26 @@ var lang = require("../lib/lang"); var Mirror = exports.Mirror = function(sender) { this.sender = sender; var doc = this.doc = new Document(""); - this.data = {}; - + var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this)); - + var _self = this; sender.on("change", function(e) { doc.applyDeltas(e.data); - if (_self.$defer) - deferredUpdate.schedule(_self.$timeout); + deferredUpdate.schedule(_self.$timeout); }); }; (function() { this.$timeout = 500; - this.$defer = true; - + this.setTimeout = function(timeout) { this.$timeout = timeout; }; - this.setDeferredUpdate = function(defer) { - this.$defer = defer; - }; - - this.setValue = function(value, data) { + this.setValue = function(value) { this.doc.setValue(value); - this.data = data; this.deferredUpdate.schedule(this.$timeout); }; diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index 91dc6ca5..5a682fe5 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -144,12 +144,12 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) { catch(ex) {} }; - this.attachToDocument = function(doc, data, ignore) { - if (this.$doc && !ignore) + this.attachToDocument = function(doc) { + if(this.$doc) this.terminate(); this.$doc = doc; - this.call("setValue", [doc.getValue(), data]); + this.call("setValue", [doc.getValue()]); doc.on("change", this.changeListener); }; From 68ebf08e8c8d8f5c536cfc52e50d69e726a495d9 Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 12 Apr 2013 14:03:19 +0400 Subject: [PATCH 18/31] cleanup --- lib/ace/autocomplete.js | 254 +---------------- lib/ace/autocomplete/popup.js | 264 ++++++++++++++++++ .../language_tools.js} | 50 +--- lib/ace/snippets.js | 1 - 4 files changed, 279 insertions(+), 290 deletions(-) create mode 100644 lib/ace/autocomplete/popup.js rename lib/ace/{autocomplete/autocomplete_worker.js => ext/language_tools.js} (57%) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index face3889..77f0f5ae 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -31,25 +31,9 @@ define(function(require, exports, module) { "use strict"; -var EditSession = require("./edit_session").EditSession; -var Renderer = require("./virtual_renderer").VirtualRenderer; var Range = require("./range").Range; -var event = require("./lib/event"); -var lang = require("./lib/lang"); - -var dom = require("./lib/dom"); var HashHandler = require("./keyboard/hash_handler").HashHandler; -var TextMode = require("./mode/text").Mode; - -var WorkerClient = require("./worker/worker_client").WorkerClient; -var worker = new WorkerClient(["ace"], "ace/autocomplete/autocomplete_worker", "AutocompleteWorker"); - -var mode = new TextMode(); -mode.$tokenizer = { - getLineTokens: function(line) { - - } -}; +var AcePopup = require("./autocomplete/popup").AcePopup; var Autocomplete = function() { this.keyboardHandler = new HashHandler(); @@ -62,7 +46,7 @@ var Autocomplete = function() { (function() { this.$init = function() { - this.popup = new AcePopup(); + this.popup = new AcePopup(document.body || document.documentElement); this.popup.on("click", function(e) { this.insertMatch(); }.bind(this)); @@ -150,13 +134,13 @@ var Autocomplete = function() { }; this.commands = { - "up": function(editor) { editor.completer.goTo("up"); }, - "down": function(editor) { editor.completer.goTo("down"); }, - "ctrl-up": function(editor) { editor.completer.goTo("start"); }, - "ctrl-down": function(editor) { editor.completer.goTo("end"); }, + "Up": function(editor) { editor.completer.goTo("up"); }, + "Down": function(editor) { editor.completer.goTo("down"); }, + "Ctrl-Up": function(editor) { editor.completer.goTo("start"); }, + "Ctrl-Down": function(editor) { editor.completer.goTo("end"); }, - "esc": function(editor) { editor.completer.detach(); }, - "space": function(editor) { editor.completer.detach(); editor.insert(" ");}, + "Esc": function(editor) { editor.completer.detach(); }, + "Space": function(editor) { editor.completer.detach(); editor.insert(" ");}, "Return": function(editor) { editor.completer.insertMatch(); }, "Shift-Return": function(editor) { editor.completer.insertMatch(true); }, "Tab": function(editor) { editor.completer.insertMatch(); } @@ -223,228 +207,6 @@ var FilteredList = function(array, mutateData) { }).call(FilteredList.prototype); - -var $singleLineEditor = function(el) { - var renderer = new Renderer(el); - el.style.overflow = "hidden"; - renderer.scrollBar.element.style.top = "0"; - renderer.scrollBar.element.style.display = "none"; - renderer.scrollBar.orginalWidth = renderer.scrollBar.width; - renderer.scrollBar.width = 0; - renderer.content.style.height = "auto"; - - renderer.screenToTextCoordinates = function(x, y) { - var pos = this.pixelToScreenCoordinates(x, y); - return this.session.screenToDocumentPosition( - Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)), - Math.max(pos.column, 0) - ); - }; - - renderer.maxLines = 4; - renderer.$computeLayerConfigWithScroll = renderer.$computeLayerConfig; - renderer.$computeLayerConfig = function() { - var config = this.layerConfig; - var height = this.session.getScreenLength() * this.lineHeight; - var maxHeight = this.maxLines * this.lineHeight - var desiredHeight = Math.max(this.lineHeight, Math.min(maxHeight, height)) - var vScroll = height > maxHeight; - if (desiredHeight != this.desiredHeight || vScroll != this.$vScroll) { - if (vScroll != this.$vScroll) { - if (vScroll) { - this.scrollBar.element.style.display = ""; - this.scrollBar.width = this.scrollBar.orginalWidth; - - height = maxHeight; - this.scrollTop = height - this.maxLines * this.lineHeight; - } else { - this.scrollBar.element.style.display = "none"; - this.scrollBar.width = 0; - } - - this.$size.height = 0; - this.$size.width = 0; - - this.$vScroll = vScroll; - } - - this.container.style.height = desiredHeight + "px"; - this.onResize(); - this.$loop.changes = 0 - this.desiredHeight = desiredHeight; - this.scroller.style.overflowX="hidden" - } - return renderer.$computeLayerConfigWithScroll(); - }; - - - var Editor = require("ace/editor").Editor; - var editor = new Editor(renderer); - - editor.setHighlightActiveLine(false); - editor.setShowPrintMargin(false); - editor.renderer.setShowGutter(false); - editor.renderer.setHighlightGutterLine(false); - - editor.$mouseHandler.$focusWaitTimout = 0; - - return editor; -}; - -var AcePopup = function(e) { - var el = dom.createElement("div"); - var popup = new $singleLineEditor(el); - document.body.appendChild(el); - el.style.display = "none"; - popup.renderer.content.style.cursor = "default"; - popup.renderer.setStyle("ace_autocomplete"); - - var noop = function(){}; - - popup.focus = noop; - popup.$isFocused = true; - - popup.renderer.$cursorLayer.restartTimer = noop; - popup.renderer.$cursorLayer.element.style.opacity = 0; - - popup.renderer.maxLines = 8 - popup.renderer.$keepTextAreaAtCursor = false; - - popup.setHighlightActiveLine(true); - popup.setSession(new EditSession("")); - - popup.on("mousedown", function(e) { - var pos = e.getDocumentPosition(); - popup.moveCursorToPosition(pos); - popup.selection.clearSelection(); - e.stop(); - }); - - popup.getRow = function() { - var line = this.getCursorPosition().row; - if (line == 0 && !this.getHighlightActiveLine()) - line = -1; - return line; - }; - - popup.setRow = function(line) { - popup.setHighlightActiveLine(line != -1); - popup.selection.clearSelection(); - popup.moveCursorTo(line, 0 || 0); - }; - - var hoverMarker = new Range(-1,0,-1,Infinity); - hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine"); - popup.on("mousemove", function(e) { - //if (popup.lastOpened) - var row = e.getDocumentPosition().row; - hoverMarker.start.row = hoverMarker.end.row = row; - popup.session._emit("changeBackMarker"); - }); - var hideHoverMarker = function() { - hoverMarker.start.row = hoverMarker.end.row = -1; - popup.session._emit("changeBackMarker"); - }; - event.addListener(popup.container, "mouseout", hideHoverMarker); - popup.on("hide", hideHoverMarker); - popup.on("changeSelection", hideHoverMarker); - popup.on("mousewheel", function(e) { - setTimeout(function() { - popup._signal("mousemove", e); - }) - }); - - popup.data = [] - popup.setData = function(list) { - popup.data = list || []; - popup.setValue(lang.stringRepeat("\n", list.length), -1); - }; - popup.session.doc.getLength = function() { - return popup.data.length; - }; - popup.session.doc.getLine = function(i) { - var data = popup.data[i]; - if (typeof data == "string") - return data; - return (data && data.value) || ""; - }; - - var bgTokenizer = popup.session.bgTokenizer - bgTokenizer.$tokenizeRow = function(i) { - var data = popup.data[i]; - var tokens = []; - if (!data) - return tokens; - if (typeof data == "string") - data = {type: data, value: data}//return [{type: "", value: data}]; - - tokens.push({type: "", value: data.value}); - if (data.type) { - var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth; - if (data.type.length + data.value.length < maxW - 2) - tokens.push({type: "rightAlignedText", value: data.type}); - } - return tokens; - }; - bgTokenizer.$updateOnChange = noop - - // highlight - popup.setHighlight = function(re) { - popup.session.highlight(re); - popup.session._emit("changeFrontMarker"); - }; - - popup.hide = function() { - this.container.style.display = "none"; - this._signal("hide"); - } - - popup.show = function(pos, lineHeight) { - var el = this.container; - if (pos.top > window.innerHeight / 2 + lineHeight) { - el.style.top = "" - el.style.bottom = window.innerHeight - pos.top + "px"; - } else { - pos.top += lineHeight; - el.style.top = pos.top + "px"; - el.style.bottom = "" - } - - el.style.left = pos.left + "px"; - el.style.display = ""; - - this._signal("show"); - } - return popup; -}; - -dom.importCssString("\ -.ace_autocomplete.ace-tm .ace_marker-layer .ace_active-line {\ - background-color: #abbffe;\ -}\ -.ace_autocomplete.ace-tm .ace_line-hover {\ - border: 1px solid #abbffe;\ - position: absolute;\ - background: rgba(233,233,253,0.4);\ - z-index: 2;\ - margin-top: -1px;\ -}\ -.ace_rightAlignedText {\ - color: gray;\ - display: inline-block;\ - position: absolute;\ - right: 4px;\ - text-align: right;\ - z-index: -1;\ -}\ -.ace_autocomplete {\ - width: 200px;\ - z-index: 200000;\ - background: #f8f8f8;\ - border: 1px lightgray solid;\ - position: fixed;\ -}"); - exports.Autocomplete = Autocomplete; exports.FilteredList = FilteredList; diff --git a/lib/ace/autocomplete/popup.js b/lib/ace/autocomplete/popup.js new file mode 100644 index 00000000..8fe2eb56 --- /dev/null +++ b/lib/ace/autocomplete/popup.js @@ -0,0 +1,264 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var EditSession = require("./edit_session").EditSession; +var Renderer = require("./virtual_renderer").VirtualRenderer; +var event = require("./lib/event"); +var lang = require("./lib/lang"); +var dom = require("./lib/dom"); + +var $singleLineEditor = function(el) { + var renderer = new Renderer(el); + el.style.overflow = "hidden"; + renderer.scrollBar.element.style.top = "0"; + renderer.scrollBar.element.style.display = "none"; + renderer.scrollBar.orginalWidth = renderer.scrollBar.width; + renderer.scrollBar.width = 0; + renderer.content.style.height = "auto"; + + renderer.screenToTextCoordinates = function(x, y) { + var pos = this.pixelToScreenCoordinates(x, y); + return this.session.screenToDocumentPosition( + Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)), + Math.max(pos.column, 0) + ); + }; + + renderer.maxLines = 4; + renderer.$computeLayerConfigWithScroll = renderer.$computeLayerConfig; + renderer.$computeLayerConfig = function() { + var config = this.layerConfig; + var height = this.session.getScreenLength() * this.lineHeight; + var maxHeight = this.maxLines * this.lineHeight + var desiredHeight = Math.max(this.lineHeight, Math.min(maxHeight, height)) + var vScroll = height > maxHeight; + if (desiredHeight != this.desiredHeight || vScroll != this.$vScroll) { + if (vScroll != this.$vScroll) { + if (vScroll) { + this.scrollBar.element.style.display = ""; + this.scrollBar.width = this.scrollBar.orginalWidth; + + height = maxHeight; + this.scrollTop = height - this.maxLines * this.lineHeight; + } else { + this.scrollBar.element.style.display = "none"; + this.scrollBar.width = 0; + } + + this.$size.height = 0; + this.$size.width = 0; + + this.$vScroll = vScroll; + } + + this.container.style.height = desiredHeight + "px"; + this.onResize(); + this.$loop.changes = 0 + this.desiredHeight = desiredHeight; + this.scroller.style.overflowX="hidden" + } + return renderer.$computeLayerConfigWithScroll(); + }; + + + var Editor = require("ace/editor").Editor; + var editor = new Editor(renderer); + + editor.setHighlightActiveLine(false); + editor.setShowPrintMargin(false); + editor.renderer.setShowGutter(false); + editor.renderer.setHighlightGutterLine(false); + + editor.$mouseHandler.$focusWaitTimout = 0; + + return editor; +}; + +var AcePopup = function(parentNode) { + var el = dom.createElement("div"); + var popup = new $singleLineEditor(el); + if (parentNode) + parentNode.appendChild(el); + el.style.display = "none"; + popup.renderer.content.style.cursor = "default"; + popup.renderer.setStyle("ace_autocomplete"); + + var noop = function(){}; + + popup.focus = noop; + popup.$isFocused = true; + + popup.renderer.$cursorLayer.restartTimer = noop; + popup.renderer.$cursorLayer.element.style.opacity = 0; + + popup.renderer.maxLines = 8 + popup.renderer.$keepTextAreaAtCursor = false; + + popup.setHighlightActiveLine(true); + popup.setSession(new EditSession("")); + + popup.on("mousedown", function(e) { + var pos = e.getDocumentPosition(); + popup.moveCursorToPosition(pos); + popup.selection.clearSelection(); + e.stop(); + }); + + popup.getRow = function() { + var line = this.getCursorPosition().row; + if (line == 0 && !this.getHighlightActiveLine()) + line = -1; + return line; + }; + + popup.setRow = function(line) { + popup.setHighlightActiveLine(line != -1); + popup.selection.clearSelection(); + popup.moveCursorTo(line, 0 || 0); + }; + + var hoverMarker = new Range(-1,0,-1,Infinity); + hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine"); + popup.on("mousemove", function(e) { + //if (popup.lastOpened) + var row = e.getDocumentPosition().row; + hoverMarker.start.row = hoverMarker.end.row = row; + popup.session._emit("changeBackMarker"); + }); + var hideHoverMarker = function() { + hoverMarker.start.row = hoverMarker.end.row = -1; + popup.session._emit("changeBackMarker"); + }; + event.addListener(popup.container, "mouseout", hideHoverMarker); + popup.on("hide", hideHoverMarker); + popup.on("changeSelection", hideHoverMarker); + popup.on("mousewheel", function(e) { + setTimeout(function() { + popup._signal("mousemove", e); + }) + }); + + popup.data = [] + popup.setData = function(list) { + popup.data = list || []; + popup.setValue(lang.stringRepeat("\n", list.length), -1); + }; + popup.session.doc.getLength = function() { + return popup.data.length; + }; + popup.session.doc.getLine = function(i) { + var data = popup.data[i]; + if (typeof data == "string") + return data; + return (data && data.value) || ""; + }; + + var bgTokenizer = popup.session.bgTokenizer + bgTokenizer.$tokenizeRow = function(i) { + var data = popup.data[i]; + var tokens = []; + if (!data) + return tokens; + if (typeof data == "string") + data = {type: data, value: data}//return [{type: "", value: data}]; + + tokens.push({type: "", value: data.value}); + if (data.type) { + var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth; + if (data.type.length + data.value.length < maxW - 2) + tokens.push({type: "rightAlignedText", value: data.type}); + } + return tokens; + }; + bgTokenizer.$updateOnChange = noop + + // highlight + popup.setHighlight = function(re) { + popup.session.highlight(re); + popup.session._emit("changeFrontMarker"); + }; + + popup.hide = function() { + this.container.style.display = "none"; + this._signal("hide"); + } + + popup.show = function(pos, lineHeight) { + var el = this.container; + if (pos.top > window.innerHeight / 2 + lineHeight) { + el.style.top = "" + el.style.bottom = window.innerHeight - pos.top + "px"; + } else { + pos.top += lineHeight; + el.style.top = pos.top + "px"; + el.style.bottom = "" + } + + el.style.left = pos.left + "px"; + el.style.display = ""; + + this._signal("show"); + } + return popup; +}; + +dom.importCssString("\ +.ace_autocomplete.ace-tm .ace_marker-layer .ace_active-line {\ + background-color: #abbffe;\ +}\ +.ace_autocomplete.ace-tm .ace_line-hover {\ + border: 1px solid #abbffe;\ + position: absolute;\ + background: rgba(233,233,253,0.4);\ + z-index: 2;\ + margin-top: -1px;\ +}\ +.ace_rightAlignedText {\ + color: gray;\ + display: inline-block;\ + position: absolute;\ + right: 4px;\ + text-align: right;\ + z-index: -1;\ +}\ +.ace_autocomplete {\ + width: 200px;\ + z-index: 200000;\ + background: #f8f8f8;\ + border: 1px lightgray solid;\ + position: fixed;\ +}"); + +exports.AcePopup = AcePopup; + +}); \ No newline at end of file diff --git a/lib/ace/autocomplete/autocomplete_worker.js b/lib/ace/ext/language_tools.js similarity index 57% rename from lib/ace/autocomplete/autocomplete_worker.js rename to lib/ace/ext/language_tools.js index 39a3ba89..510fb01f 100644 --- a/lib/ace/autocomplete/autocomplete_worker.js +++ b/lib/ace/ext/language_tools.js @@ -3,7 +3,7 @@ * * Copyright (c) 2012, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -31,50 +31,14 @@ define(function(require, exports, module) { "use strict"; -var oop = require("../lib/oop"); -var Mirror = require("../worker/mirror").Mirror; +var snippetManager = require("../snippets").snippetManager; +var Autocomplete = require("../autocomplete").Autocomplete; -var completer = require("./text_completer"); - -var AutocompleteWorker = exports.AutocompleteWorker = function(sender) { - this.setTimeout(0); - Mirror.call(this, sender); - this.setDeferredUpdate(false); +var completers = []; +exports.addCompleter = function(completer) { + completers.push(completer); }; -oop.inherits(AutocompleteWorker, Mirror); -(function() { - this.onUpdate = function() { - var _self = this; - - var doc = this.doc.getValue(); - var pos = this.data.cursor; - - var currentPos = { line: pos.row, col: pos.column }; - - completer.complete(_self.doc, this.data.cursor, this.data.keywords, function(identifier, completions) { - if (!identifier) { - _self.sender.emit("complete", { - matches: [] - }); - } - - else { - _self.sender.emit("complete", { - startRow: pos.row, - startColumn: pos.column - identifier.length, - endRow: pos.row, - endColumn: Infinity, - matches: completions, - line: _self.doc.getLine(pos.row) - }); - } - - return; - }); - }; - -}).call(AutocompleteWorker.prototype); }); \ No newline at end of file diff --git a/lib/ace/snippets.js b/lib/ace/snippets.js index da9533b1..35308b9d 100644 --- a/lib/ace/snippets.js +++ b/lib/ace/snippets.js @@ -533,7 +533,6 @@ var SnippetManager = function() { }).call(SnippetManager.prototype); - var TabstopManager = function(editor) { if (editor.tabstopManager) return editor.tabstopManager; From df115ba6595ca326bd630fd3cc63f53e9b62c0ec Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 13 Apr 2013 14:44:20 +0400 Subject: [PATCH 19/31] add snippets placeholder files for all languages --- Makefile.dryice.js | 25 +++++++++++++++++++ lib/ace/snippets/abap.js | 7 ++++++ lib/ace/snippets/abap.snippets | 0 lib/ace/snippets/asciidoc.js | 7 ++++++ lib/ace/snippets/asciidoc.snippets | 0 lib/ace/snippets/c9search.js | 7 ++++++ lib/ace/snippets/c9search.snippets | 0 lib/ace/snippets/c_cpp.js | 7 ++++++ .../snippets/{cpp.snippets => c_cpp.snippets} | 0 lib/ace/snippets/clojure.js | 7 ++++++ lib/ace/snippets/coffee.js | 7 ++++++ lib/ace/snippets/coldfusion.js | 7 ++++++ lib/ace/snippets/coldfusion.snippets | 0 lib/ace/snippets/csharp.js | 7 ++++++ lib/ace/snippets/csharp.snippets | 0 lib/ace/snippets/css.js | 7 ++++++ lib/ace/snippets/curly.js | 7 ++++++ lib/ace/snippets/curly.snippets | 0 lib/ace/snippets/dart.js | 7 ++++++ lib/ace/snippets/diff.js | 7 ++++++ lib/ace/snippets/django.js | 7 ++++++ lib/ace/snippets/dot.js | 7 ++++++ lib/ace/snippets/dot.snippets | 0 lib/ace/snippets/ftl.js | 7 ++++++ lib/ace/snippets/ftl.snippets | 0 lib/ace/snippets/glsl.js | 7 ++++++ lib/ace/snippets/glsl.snippets | 0 lib/ace/snippets/golang.js | 7 ++++++ lib/ace/snippets/golang.snippets | 0 lib/ace/snippets/groovy.js | 7 ++++++ lib/ace/snippets/groovy.snippets | 0 lib/ace/snippets/haml.js | 7 ++++++ lib/ace/snippets/haxe.js | 7 ++++++ lib/ace/snippets/haxe.snippets | 0 lib/ace/snippets/html.js | 7 ++++++ lib/ace/snippets/jade.js | 7 ++++++ lib/ace/snippets/jade.snippets | 0 lib/ace/snippets/java.js | 7 ++++++ lib/ace/snippets/json.js | 7 ++++++ lib/ace/snippets/json.snippets | 0 lib/ace/snippets/jsp.js | 7 ++++++ lib/ace/snippets/jsx.js | 7 ++++++ lib/ace/snippets/jsx.snippets | 0 lib/ace/snippets/latex.js | 7 ++++++ lib/ace/snippets/latex.snippets | 0 lib/ace/snippets/less.js | 7 ++++++ lib/ace/snippets/less.snippets | 0 lib/ace/snippets/liquid.js | 7 ++++++ lib/ace/snippets/liquid.snippets | 0 lib/ace/snippets/lisp.js | 7 ++++++ lib/ace/snippets/lisp.snippets | 0 lib/ace/snippets/livescript.js | 7 ++++++ lib/ace/snippets/livescript.snippets | 0 lib/ace/snippets/logiql.js | 7 ++++++ lib/ace/snippets/logiql.snippets | 0 lib/ace/snippets/lsl.js | 7 ++++++ lib/ace/snippets/lua.js | 7 ++++++ lib/ace/snippets/luapage.js | 7 ++++++ lib/ace/snippets/luapage.snippets | 0 lib/ace/snippets/lucene.js | 7 ++++++ lib/ace/snippets/lucene.snippets | 0 lib/ace/snippets/makefile.js | 7 ++++++ .../{make.snippets => makefile.snippets} | 0 lib/ace/snippets/markdown.js | 7 ++++++ lib/ace/snippets/mushcode.js | 7 ++++++ lib/ace/snippets/mushcode.snippets | 0 lib/ace/snippets/mushcode_high_rules.js | 7 ++++++ lib/ace/snippets/mushcode_high_rules.snippets | 0 lib/ace/snippets/objectivec.js | 7 ++++++ lib/ace/snippets/objectivec.snippets | 0 lib/ace/snippets/ocaml.js | 7 ++++++ lib/ace/snippets/ocaml.snippets | 0 lib/ace/snippets/pascal.js | 7 ++++++ lib/ace/snippets/pascal.snippets | 0 lib/ace/snippets/perl.js | 7 ++++++ lib/ace/snippets/pgsql.js | 7 ++++++ lib/ace/snippets/pgsql.snippets | 0 lib/ace/snippets/php.js | 7 ++++++ lib/ace/snippets/powershell.js | 7 ++++++ lib/ace/snippets/powershell.snippets | 0 lib/ace/snippets/python.js | 7 ++++++ lib/ace/snippets/r.js | 7 ++++++ lib/ace/snippets/rdoc.js | 7 ++++++ lib/ace/snippets/rdoc.snippets | 0 lib/ace/snippets/rhtml.js | 7 ++++++ lib/ace/snippets/rhtml.snippets | 0 lib/ace/snippets/ruby.js | 7 ++++++ lib/ace/snippets/sass.js | 7 ++++++ lib/ace/snippets/sass.snippets | 0 lib/ace/snippets/scad.js | 7 ++++++ lib/ace/snippets/scad.snippets | 0 lib/ace/snippets/scala.js | 7 ++++++ lib/ace/snippets/scala.snippets | 0 lib/ace/snippets/scheme.js | 7 ++++++ lib/ace/snippets/scheme.snippets | 0 lib/ace/snippets/scss.js | 7 ++++++ lib/ace/snippets/scss.snippets | 0 lib/ace/snippets/sh.js | 7 ++++++ lib/ace/snippets/sql.js | 7 ++++++ lib/ace/snippets/stylus.js | 7 ++++++ lib/ace/snippets/stylus.snippets | 0 lib/ace/snippets/svg.js | 7 ++++++ lib/ace/snippets/svg.snippets | 0 lib/ace/snippets/tcl.js | 7 ++++++ lib/ace/snippets/tex.js | 7 ++++++ lib/ace/snippets/text.js | 7 ++++++ lib/ace/snippets/text.snippets | 0 lib/ace/snippets/textile.js | 7 ++++++ lib/ace/snippets/tmsnippet.js | 7 ++++++ lib/ace/snippets/tmsnippet.snippets | 0 lib/ace/snippets/toml.js | 7 ++++++ lib/ace/snippets/toml.snippets | 0 lib/ace/snippets/typescript.js | 7 ++++++ lib/ace/snippets/typescript.snippets | 0 lib/ace/snippets/vbscript.js | 7 ++++++ lib/ace/snippets/vbscript.snippets | 0 lib/ace/snippets/velocity.js | 7 ++++++ lib/ace/snippets/velocity.snippets | 0 lib/ace/snippets/xml.js | 7 ++++++ lib/ace/snippets/xml.snippets | 0 lib/ace/snippets/xquery.js | 7 ++++++ lib/ace/snippets/xquery.snippets | 0 lib/ace/snippets/yaml.js | 7 ++++++ lib/ace/snippets/yaml.snippets | 0 124 files changed, 536 insertions(+) create mode 100644 lib/ace/snippets/abap.js create mode 100644 lib/ace/snippets/abap.snippets create mode 100644 lib/ace/snippets/asciidoc.js create mode 100644 lib/ace/snippets/asciidoc.snippets create mode 100644 lib/ace/snippets/c9search.js create mode 100644 lib/ace/snippets/c9search.snippets create mode 100644 lib/ace/snippets/c_cpp.js rename lib/ace/snippets/{cpp.snippets => c_cpp.snippets} (100%) create mode 100644 lib/ace/snippets/clojure.js create mode 100644 lib/ace/snippets/coffee.js create mode 100644 lib/ace/snippets/coldfusion.js create mode 100644 lib/ace/snippets/coldfusion.snippets create mode 100644 lib/ace/snippets/csharp.js create mode 100644 lib/ace/snippets/csharp.snippets create mode 100644 lib/ace/snippets/css.js create mode 100644 lib/ace/snippets/curly.js create mode 100644 lib/ace/snippets/curly.snippets create mode 100644 lib/ace/snippets/dart.js create mode 100644 lib/ace/snippets/diff.js create mode 100644 lib/ace/snippets/django.js create mode 100644 lib/ace/snippets/dot.js create mode 100644 lib/ace/snippets/dot.snippets create mode 100644 lib/ace/snippets/ftl.js create mode 100644 lib/ace/snippets/ftl.snippets create mode 100644 lib/ace/snippets/glsl.js create mode 100644 lib/ace/snippets/glsl.snippets create mode 100644 lib/ace/snippets/golang.js create mode 100644 lib/ace/snippets/golang.snippets create mode 100644 lib/ace/snippets/groovy.js create mode 100644 lib/ace/snippets/groovy.snippets create mode 100644 lib/ace/snippets/haml.js create mode 100644 lib/ace/snippets/haxe.js create mode 100644 lib/ace/snippets/haxe.snippets create mode 100644 lib/ace/snippets/html.js create mode 100644 lib/ace/snippets/jade.js create mode 100644 lib/ace/snippets/jade.snippets create mode 100644 lib/ace/snippets/java.js create mode 100644 lib/ace/snippets/json.js create mode 100644 lib/ace/snippets/json.snippets create mode 100644 lib/ace/snippets/jsp.js create mode 100644 lib/ace/snippets/jsx.js create mode 100644 lib/ace/snippets/jsx.snippets create mode 100644 lib/ace/snippets/latex.js create mode 100644 lib/ace/snippets/latex.snippets create mode 100644 lib/ace/snippets/less.js create mode 100644 lib/ace/snippets/less.snippets create mode 100644 lib/ace/snippets/liquid.js create mode 100644 lib/ace/snippets/liquid.snippets create mode 100644 lib/ace/snippets/lisp.js create mode 100644 lib/ace/snippets/lisp.snippets create mode 100644 lib/ace/snippets/livescript.js create mode 100644 lib/ace/snippets/livescript.snippets create mode 100644 lib/ace/snippets/logiql.js create mode 100644 lib/ace/snippets/logiql.snippets create mode 100644 lib/ace/snippets/lsl.js create mode 100644 lib/ace/snippets/lua.js create mode 100644 lib/ace/snippets/luapage.js create mode 100644 lib/ace/snippets/luapage.snippets create mode 100644 lib/ace/snippets/lucene.js create mode 100644 lib/ace/snippets/lucene.snippets create mode 100644 lib/ace/snippets/makefile.js rename lib/ace/snippets/{make.snippets => makefile.snippets} (100%) create mode 100644 lib/ace/snippets/markdown.js create mode 100644 lib/ace/snippets/mushcode.js create mode 100644 lib/ace/snippets/mushcode.snippets create mode 100644 lib/ace/snippets/mushcode_high_rules.js create mode 100644 lib/ace/snippets/mushcode_high_rules.snippets create mode 100644 lib/ace/snippets/objectivec.js create mode 100644 lib/ace/snippets/objectivec.snippets create mode 100644 lib/ace/snippets/ocaml.js create mode 100644 lib/ace/snippets/ocaml.snippets create mode 100644 lib/ace/snippets/pascal.js create mode 100644 lib/ace/snippets/pascal.snippets create mode 100644 lib/ace/snippets/perl.js create mode 100644 lib/ace/snippets/pgsql.js create mode 100644 lib/ace/snippets/pgsql.snippets create mode 100644 lib/ace/snippets/php.js create mode 100644 lib/ace/snippets/powershell.js create mode 100644 lib/ace/snippets/powershell.snippets create mode 100644 lib/ace/snippets/python.js create mode 100644 lib/ace/snippets/r.js create mode 100644 lib/ace/snippets/rdoc.js create mode 100644 lib/ace/snippets/rdoc.snippets create mode 100644 lib/ace/snippets/rhtml.js create mode 100644 lib/ace/snippets/rhtml.snippets create mode 100644 lib/ace/snippets/ruby.js create mode 100644 lib/ace/snippets/sass.js create mode 100644 lib/ace/snippets/sass.snippets create mode 100644 lib/ace/snippets/scad.js create mode 100644 lib/ace/snippets/scad.snippets create mode 100644 lib/ace/snippets/scala.js create mode 100644 lib/ace/snippets/scala.snippets create mode 100644 lib/ace/snippets/scheme.js create mode 100644 lib/ace/snippets/scheme.snippets create mode 100644 lib/ace/snippets/scss.js create mode 100644 lib/ace/snippets/scss.snippets create mode 100644 lib/ace/snippets/sh.js create mode 100644 lib/ace/snippets/sql.js create mode 100644 lib/ace/snippets/stylus.js create mode 100644 lib/ace/snippets/stylus.snippets create mode 100644 lib/ace/snippets/svg.js create mode 100644 lib/ace/snippets/svg.snippets create mode 100644 lib/ace/snippets/tcl.js create mode 100644 lib/ace/snippets/tex.js create mode 100644 lib/ace/snippets/text.js create mode 100644 lib/ace/snippets/text.snippets create mode 100644 lib/ace/snippets/textile.js create mode 100644 lib/ace/snippets/tmsnippet.js create mode 100644 lib/ace/snippets/tmsnippet.snippets create mode 100644 lib/ace/snippets/toml.js create mode 100644 lib/ace/snippets/toml.snippets create mode 100644 lib/ace/snippets/typescript.js create mode 100644 lib/ace/snippets/typescript.snippets create mode 100644 lib/ace/snippets/vbscript.js create mode 100644 lib/ace/snippets/vbscript.snippets create mode 100644 lib/ace/snippets/velocity.js create mode 100644 lib/ace/snippets/velocity.snippets create mode 100644 lib/ace/snippets/xml.js create mode 100644 lib/ace/snippets/xml.snippets create mode 100644 lib/ace/snippets/xquery.js create mode 100644 lib/ace/snippets/xquery.snippets create mode 100644 lib/ace/snippets/yaml.js create mode 100644 lib/ace/snippets/yaml.snippets diff --git a/Makefile.dryice.js b/Makefile.dryice.js index 73abf1c1..9ac8fc99 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -349,6 +349,7 @@ var buildAce = function(options) { project.assumeAllFilesLoaded(); options.modes.forEach(function(mode) { console.log("mode " + mode); + addSnippetFile(mode, project, targetDir, options); copy({ source: [{ project: cloneProject(project), @@ -460,6 +461,30 @@ var buildAce = function(fn) { } }(buildAce); +var addSnippetFile = function(modeName, project, targetDir, options) { + var snippetFilePath = ACE_HOME + "/lib/ace/snippets/" + modeName; + if (!fs.existsSync(snippetFilePath + ".js")) { + copy({ + source: ACE_HOME + "/tool/snippet.tmpl.js", + dest: snippetFilePath + ".js", + filter: [ + function(t) {return t.replace("%modeName%", modeName);} + ] + }); + } + if (!fs.existsSync(snippetFilePath + ".snippets")) { + fs.writeFileSync(snippetFilePath + ".snippets", "") + } + copy({ + source: [{ + project: cloneProject(project), + require: [ 'ace/snippets/' + modeName ] + }], + filter: getWriteFilters(options, "mode"), + dest: targetDir + "/snippets/" + modeName + ".js" + }); +} + var textModules = {} var detectTextModules = function(input, source) { if (!source) diff --git a/lib/ace/snippets/abap.js b/lib/ace/snippets/abap.js new file mode 100644 index 00000000..40870ff7 --- /dev/null +++ b/lib/ace/snippets/abap.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./abap.snippets"); + + +}); diff --git a/lib/ace/snippets/abap.snippets b/lib/ace/snippets/abap.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/asciidoc.js b/lib/ace/snippets/asciidoc.js new file mode 100644 index 00000000..0d8d353b --- /dev/null +++ b/lib/ace/snippets/asciidoc.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./asciidoc.snippets"); + + +}); diff --git a/lib/ace/snippets/asciidoc.snippets b/lib/ace/snippets/asciidoc.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/c9search.js b/lib/ace/snippets/c9search.js new file mode 100644 index 00000000..da0d3101 --- /dev/null +++ b/lib/ace/snippets/c9search.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./c9search.snippets"); + + +}); diff --git a/lib/ace/snippets/c9search.snippets b/lib/ace/snippets/c9search.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/c_cpp.js b/lib/ace/snippets/c_cpp.js new file mode 100644 index 00000000..b9555c14 --- /dev/null +++ b/lib/ace/snippets/c_cpp.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./c_cpp.snippets"); + + +}); diff --git a/lib/ace/snippets/cpp.snippets b/lib/ace/snippets/c_cpp.snippets similarity index 100% rename from lib/ace/snippets/cpp.snippets rename to lib/ace/snippets/c_cpp.snippets diff --git a/lib/ace/snippets/clojure.js b/lib/ace/snippets/clojure.js new file mode 100644 index 00000000..8a1cf1c5 --- /dev/null +++ b/lib/ace/snippets/clojure.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./clojure.snippets"); + + +}); diff --git a/lib/ace/snippets/coffee.js b/lib/ace/snippets/coffee.js new file mode 100644 index 00000000..788227b6 --- /dev/null +++ b/lib/ace/snippets/coffee.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./coffee.snippets"); + + +}); diff --git a/lib/ace/snippets/coldfusion.js b/lib/ace/snippets/coldfusion.js new file mode 100644 index 00000000..0002b081 --- /dev/null +++ b/lib/ace/snippets/coldfusion.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./coldfusion.snippets"); + + +}); diff --git a/lib/ace/snippets/coldfusion.snippets b/lib/ace/snippets/coldfusion.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/csharp.js b/lib/ace/snippets/csharp.js new file mode 100644 index 00000000..99fbe4ce --- /dev/null +++ b/lib/ace/snippets/csharp.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./csharp.snippets"); + + +}); diff --git a/lib/ace/snippets/csharp.snippets b/lib/ace/snippets/csharp.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/css.js b/lib/ace/snippets/css.js new file mode 100644 index 00000000..a5d3e744 --- /dev/null +++ b/lib/ace/snippets/css.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./css.snippets"); + + +}); diff --git a/lib/ace/snippets/curly.js b/lib/ace/snippets/curly.js new file mode 100644 index 00000000..ee584465 --- /dev/null +++ b/lib/ace/snippets/curly.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./curly.snippets"); + + +}); diff --git a/lib/ace/snippets/curly.snippets b/lib/ace/snippets/curly.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/dart.js b/lib/ace/snippets/dart.js new file mode 100644 index 00000000..be721176 --- /dev/null +++ b/lib/ace/snippets/dart.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./dart.snippets"); + + +}); diff --git a/lib/ace/snippets/diff.js b/lib/ace/snippets/diff.js new file mode 100644 index 00000000..5ed1e646 --- /dev/null +++ b/lib/ace/snippets/diff.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./diff.snippets"); + + +}); diff --git a/lib/ace/snippets/django.js b/lib/ace/snippets/django.js new file mode 100644 index 00000000..7ecc97d1 --- /dev/null +++ b/lib/ace/snippets/django.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./django.snippets"); + + +}); diff --git a/lib/ace/snippets/dot.js b/lib/ace/snippets/dot.js new file mode 100644 index 00000000..7a2f1792 --- /dev/null +++ b/lib/ace/snippets/dot.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./dot.snippets"); + + +}); diff --git a/lib/ace/snippets/dot.snippets b/lib/ace/snippets/dot.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/ftl.js b/lib/ace/snippets/ftl.js new file mode 100644 index 00000000..ef9d12e0 --- /dev/null +++ b/lib/ace/snippets/ftl.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./ftl.snippets"); + + +}); diff --git a/lib/ace/snippets/ftl.snippets b/lib/ace/snippets/ftl.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/glsl.js b/lib/ace/snippets/glsl.js new file mode 100644 index 00000000..729e0890 --- /dev/null +++ b/lib/ace/snippets/glsl.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./glsl.snippets"); + + +}); diff --git a/lib/ace/snippets/glsl.snippets b/lib/ace/snippets/glsl.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/golang.js b/lib/ace/snippets/golang.js new file mode 100644 index 00000000..e6b169c9 --- /dev/null +++ b/lib/ace/snippets/golang.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./golang.snippets"); + + +}); diff --git a/lib/ace/snippets/golang.snippets b/lib/ace/snippets/golang.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/groovy.js b/lib/ace/snippets/groovy.js new file mode 100644 index 00000000..33bcb3d2 --- /dev/null +++ b/lib/ace/snippets/groovy.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./groovy.snippets"); + + +}); diff --git a/lib/ace/snippets/groovy.snippets b/lib/ace/snippets/groovy.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/haml.js b/lib/ace/snippets/haml.js new file mode 100644 index 00000000..eb1b5fb2 --- /dev/null +++ b/lib/ace/snippets/haml.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./haml.snippets"); + + +}); diff --git a/lib/ace/snippets/haxe.js b/lib/ace/snippets/haxe.js new file mode 100644 index 00000000..660addb7 --- /dev/null +++ b/lib/ace/snippets/haxe.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./haxe.snippets"); + + +}); diff --git a/lib/ace/snippets/haxe.snippets b/lib/ace/snippets/haxe.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/html.js b/lib/ace/snippets/html.js new file mode 100644 index 00000000..18db8416 --- /dev/null +++ b/lib/ace/snippets/html.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./html.snippets"); + + +}); diff --git a/lib/ace/snippets/jade.js b/lib/ace/snippets/jade.js new file mode 100644 index 00000000..e272e831 --- /dev/null +++ b/lib/ace/snippets/jade.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./jade.snippets"); + + +}); diff --git a/lib/ace/snippets/jade.snippets b/lib/ace/snippets/jade.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/java.js b/lib/ace/snippets/java.js new file mode 100644 index 00000000..9b861bf5 --- /dev/null +++ b/lib/ace/snippets/java.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./java.snippets"); + + +}); diff --git a/lib/ace/snippets/json.js b/lib/ace/snippets/json.js new file mode 100644 index 00000000..cbecb6e1 --- /dev/null +++ b/lib/ace/snippets/json.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./json.snippets"); + + +}); diff --git a/lib/ace/snippets/json.snippets b/lib/ace/snippets/json.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/jsp.js b/lib/ace/snippets/jsp.js new file mode 100644 index 00000000..0f39d9af --- /dev/null +++ b/lib/ace/snippets/jsp.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./jsp.snippets"); + + +}); diff --git a/lib/ace/snippets/jsx.js b/lib/ace/snippets/jsx.js new file mode 100644 index 00000000..5c31e99f --- /dev/null +++ b/lib/ace/snippets/jsx.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./jsx.snippets"); + + +}); diff --git a/lib/ace/snippets/jsx.snippets b/lib/ace/snippets/jsx.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/latex.js b/lib/ace/snippets/latex.js new file mode 100644 index 00000000..98fc6a48 --- /dev/null +++ b/lib/ace/snippets/latex.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./latex.snippets"); + + +}); diff --git a/lib/ace/snippets/latex.snippets b/lib/ace/snippets/latex.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/less.js b/lib/ace/snippets/less.js new file mode 100644 index 00000000..c2af7180 --- /dev/null +++ b/lib/ace/snippets/less.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./less.snippets"); + + +}); diff --git a/lib/ace/snippets/less.snippets b/lib/ace/snippets/less.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/liquid.js b/lib/ace/snippets/liquid.js new file mode 100644 index 00000000..1f76c3cc --- /dev/null +++ b/lib/ace/snippets/liquid.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./liquid.snippets"); + + +}); diff --git a/lib/ace/snippets/liquid.snippets b/lib/ace/snippets/liquid.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/lisp.js b/lib/ace/snippets/lisp.js new file mode 100644 index 00000000..9dc94deb --- /dev/null +++ b/lib/ace/snippets/lisp.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./lisp.snippets"); + + +}); diff --git a/lib/ace/snippets/lisp.snippets b/lib/ace/snippets/lisp.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/livescript.js b/lib/ace/snippets/livescript.js new file mode 100644 index 00000000..707ea6a4 --- /dev/null +++ b/lib/ace/snippets/livescript.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./livescript.snippets"); + + +}); diff --git a/lib/ace/snippets/livescript.snippets b/lib/ace/snippets/livescript.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/logiql.js b/lib/ace/snippets/logiql.js new file mode 100644 index 00000000..c879daac --- /dev/null +++ b/lib/ace/snippets/logiql.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./logiql.snippets"); + + +}); diff --git a/lib/ace/snippets/logiql.snippets b/lib/ace/snippets/logiql.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/lsl.js b/lib/ace/snippets/lsl.js new file mode 100644 index 00000000..342c8fb1 --- /dev/null +++ b/lib/ace/snippets/lsl.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./lsl.snippets"); + + +}); diff --git a/lib/ace/snippets/lua.js b/lib/ace/snippets/lua.js new file mode 100644 index 00000000..8ccd6fcb --- /dev/null +++ b/lib/ace/snippets/lua.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./lua.snippets"); + + +}); diff --git a/lib/ace/snippets/luapage.js b/lib/ace/snippets/luapage.js new file mode 100644 index 00000000..b6671d63 --- /dev/null +++ b/lib/ace/snippets/luapage.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./luapage.snippets"); + + +}); diff --git a/lib/ace/snippets/luapage.snippets b/lib/ace/snippets/luapage.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/lucene.js b/lib/ace/snippets/lucene.js new file mode 100644 index 00000000..014daa76 --- /dev/null +++ b/lib/ace/snippets/lucene.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./lucene.snippets"); + + +}); diff --git a/lib/ace/snippets/lucene.snippets b/lib/ace/snippets/lucene.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/makefile.js b/lib/ace/snippets/makefile.js new file mode 100644 index 00000000..3239254c --- /dev/null +++ b/lib/ace/snippets/makefile.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./makefile.snippets"); + + +}); diff --git a/lib/ace/snippets/make.snippets b/lib/ace/snippets/makefile.snippets similarity index 100% rename from lib/ace/snippets/make.snippets rename to lib/ace/snippets/makefile.snippets diff --git a/lib/ace/snippets/markdown.js b/lib/ace/snippets/markdown.js new file mode 100644 index 00000000..1a247b2c --- /dev/null +++ b/lib/ace/snippets/markdown.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./markdown.snippets"); + + +}); diff --git a/lib/ace/snippets/mushcode.js b/lib/ace/snippets/mushcode.js new file mode 100644 index 00000000..3c9f52fc --- /dev/null +++ b/lib/ace/snippets/mushcode.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./mushcode.snippets"); + + +}); diff --git a/lib/ace/snippets/mushcode.snippets b/lib/ace/snippets/mushcode.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/mushcode_high_rules.js b/lib/ace/snippets/mushcode_high_rules.js new file mode 100644 index 00000000..e4670deb --- /dev/null +++ b/lib/ace/snippets/mushcode_high_rules.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./mushcode_high_rules.snippets"); + + +}); diff --git a/lib/ace/snippets/mushcode_high_rules.snippets b/lib/ace/snippets/mushcode_high_rules.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/objectivec.js b/lib/ace/snippets/objectivec.js new file mode 100644 index 00000000..2e200fbd --- /dev/null +++ b/lib/ace/snippets/objectivec.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./objectivec.snippets"); + + +}); diff --git a/lib/ace/snippets/objectivec.snippets b/lib/ace/snippets/objectivec.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/ocaml.js b/lib/ace/snippets/ocaml.js new file mode 100644 index 00000000..805c6a37 --- /dev/null +++ b/lib/ace/snippets/ocaml.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./ocaml.snippets"); + + +}); diff --git a/lib/ace/snippets/ocaml.snippets b/lib/ace/snippets/ocaml.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/pascal.js b/lib/ace/snippets/pascal.js new file mode 100644 index 00000000..8d2fa6f4 --- /dev/null +++ b/lib/ace/snippets/pascal.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./pascal.snippets"); + + +}); diff --git a/lib/ace/snippets/pascal.snippets b/lib/ace/snippets/pascal.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/perl.js b/lib/ace/snippets/perl.js new file mode 100644 index 00000000..70d2e8d6 --- /dev/null +++ b/lib/ace/snippets/perl.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./perl.snippets"); + + +}); diff --git a/lib/ace/snippets/pgsql.js b/lib/ace/snippets/pgsql.js new file mode 100644 index 00000000..7b2bc647 --- /dev/null +++ b/lib/ace/snippets/pgsql.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./pgsql.snippets"); + + +}); diff --git a/lib/ace/snippets/pgsql.snippets b/lib/ace/snippets/pgsql.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/php.js b/lib/ace/snippets/php.js new file mode 100644 index 00000000..e10929e9 --- /dev/null +++ b/lib/ace/snippets/php.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./php.snippets"); + + +}); diff --git a/lib/ace/snippets/powershell.js b/lib/ace/snippets/powershell.js new file mode 100644 index 00000000..8b30a0b5 --- /dev/null +++ b/lib/ace/snippets/powershell.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./powershell.snippets"); + + +}); diff --git a/lib/ace/snippets/powershell.snippets b/lib/ace/snippets/powershell.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/python.js b/lib/ace/snippets/python.js new file mode 100644 index 00000000..bb17d22e --- /dev/null +++ b/lib/ace/snippets/python.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./python.snippets"); + + +}); diff --git a/lib/ace/snippets/r.js b/lib/ace/snippets/r.js new file mode 100644 index 00000000..f4fe2265 --- /dev/null +++ b/lib/ace/snippets/r.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./r.snippets"); + + +}); diff --git a/lib/ace/snippets/rdoc.js b/lib/ace/snippets/rdoc.js new file mode 100644 index 00000000..758bdd9a --- /dev/null +++ b/lib/ace/snippets/rdoc.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./rdoc.snippets"); + + +}); diff --git a/lib/ace/snippets/rdoc.snippets b/lib/ace/snippets/rdoc.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/rhtml.js b/lib/ace/snippets/rhtml.js new file mode 100644 index 00000000..a583b085 --- /dev/null +++ b/lib/ace/snippets/rhtml.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./rhtml.snippets"); + + +}); diff --git a/lib/ace/snippets/rhtml.snippets b/lib/ace/snippets/rhtml.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/ruby.js b/lib/ace/snippets/ruby.js new file mode 100644 index 00000000..4fccdbfa --- /dev/null +++ b/lib/ace/snippets/ruby.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./ruby.snippets"); + + +}); diff --git a/lib/ace/snippets/sass.js b/lib/ace/snippets/sass.js new file mode 100644 index 00000000..9ff1aa06 --- /dev/null +++ b/lib/ace/snippets/sass.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./sass.snippets"); + + +}); diff --git a/lib/ace/snippets/sass.snippets b/lib/ace/snippets/sass.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/scad.js b/lib/ace/snippets/scad.js new file mode 100644 index 00000000..added1b4 --- /dev/null +++ b/lib/ace/snippets/scad.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./scad.snippets"); + + +}); diff --git a/lib/ace/snippets/scad.snippets b/lib/ace/snippets/scad.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/scala.js b/lib/ace/snippets/scala.js new file mode 100644 index 00000000..d2281a49 --- /dev/null +++ b/lib/ace/snippets/scala.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./scala.snippets"); + + +}); diff --git a/lib/ace/snippets/scala.snippets b/lib/ace/snippets/scala.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/scheme.js b/lib/ace/snippets/scheme.js new file mode 100644 index 00000000..208454f6 --- /dev/null +++ b/lib/ace/snippets/scheme.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./scheme.snippets"); + + +}); diff --git a/lib/ace/snippets/scheme.snippets b/lib/ace/snippets/scheme.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/scss.js b/lib/ace/snippets/scss.js new file mode 100644 index 00000000..cf621dd3 --- /dev/null +++ b/lib/ace/snippets/scss.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./scss.snippets"); + + +}); diff --git a/lib/ace/snippets/scss.snippets b/lib/ace/snippets/scss.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/sh.js b/lib/ace/snippets/sh.js new file mode 100644 index 00000000..ac859391 --- /dev/null +++ b/lib/ace/snippets/sh.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./sh.snippets"); + + +}); diff --git a/lib/ace/snippets/sql.js b/lib/ace/snippets/sql.js new file mode 100644 index 00000000..34954dfa --- /dev/null +++ b/lib/ace/snippets/sql.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./sql.snippets"); + + +}); diff --git a/lib/ace/snippets/stylus.js b/lib/ace/snippets/stylus.js new file mode 100644 index 00000000..97a414ef --- /dev/null +++ b/lib/ace/snippets/stylus.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./stylus.snippets"); + + +}); diff --git a/lib/ace/snippets/stylus.snippets b/lib/ace/snippets/stylus.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/svg.js b/lib/ace/snippets/svg.js new file mode 100644 index 00000000..db48fb32 --- /dev/null +++ b/lib/ace/snippets/svg.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./svg.snippets"); + + +}); diff --git a/lib/ace/snippets/svg.snippets b/lib/ace/snippets/svg.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/tcl.js b/lib/ace/snippets/tcl.js new file mode 100644 index 00000000..1af7e59b --- /dev/null +++ b/lib/ace/snippets/tcl.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./tcl.snippets"); + + +}); diff --git a/lib/ace/snippets/tex.js b/lib/ace/snippets/tex.js new file mode 100644 index 00000000..d72e8320 --- /dev/null +++ b/lib/ace/snippets/tex.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./tex.snippets"); + + +}); diff --git a/lib/ace/snippets/text.js b/lib/ace/snippets/text.js new file mode 100644 index 00000000..f88da241 --- /dev/null +++ b/lib/ace/snippets/text.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./text.snippets"); + + +}); diff --git a/lib/ace/snippets/text.snippets b/lib/ace/snippets/text.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/textile.js b/lib/ace/snippets/textile.js new file mode 100644 index 00000000..4bed9a59 --- /dev/null +++ b/lib/ace/snippets/textile.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./textile.snippets"); + + +}); diff --git a/lib/ace/snippets/tmsnippet.js b/lib/ace/snippets/tmsnippet.js new file mode 100644 index 00000000..38ea1af0 --- /dev/null +++ b/lib/ace/snippets/tmsnippet.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./tmsnippet.snippets"); + + +}); diff --git a/lib/ace/snippets/tmsnippet.snippets b/lib/ace/snippets/tmsnippet.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/toml.js b/lib/ace/snippets/toml.js new file mode 100644 index 00000000..295bc824 --- /dev/null +++ b/lib/ace/snippets/toml.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./toml.snippets"); + + +}); diff --git a/lib/ace/snippets/toml.snippets b/lib/ace/snippets/toml.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/typescript.js b/lib/ace/snippets/typescript.js new file mode 100644 index 00000000..fe01171e --- /dev/null +++ b/lib/ace/snippets/typescript.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./typescript.snippets"); + + +}); diff --git a/lib/ace/snippets/typescript.snippets b/lib/ace/snippets/typescript.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/vbscript.js b/lib/ace/snippets/vbscript.js new file mode 100644 index 00000000..f6e370f3 --- /dev/null +++ b/lib/ace/snippets/vbscript.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./vbscript.snippets"); + + +}); diff --git a/lib/ace/snippets/vbscript.snippets b/lib/ace/snippets/vbscript.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/velocity.js b/lib/ace/snippets/velocity.js new file mode 100644 index 00000000..02f5b338 --- /dev/null +++ b/lib/ace/snippets/velocity.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./velocity.snippets"); + + +}); diff --git a/lib/ace/snippets/velocity.snippets b/lib/ace/snippets/velocity.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/xml.js b/lib/ace/snippets/xml.js new file mode 100644 index 00000000..e9328060 --- /dev/null +++ b/lib/ace/snippets/xml.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./xml.snippets"); + + +}); diff --git a/lib/ace/snippets/xml.snippets b/lib/ace/snippets/xml.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/xquery.js b/lib/ace/snippets/xquery.js new file mode 100644 index 00000000..0854dfb7 --- /dev/null +++ b/lib/ace/snippets/xquery.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./xquery.snippets"); + + +}); diff --git a/lib/ace/snippets/xquery.snippets b/lib/ace/snippets/xquery.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/yaml.js b/lib/ace/snippets/yaml.js new file mode 100644 index 00000000..bbdf8003 --- /dev/null +++ b/lib/ace/snippets/yaml.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./yaml.snippets"); + + +}); diff --git a/lib/ace/snippets/yaml.snippets b/lib/ace/snippets/yaml.snippets new file mode 100644 index 00000000..e69de29b From a399d1440aa080c4a6c8dc7356b82cf0b41d8a8d Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 13 Apr 2013 16:49:26 +0400 Subject: [PATCH 20/31] cleanup --- lib/ace/autocomplete.js | 35 +++++++++++++++++++---------------- lib/ace/autocomplete/popup.js | 12 ++++++------ lib/ace/ext/language_tools.js | 4 ++-- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 77f0f5ae..d6ec8641 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -85,7 +85,7 @@ var Autocomplete = function() { this.changeListener = function(e) { if (this.editor.completer.activated) - Autocomplete.startCommand.exec(this.editor); + this.complete(this.editor); else this.detach(); }; @@ -136,14 +136,17 @@ var Autocomplete = function() { this.commands = { "Up": function(editor) { editor.completer.goTo("up"); }, "Down": function(editor) { editor.completer.goTo("down"); }, - "Ctrl-Up": function(editor) { editor.completer.goTo("start"); }, - "Ctrl-Down": function(editor) { editor.completer.goTo("end"); }, + "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) { editor.completer.insertMatch(); }, "Shift-Return": function(editor) { editor.completer.insertMatch(true); }, - "Tab": function(editor) { editor.completer.insertMatch(); } + "Tab": function(editor) { editor.completer.insertMatch(); }, + + "PageUp": function(editor) { editor.completer.popup.gotoPageDown(); }, + "PageDown": function(editor) { editor.completer.popup.gotoPageUp(); } }; this.complete = function(editor) { @@ -163,20 +166,20 @@ var Autocomplete = function() { editor.on("blur", this.$blurListener); editor.on("mousedown", this.$mousedownListener); - worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition(), keywords: editor.session.getMode().getKeywords()}, true); + //worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition(), keywords: editor.session.getMode().getKeywords()}, true); - worker.on("complete", function(data) { - var matches = data.data.matches; - if (matches.length) { - _self.completions = new FilteredList(matches); - _self.completions.setFilter("a"); - _self.openPopup(editor); - } - else { - _self.detach(); - } - }); + var matches = data.data.matches; + + if (matches.length) { + _self.completions = new FilteredList(matches); + _self.completions.setFilter("a"); + _self.openPopup(editor); + } + else { + _self.detach(); + } + }; }).call(Autocomplete.prototype); diff --git a/lib/ace/autocomplete/popup.js b/lib/ace/autocomplete/popup.js index 8fe2eb56..374f4334 100644 --- a/lib/ace/autocomplete/popup.js +++ b/lib/ace/autocomplete/popup.js @@ -31,11 +31,11 @@ define(function(require, exports, module) { "use strict"; -var EditSession = require("./edit_session").EditSession; -var Renderer = require("./virtual_renderer").VirtualRenderer; -var event = require("./lib/event"); -var lang = require("./lib/lang"); -var dom = require("./lib/dom"); +var EditSession = require("../edit_session").EditSession; +var Renderer = require("../virtual_renderer").VirtualRenderer; +var event = require("../lib/event"); +var lang = require("../lib/lang"); +var dom = require("../lib/dom"); var $singleLineEditor = function(el) { var renderer = new Renderer(el); @@ -108,7 +108,7 @@ var AcePopup = function(parentNode) { var el = dom.createElement("div"); var popup = new $singleLineEditor(el); if (parentNode) - parentNode.appendChild(el); + parentNode.appendChild(el); el.style.display = "none"; popup.renderer.content.style.cursor = "default"; popup.renderer.setStyle("ace_autocomplete"); diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index 510fb01f..3aa000f1 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -36,9 +36,9 @@ var Autocomplete = require("../autocomplete").Autocomplete; var completers = []; exports.addCompleter = function(completer) { - completers.push(completer); + completers.push(completer); }; - +exports.completers = {} }); \ No newline at end of file From f6f475747b09a6fd865e8d83941079739b3828af Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 29 May 2013 00:30:05 +0400 Subject: [PATCH 21/31] style improvements --- demo/kitchen-sink/demo.js | 6 +- lib/ace/autocomplete.js | 117 ++++++++++++------ lib/ace/autocomplete/popup.js | 102 +++++++-------- lib/ace/autocomplete/text_completer.js | 106 ++++++++-------- .../{complete_util.js => util.js} | 88 +++---------- lib/ace/config.js | 4 +- lib/ace/ext/language_tools.js | 40 +++++- lib/ace/keyboard/textinput.js | 10 +- lib/ace/mode/abap.js | 2 +- tool/tmtheme.js | 1 + 10 files changed, 243 insertions(+), 233 deletions(-) rename lib/ace/autocomplete/{complete_util.js => util.js} (56%) diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index 1db21a9e..41ed5b19 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -155,7 +155,7 @@ env.editor.commands.addCommands([{ bindKey: "ctrl+enter", exec: function(editor) { try { - var r = eval(editor.getCopyText()||editor.getValue()); + var r = window.eval(editor.getCopyText()||editor.getValue()); } catch(e) { r = e; } @@ -559,7 +559,7 @@ ace.commands.bindKey("Tab", function(editor) { editor.execCommand("indent"); }) -var Autocompleter = require("ace/autocomplete").Autocomplete; -Autocompleter.addTo(env.editor) +require("ace/ext/language_tools"); + }); diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index d6ec8641..d2e8b4c7 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -31,17 +31,18 @@ define(function(require, exports, module) { "use strict"; -var Range = require("./range").Range; var HashHandler = require("./keyboard/hash_handler").HashHandler; var AcePopup = require("./autocomplete/popup").AcePopup; +var util = require("./autocomplete/util"); +var event = require("./lib/event"); var Autocomplete = function() { this.keyboardHandler = new HashHandler(); this.keyboardHandler.bindKeys(this.commands); - this.$blurListener = this.blurListener.bind(this); - this.$changeListener = this.changeListener.bind(this); - this.$mousedownListener = this.mousedownListener.bind(this); + this.blurListener = this.blurListener.bind(this); + this.changeListener = this.changeListener.bind(this); + this.mousedownListener = this.mousedownListener.bind(this); }; (function() { @@ -49,6 +50,7 @@ var Autocomplete = function() { this.popup = new AcePopup(document.body || document.documentElement); this.popup.on("click", function(e) { this.insertMatch(); + e.stop(); }.bind(this)); }; @@ -56,12 +58,12 @@ var Autocomplete = function() { if (!this.popup) this.$init(); - this.popup.setData(this.completions.filtered) + this.popup.setData(this.completions.filtered); var renderer = editor.renderer; var lineHeight = renderer.layerConfig.lineHeight; - var pos = renderer.$cursorLayer.getPixelPosition(null, true) - var rect = editor.container.getBoundingClientRect() + var pos = renderer.$cursorLayer.getPixelPosition(null, true); + var rect = editor.container.getBoundingClientRect(); pos.top += rect.top - renderer.layerConfig.offset; pos.left += rect.left; pos.left += renderer.$gutterLayer.gutterWidth; @@ -113,24 +115,26 @@ var Autocomplete = function() { case "up": row = row <= 0 ? max : row - 1; break; case "down": row = row >= max ? 0 : row + 1; break; case "start": row = 0; break; - case "end": row = max; break + case "end": row = max; break; } this.popup.setRow(row); }; - this.insertMatch = function(row) { + this.insertMatch = function(data) { this.detach(); - - if (row == undefined) - row = this.popup.getRow(); - var text = this.completions.filtered[row]; - if (text.value) - text = text.value; - - // should be good enough, otherwise we can use getDocument().removeInLine - this.editor.removeWordLeft(); - this.editor.insert(text); + if (!data) + data = this.popup.getData(this.popup.getRow()); + if (!data) + return false; + if (data.completer && data.completer.insertMatch) { + data.completer.insertMatch(this.editor); + } else { + if (data.value) + data = data.value; + this.editor.removeWordLeft(); + this.editor.insert(data); + } }; this.commands = { @@ -149,11 +153,36 @@ var Autocomplete = function() { "PageDown": function(editor) { editor.completer.popup.gotoPageUp(); } }; + this.getCompletions = function(editor, callback) { + var session = editor.getSession(); + var pos = editor.getCursorPosition(); + + var line = session.getLine(pos.row); + var prefix = util.retrievePrecedingIdentifier(line, pos.column); + + var matches = []; + util.parForEach(editor.completers, function(completer, next) { + completer.getCompletions(session, pos, prefix, function(err, results) { + if (!err) + matches = matches.concat(results); + next(); + }); + }, function() { + matches.sort(function(a, b) { + return b.score - a.score; + }); + callback(null, { + prefix: prefix, + matches: matches + }); + }); + return true; + }; + this.complete = function(editor) { if (this.editor) this.detach(); - var _self = this; this.editor = editor; if (editor.completer != this) { if (editor.completer) @@ -162,25 +191,35 @@ var Autocomplete = function() { } editor.keyBinding.addKeyboardHandler(this.keyboardHandler); - editor.on("changeSelection", this.$changeListener); - editor.on("blur", this.$blurListener); - editor.on("mousedown", this.$mousedownListener); + editor.on("changeSelection", this.changeListener); + editor.on("blur", this.blurListener); + editor.on("mousedown", this.mousedownListener); - //worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition(), keywords: editor.session.getMode().getKeywords()}, true); - - - var matches = data.data.matches; - - if (matches.length) { - _self.completions = new FilteredList(matches); - _self.completions.setFilter("a"); - _self.openPopup(editor); - } - else { - _self.detach(); - } + this.getCompletions(this.editor, function(err, results) { + var matches = results && results.matches; + if (!matches || !matches.length) + return this.detach(); + if (matches.length == 1) + return this.insertMatch(matches[0]); + this.completions = new FilteredList(matches); + this.completions.setFilter(results.prefix); + this.openPopup(editor); + this.popup.setHighlight(results.prefix); + }.bind(this)); }; + + this.cancelContextMenu = function() { + var stop = function(e) { + this.editor.off("nativecontextmenu", stop); + if (e && e.domEvent) + event.stopEvent(e.domEvent); + }.bind(this); + setTimeout(stop, 10); + this.editor.on("nativecontextmenu", stop); + }; + + this.completers = []; }).call(Autocomplete.prototype); @@ -191,12 +230,14 @@ Autocomplete.startCommand = { editor.completer = new Autocomplete(); editor.completer.complete(editor); editor.completer.activated = true; + // needed for firefox on mac + editor.completer.cancelContextMenu(); }, bindKey: "Ctrl-Space|Shift-Space|Alt-Space" -} +}; Autocomplete.addTo = function(editor) { editor.commands.addCommand(Autocomplete.startCommand); -} +}; var FilteredList = function(array, mutateData) { this.all = array; diff --git a/lib/ace/autocomplete/popup.js b/lib/ace/autocomplete/popup.js index 374f4334..c6b401b2 100644 --- a/lib/ace/autocomplete/popup.js +++ b/lib/ace/autocomplete/popup.js @@ -33,34 +33,22 @@ define(function(require, exports, module) { var EditSession = require("../edit_session").EditSession; var Renderer = require("../virtual_renderer").VirtualRenderer; +var Editor = require("../editor").Editor; +var Range = require("../range").Range; var event = require("../lib/event"); var lang = require("../lib/lang"); var dom = require("../lib/dom"); var $singleLineEditor = function(el) { var renderer = new Renderer(el); - el.style.overflow = "hidden"; - renderer.scrollBar.element.style.top = "0"; - renderer.scrollBar.element.style.display = "none"; - renderer.scrollBar.orginalWidth = renderer.scrollBar.width; - renderer.scrollBar.width = 0; - renderer.content.style.height = "auto"; - - renderer.screenToTextCoordinates = function(x, y) { - var pos = this.pixelToScreenCoordinates(x, y); - return this.session.screenToDocumentPosition( - Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)), - Math.max(pos.column, 0) - ); - }; renderer.maxLines = 4; renderer.$computeLayerConfigWithScroll = renderer.$computeLayerConfig; + renderer.scrollBar.orginalWidth = renderer.scrollBar.getWidth(); renderer.$computeLayerConfig = function() { - var config = this.layerConfig; var height = this.session.getScreenLength() * this.lineHeight; - var maxHeight = this.maxLines * this.lineHeight - var desiredHeight = Math.max(this.lineHeight, Math.min(maxHeight, height)) + var maxHeight = this.maxLines * this.lineHeight; + var desiredHeight = Math.max(this.lineHeight, Math.min(maxHeight, height)); var vScroll = height > maxHeight; if (desiredHeight != this.desiredHeight || vScroll != this.$vScroll) { if (vScroll != this.$vScroll) { @@ -83,15 +71,13 @@ var $singleLineEditor = function(el) { this.container.style.height = desiredHeight + "px"; this.onResize(); - this.$loop.changes = 0 + this.$loop.changes = 0; this.desiredHeight = desiredHeight; - this.scroller.style.overflowX="hidden" + this.scroller.style.overflowX = "hidden"; } return renderer.$computeLayerConfigWithScroll(); }; - - var Editor = require("ace/editor").Editor; var editor = new Editor(renderer); editor.setHighlightActiveLine(false); @@ -121,7 +107,7 @@ var AcePopup = function(parentNode) { popup.renderer.$cursorLayer.restartTimer = noop; popup.renderer.$cursorLayer.element.style.opacity = 0; - popup.renderer.maxLines = 8 + popup.renderer.maxLines = 8; popup.renderer.$keepTextAreaAtCursor = false; popup.setHighlightActiveLine(true); @@ -134,19 +120,6 @@ var AcePopup = function(parentNode) { e.stop(); }); - popup.getRow = function() { - var line = this.getCursorPosition().row; - if (line == 0 && !this.getHighlightActiveLine()) - line = -1; - return line; - }; - - popup.setRow = function(line) { - popup.setHighlightActiveLine(line != -1); - popup.selection.clearSelection(); - popup.moveCursorTo(line, 0 || 0); - }; - var hoverMarker = new Range(-1,0,-1,Infinity); hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine"); popup.on("mousemove", function(e) { @@ -165,14 +138,9 @@ var AcePopup = function(parentNode) { popup.on("mousewheel", function(e) { setTimeout(function() { popup._signal("mousemove", e); - }) + }); }); - popup.data = [] - popup.setData = function(list) { - popup.data = list || []; - popup.setValue(lang.stringRepeat("\n", list.length), -1); - }; popup.session.doc.getLength = function() { return popup.data.length; }; @@ -183,26 +151,51 @@ var AcePopup = function(parentNode) { return (data && data.value) || ""; }; - var bgTokenizer = popup.session.bgTokenizer + var bgTokenizer = popup.session.bgTokenizer; bgTokenizer.$tokenizeRow = function(i) { var data = popup.data[i]; var tokens = []; if (!data) return tokens; if (typeof data == "string") - data = {type: data, value: data}//return [{type: "", value: data}]; + data = {value: data}; - tokens.push({type: "", value: data.value}); - if (data.type) { + tokens.push({type: data.className || "", value: data.value}); + if (data.meta) { var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth; - if (data.type.length + data.value.length < maxW - 2) - tokens.push({type: "rightAlignedText", value: data.type}); + if (data.meta.length + data.value.length < maxW - 2) + tokens.push({type: "rightAlignedText", value: data.meta}); } return tokens; }; - bgTokenizer.$updateOnChange = noop + bgTokenizer.$updateOnChange = noop; + + popup.session.$computeWidth = function() { + return this.screenWidth = 0; + } + + // public + popup.data = []; + popup.setData = function(list) { + popup.data = list || []; + popup.setValue(lang.stringRepeat("\n", list.length), -1); + }; + popup.getData = function(row) { + return popup.data[row]; + }; + + popup.getRow = function() { + var line = this.getCursorPosition().row; + if (line == 0 && !this.getHighlightActiveLine()) + line = -1; + return line; + }; + popup.setRow = function(line) { + popup.setHighlightActiveLine(line != -1); + popup.selection.clearSelection(); + popup.moveCursorTo(line, 0 || 0); + }; - // highlight popup.setHighlight = function(re) { popup.session.highlight(re); popup.session._emit("changeFrontMarker"); @@ -211,24 +204,24 @@ var AcePopup = function(parentNode) { popup.hide = function() { this.container.style.display = "none"; this._signal("hide"); - } - + }; popup.show = function(pos, lineHeight) { var el = this.container; if (pos.top > window.innerHeight / 2 + lineHeight) { - el.style.top = "" + el.style.top = ""; el.style.bottom = window.innerHeight - pos.top + "px"; } else { pos.top += lineHeight; el.style.top = pos.top + "px"; - el.style.bottom = "" + el.style.bottom = ""; } el.style.left = pos.left + "px"; el.style.display = ""; this._signal("show"); - } + }; + return popup; }; @@ -257,6 +250,7 @@ dom.importCssString("\ background: #f8f8f8;\ border: 1px lightgray solid;\ position: fixed;\ + box-shadow: 2px 3px 5px rgba(0,0,0,.2);\ }"); exports.AcePopup = AcePopup; diff --git a/lib/ace/autocomplete/text_completer.js b/lib/ace/autocomplete/text_completer.js index d8d5673f..30b9352f 100644 --- a/lib/ace/autocomplete/text_completer.js +++ b/lib/ace/autocomplete/text_completer.js @@ -29,69 +29,61 @@ * ***** END LICENSE BLOCK ***** */ define(function(require, exports, module) { - var completeUtil = require("./complete_util"); - var SPLIT_REGEX = /[^a-zA-Z_0-9\$]+/; - var MAX_SCORE = 1000000; + var Range = require("ace/range").Range; + + var splitRegex = /[^a-zA-Z_0-9\$\-]+/; - var completer = module.exports; - - // For the current document, gives scores to identifiers not on frequency, but on distance from the current prefix - function wordDistanceAnalyzer(doc, pos, prefix, keywords) { - var text = doc.getValue().trim(); - - // Determine cursor's word index - var textBefore = doc.getLines(0, pos.row - 1).join("\n") + "\n"; - var currentLine = doc.getLine(pos.row); - textBefore += currentLine.substr(0, pos.column); - var prefixPosition = textBefore.trim().split(SPLIT_REGEX).length - 1; - - // Split entire document into words - var identifiers = text.split(SPLIT_REGEX); - var identDict = {}; - - // Find prefix to find other identifiers close it - for (var i = 0; i < identifiers.length; i++) { - if (i === prefixPosition) - continue; - var ident = identifiers[i]; - if (ident.length === 0) - continue; - var distance = Math.max(prefixPosition, i) - Math.min(prefixPosition, i); - // Score substracted from MAX to force descending ordering - if (Object.prototype.hasOwnProperty.call(identDict, ident)) - identDict[ident] = Math.max(MAX_SCORE - distance, identDict[ident]); - else - identDict[ident] = MAX_SCORE - distance; - - } - - for (var k = 0, l = keywords.length; k < l; k++) { - identDict[keywords[k]] = MAX_SCORE; - } - - return identDict; + function getWordIndex(doc, pos) { + var textBefore = doc.getTextRange(Range.fromPoints({row: 0, column:0}, pos)); + return textBefore.split(splitRegex).length - 1; } - completer.complete = function(doc, pos, keywords, callback) { - var line = doc.getLine(pos.row); - var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column); - - // there's nothing to autocomplete - if (identifier === "") - return callback(null); - - var identDict = wordDistanceAnalyzer(doc, pos, identifier, keywords); - - var allIdentifiers = []; - for (var ident in identDict) { - allIdentifiers.push(ident); + // NOTE: Naive implementation O(n), can be O(log n) with binary search + function filterPrefix(prefix, words) { + var results = []; + for (var i = 0; i < words.length; i++) { + if (words[i].indexOf(prefix) === 0) { + results.push(words[i]); + } } + return results; + } - allIdentifiers = completeUtil.removeDuplicateWords(allIdentifiers); + /** + * Does a distance analysis of the word `prefix` at position `pos` in `doc`. + * @return Map + */ + function wordDistance(doc, pos) { + var prefixPos = getWordIndex(doc, pos); + var words = doc.getValue().split(splitRegex); + var wordScores = Object.create(null); + + var currentWord = words[prefixPos]; - // find fuzzy matches based on text in doc, as well as mode keywords - var matches = completeUtil.findCompletions(identifier, identDict, allIdentifiers); + words.forEach(function(word, idx) { + if (!word || word === currentWord) return; - callback(identifier, matches); + var distance = Math.abs(prefixPos - idx); + var score = words.length - distance; + if (wordScores[word]) { + wordScores[word] = Math.max(score, wordScores[word]); + } else { + wordScores[word] = score; + } + }); + return wordScores; + } + + exports.getCompletions = function(session, pos, prefix, callback) { + var wordScore = wordDistance(session, pos, prefix); + var wordList = filterPrefix(prefix, Object.keys(wordScore)); + callback(null, wordList.map(function(word) { + return { + name: word, + value: word, + score: wordScore[word], + meta: "local" + }; + })); }; }); \ No newline at end of file diff --git a/lib/ace/autocomplete/complete_util.js b/lib/ace/autocomplete/util.js similarity index 56% rename from lib/ace/autocomplete/complete_util.js rename to lib/ace/autocomplete/util.js index ad62393e..ae9ece5d 100644 --- a/lib/ace/autocomplete/complete_util.js +++ b/lib/ace/autocomplete/util.js @@ -29,10 +29,25 @@ * ***** END LICENSE BLOCK ***** */ define(function(require, exports, module) { +"use strict"; + +exports.parForEach = function(array, fn, callback) { + var completed = 0; + var arLength = array.length; + if (arLength === 0) + callback(); + for (var i = 0; i < arLength; i++) { + fn(array[i], function(result, err) { + completed++; + if (completed === arLength) + callback(result, err); + }); + } +} var ID_REGEX = /[a-zA-Z_0-9\$]/; -function retrievePrecedingIdentifier(text, pos, regex) { +exports.retrievePrecedingIdentifier = function(text, pos, regex) { regex = regex || ID_REGEX; var buf = []; for (var i = pos-1; i >= 0; i--) { @@ -44,7 +59,7 @@ function retrievePrecedingIdentifier(text, pos, regex) { return buf.reverse().join(""); } -function retrieveFollowingIdentifier(text, pos, regex) { +exports.retrieveFollowingIdentifier = function(text, pos, regex) { regex = regex || ID_REGEX; var buf = []; for (var i = pos; i < text.length; i++) { @@ -56,73 +71,4 @@ function retrieveFollowingIdentifier(text, pos, regex) { return buf; } -// filched from jQuery -function grep( elems, callback, inv ) { - var retVal, - ret = [], - i = 0, - length = elems.length; - inv = !!inv; - - // Go through the array, only saving the items - // that pass the validator function - for ( ; i < length; i++ ) { - retVal = !!callback( elems[ i ], i ); - if ( inv !== retVal ) { - ret.push( elems[ i ] ); - } - } - - return ret; -}; - -function sortByScore(items, identDict) { - - return items.sort(function(a, b) { - var scoreA = identDict[a], - scoreB = identDict[b]; - - if (a < b) - return 1; - else if (a > b) - return -1; - else - return 0; - }); -}; - -function findCompletions(prefix, identDict, allIdentifiers) { - var _self = this, - fuzzyMatcher = function (prefix, item) { - return ~item.toLowerCase().indexOf(prefix.toLowerCase()); - }; - - var matches = grep(allIdentifiers, function (item) { - return fuzzyMatcher(prefix, item); - }); - - matches = sortByScore(matches, identDict); - - return matches; -} - -exports.removeDuplicateWords = function(matches) { - // First, sort - matches = matches.sort(); - - for (var i = 1; i < matches.length; ){ - if (matches[i - 1] == matches[i]){ - matches.splice(i, 1); - } else { - i++; - } - } - - return matches; -}; - -exports.retrievePrecedingIdentifier = retrievePrecedingIdentifier; -exports.retrieveFollowingIdentifier = retrieveFollowingIdentifier; -exports.findCompletions = findCompletions; - }); diff --git a/lib/ace/config.js b/lib/ace/config.js index db36d59f..605abe1e 100644 --- a/lib/ace/config.js +++ b/lib/ace/config.js @@ -208,7 +208,7 @@ var optionsProvider = { return; var opt = this.$options[name]; if (!opt) - return undefined; + return false; if (opt.forwardTo) return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value); @@ -220,7 +220,7 @@ var optionsProvider = { getOption: function(name) { var opt = this.$options[name]; if (!opt) - return undefined; + return false; if (opt.forwardTo) return this[opt.forwardTo] && this[opt.forwardTo].getOption(name); return opt && opt.get ? opt.get.call(this) : this["$" + name]; diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index 3aa000f1..05e00129 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -34,11 +34,47 @@ define(function(require, exports, module) { var snippetManager = require("../snippets").snippetManager; var Autocomplete = require("../autocomplete").Autocomplete; -var completers = []; +var textCompleter = require("../autocomplete/text_completer"); + +var completers = [textCompleter]; exports.addCompleter = function(completer) { completers.push(completer); }; -exports.completers = {} +var expandSnippet = { + name: "expandSnippet", + exec: function(editor) { + var success = snippetManager.expandWithTab(editor); + if (!success) + editor.execCommand("indent"); + }, + bindKey: "tab" +} + + +var Editor = require("../editor").Editor; +require("../config").defineOptions(Editor.prototype, "editor", { + enableBasicAutocompletion: { + set: function(val) { + if (val) { + this.completers = completers + this.commands.addCommand(Autocomplete.startCommand); + } else { + this.commands.removeCommand(Autocomplete.startCommand); + } + }, + value: true + }, + enableSnippets: { + set: function(val) { + if (val) { + this.commands.addCommand(expandSnippet); + } else { + this.commands.removeCommand(expandSnippet); + } + }, + value: true + } +}); }); \ No newline at end of file diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index e7fbab5b..1309c295 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -40,8 +40,8 @@ var BROKEN_SETDATA = useragent.isChrome < 18; var TextInput = function(parentNode, host) { var text = dom.createElement("textarea"); text.className = "ace_text-input"; - /*/ debug - text.style.cssText = "opacity:1;background:rgba(0, 250, 0, 0.3);outline:rgba(0, 250, 0, 0.8) solid 1px;outline-offset:3px;width:5em;z-index:500"; + // debug + text.style.cssText = "opacity:1;background:rgba(0, 250, 0, 0.3);outline:rgba(0, 250, 0, 0.8) solid 1px;outline-offset:3px;width:5em;z-pindex:500"; /**/ if (useragent.isTouchPad) text.setAttribute("x-palm-disable-auto-cap", true); @@ -436,10 +436,10 @@ var TextInput = function(parentNode, host) { tempStyle = text.style.cssText; text.style.cssText = "z-index:100000;" + (useragent.isIE ? "opacity:0.1;" : ""); - // text.style.cssText += "background:rgba(250, 0, 0, 0.3); opacity:1;"; + text.style.cssText += "background:rgba(250, 0, 0, 0.3); opacity:1;"; resetSelection(host.selection.isEmpty()); - host._emit("nativecontextmenu", {target: host}); + host._emit("nativecontextmenu", {target: host, domEvent: e}); var rect = host.container.getBoundingClientRect(); var style = dom.computedStyle(host.container); var top = rect.top + (parseInt(style.borderTopWidth) || 0); @@ -477,7 +477,7 @@ var TextInput = function(parentNode, host) { } // firefox fires contextmenu event after opening it - if (!useragent.isGecko) { + if (!useragent.isGecko || useragent.isMac) { event.addListener(text, "contextmenu", function(e) { host.textInput.onContextMenu(e); onContextMenuClose(); diff --git a/lib/ace/mode/abap.js b/lib/ace/mode/abap.js index 53cd9532..fbd8066a 100644 --- a/lib/ace/mode/abap.js +++ b/lib/ace/mode/abap.js @@ -41,7 +41,7 @@ var oop = require("../lib/oop"); function Mode() { var highlighter = new Rules(); this.$tokenizer = new Tokenizer(highlighter.getRules()); - this.$keywordList = new Rules(rules.$keywordList); + this.$keywordList = new Rules(highlighter.$keywordList); this.foldingRules = new FoldMode(); } diff --git a/tool/tmtheme.js b/tool/tmtheme.js index 7bfc07ea..c01fb16f 100755 --- a/tool/tmtheme.js +++ b/tool/tmtheme.js @@ -247,6 +247,7 @@ var themes = { "pastel_on_dark": "Pastels on Dark", "solarized_dark": "Solarized-dark", "solarized_light": "Solarized-light", + "katzenmilch": "Katzenmilch", //"textmate": "Textmate (Mac Classic)", "tomorrow": "Tomorrow", "tomorrow_night": "Tomorrow-Night", From c2b7d1f08274ba72a73d7a9033dce504721a9460 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 1 Jun 2013 22:32:27 +0400 Subject: [PATCH 22/31] better style for match highlight in popup --- lib/ace/autocomplete/popup.js | 5 ++++- lib/ace/css/editor.css | 15 ++++++++++++++- lib/ace/edit_session/folding.js | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/ace/autocomplete/popup.js b/lib/ace/autocomplete/popup.js index c6b401b2..85a5d8b7 100644 --- a/lib/ace/autocomplete/popup.js +++ b/lib/ace/autocomplete/popup.js @@ -93,6 +93,7 @@ var $singleLineEditor = function(el) { var AcePopup = function(parentNode) { var el = dom.createElement("div"); var popup = new $singleLineEditor(el); + if (parentNode) parentNode.appendChild(el); el.style.display = "none"; @@ -111,7 +112,9 @@ var AcePopup = function(parentNode) { popup.renderer.$keepTextAreaAtCursor = false; popup.setHighlightActiveLine(true); - popup.setSession(new EditSession("")); + // set default highlight color + popup.session.highlight(""); + popup.session.$searchHighlight.clazz = "ace_highlight-marker"; popup.on("mousedown", function(e) { var pos = e.getDocumentPosition(); diff --git a/lib/ace/css/editor.css b/lib/ace/css/editor.css index 4f32b905..8ebc1616 100644 --- a/lib/ace/css/editor.css +++ b/lib/ace/css/editor.css @@ -181,7 +181,7 @@ white-space: nowrap; } -.ace_marker-layer .ace_step { +.ace_marker-layer .ace_step, .ace_marker-layer .ace_stack { position: absolute; z-index: 3; } @@ -386,3 +386,16 @@ .ace_italic { font-style: italic; } + + +.ace_error-marker { + background-color: rgba(255, 0, 0,0.2); + position: absolute; + z-index: 9; +} + +.ace_highlight-marker { + background-color: rgba(255, 255, 0,0.2); + position: absolute; + z-index: 8; +} diff --git a/lib/ace/edit_session/folding.js b/lib/ace/edit_session/folding.js index e85d4f0c..b36857c6 100644 --- a/lib/ace/edit_session/folding.js +++ b/lib/ace/edit_session/folding.js @@ -639,8 +639,8 @@ function Folding() { if (range && range.end.row <= endRow) try { var fold = this.addFold("...", range); fold.collapseChildren = depth; + row = range.end.row; } catch(e) {} - row = range.end.row; } }; From c223f59e1ace162f0a5885c06de9a106a4b467c7 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 3 Jun 2013 14:39:10 +0400 Subject: [PATCH 23/31] add scope to snippets.js files --- Makefile.dryice.js | 56 ++++++++++++------------- lib/ace/snippets/abap.js | 2 +- lib/ace/snippets/actionscript.js | 7 ++++ lib/ace/snippets/ada.js | 7 ++++ lib/ace/snippets/ada.snippets | 0 lib/ace/snippets/asciidoc.js | 2 +- lib/ace/snippets/assembly_x86.js | 7 ++++ lib/ace/snippets/assembly_x86.snippets | 0 lib/ace/snippets/autohotkey.js | 7 ++++ lib/ace/snippets/autohotkey.snippets | 0 lib/ace/snippets/batchfile.js | 7 ++++ lib/ace/snippets/batchfile.snippets | 0 lib/ace/snippets/c9search.js | 2 +- lib/ace/snippets/c_cpp.js | 2 +- lib/ace/snippets/clojure.js | 2 +- lib/ace/snippets/cobol.js | 7 ++++ lib/ace/snippets/cobol.snippets | 0 lib/ace/snippets/coffee.js | 2 +- lib/ace/snippets/coldfusion.js | 2 +- lib/ace/snippets/csharp.js | 2 +- lib/ace/snippets/css.js | 2 +- lib/ace/snippets/curly.js | 2 +- lib/ace/snippets/d.js | 7 ++++ lib/ace/snippets/d.snippets | 0 lib/ace/snippets/dart.js | 2 +- lib/ace/snippets/diff.js | 2 +- lib/ace/snippets/django.js | 2 +- lib/ace/snippets/dot.js | 2 +- lib/ace/snippets/ejs.js | 7 ++++ lib/ace/snippets/ejs.snippets | 0 lib/ace/snippets/erlang.js | 7 ++++ lib/ace/snippets/forth.js | 7 ++++ lib/ace/snippets/forth.snippets | 0 lib/ace/snippets/ftl.js | 2 +- lib/ace/snippets/glsl.js | 2 +- lib/ace/snippets/golang.js | 2 +- lib/ace/snippets/groovy.js | 2 +- lib/ace/snippets/haml.js | 2 +- lib/ace/snippets/haskell.js | 7 ++++ lib/ace/snippets/haxe.js | 2 +- lib/ace/snippets/html.js | 2 +- lib/ace/snippets/html_ruby.js | 7 ++++ lib/ace/snippets/html_ruby.snippets | 0 lib/ace/snippets/ini.js | 7 ++++ lib/ace/snippets/ini.snippets | 0 lib/ace/snippets/jade.js | 2 +- lib/ace/snippets/java.js | 2 +- lib/ace/snippets/javascript.js | 2 +- lib/ace/snippets/json.js | 2 +- lib/ace/snippets/jsoniq.js | 7 ++++ lib/ace/snippets/jsoniq.snippets | 0 lib/ace/snippets/jsp.js | 2 +- lib/ace/snippets/jsx.js | 2 +- lib/ace/snippets/julia.js | 7 ++++ lib/ace/snippets/julia.snippets | 0 lib/ace/snippets/latex.js | 2 +- lib/ace/snippets/less.js | 2 +- lib/ace/snippets/liquid.js | 2 +- lib/ace/snippets/lisp.js | 2 +- lib/ace/snippets/livescript.js | 2 +- lib/ace/snippets/logiql.js | 2 +- lib/ace/snippets/lsl.js | 2 +- lib/ace/snippets/lua.js | 2 +- lib/ace/snippets/luapage.js | 2 +- lib/ace/snippets/lucene.js | 2 +- lib/ace/snippets/makefile.js | 2 +- lib/ace/snippets/markdown.js | 2 +- lib/ace/snippets/matlab.js | 7 ++++ lib/ace/snippets/matlab.snippets | 0 lib/ace/snippets/mushcode.js | 2 +- lib/ace/snippets/mushcode_high_rules.js | 2 +- lib/ace/snippets/mysql.js | 7 ++++ lib/ace/snippets/mysql.snippets | 0 lib/ace/snippets/objectivec.js | 2 +- lib/ace/snippets/ocaml.js | 2 +- lib/ace/snippets/pascal.js | 2 +- lib/ace/snippets/perl.js | 2 +- lib/ace/snippets/pgsql.js | 2 +- lib/ace/snippets/php.js | 2 +- lib/ace/snippets/powershell.js | 2 +- lib/ace/snippets/prolog.js | 7 ++++ lib/ace/snippets/prolog.snippets | 0 lib/ace/snippets/properties.js | 7 ++++ lib/ace/snippets/properties.snippets | 0 lib/ace/snippets/python.js | 2 +- lib/ace/snippets/r.js | 2 +- lib/ace/snippets/rdoc.js | 2 +- lib/ace/snippets/rhtml.js | 2 +- lib/ace/snippets/ruby.js | 2 +- lib/ace/snippets/rust.js | 7 ++++ lib/ace/snippets/rust.snippets | 0 lib/ace/snippets/sass.js | 2 +- lib/ace/snippets/scad.js | 2 +- lib/ace/snippets/scala.js | 2 +- lib/ace/snippets/scheme.js | 2 +- lib/ace/snippets/scss.js | 2 +- lib/ace/snippets/sh.js | 2 +- lib/ace/snippets/snippets.js | 7 ++++ lib/ace/snippets/sql.js | 2 +- lib/ace/snippets/stylus.js | 2 +- lib/ace/snippets/svg.js | 2 +- lib/ace/snippets/tcl.js | 2 +- lib/ace/snippets/tex.js | 2 +- lib/ace/snippets/text.js | 2 +- lib/ace/snippets/textile.js | 2 +- lib/ace/snippets/tmsnippet.js | 7 ---- lib/ace/snippets/toml.js | 2 +- lib/ace/snippets/twig.js | 7 ++++ lib/ace/snippets/twig.snippets | 0 lib/ace/snippets/typescript.js | 2 +- lib/ace/snippets/vbscript.js | 2 +- lib/ace/snippets/velocity.js | 2 +- lib/ace/snippets/verilog.js | 7 ++++ lib/ace/snippets/verilog.snippets | 0 lib/ace/snippets/xml.js | 2 +- lib/ace/snippets/xquery.js | 2 +- lib/ace/snippets/yaml.js | 2 +- 117 files changed, 262 insertions(+), 108 deletions(-) create mode 100644 lib/ace/snippets/actionscript.js create mode 100644 lib/ace/snippets/ada.js create mode 100644 lib/ace/snippets/ada.snippets create mode 100644 lib/ace/snippets/assembly_x86.js create mode 100644 lib/ace/snippets/assembly_x86.snippets create mode 100644 lib/ace/snippets/autohotkey.js create mode 100644 lib/ace/snippets/autohotkey.snippets create mode 100644 lib/ace/snippets/batchfile.js create mode 100644 lib/ace/snippets/batchfile.snippets create mode 100644 lib/ace/snippets/cobol.js create mode 100644 lib/ace/snippets/cobol.snippets create mode 100644 lib/ace/snippets/d.js create mode 100644 lib/ace/snippets/d.snippets create mode 100644 lib/ace/snippets/ejs.js create mode 100644 lib/ace/snippets/ejs.snippets create mode 100644 lib/ace/snippets/erlang.js create mode 100644 lib/ace/snippets/forth.js create mode 100644 lib/ace/snippets/forth.snippets create mode 100644 lib/ace/snippets/haskell.js create mode 100644 lib/ace/snippets/html_ruby.js create mode 100644 lib/ace/snippets/html_ruby.snippets create mode 100644 lib/ace/snippets/ini.js create mode 100644 lib/ace/snippets/ini.snippets create mode 100644 lib/ace/snippets/jsoniq.js create mode 100644 lib/ace/snippets/jsoniq.snippets create mode 100644 lib/ace/snippets/julia.js create mode 100644 lib/ace/snippets/julia.snippets create mode 100644 lib/ace/snippets/matlab.js create mode 100644 lib/ace/snippets/matlab.snippets create mode 100644 lib/ace/snippets/mysql.js create mode 100644 lib/ace/snippets/mysql.snippets create mode 100644 lib/ace/snippets/prolog.js create mode 100644 lib/ace/snippets/prolog.snippets create mode 100644 lib/ace/snippets/properties.js create mode 100644 lib/ace/snippets/properties.snippets create mode 100644 lib/ace/snippets/rust.js create mode 100644 lib/ace/snippets/rust.snippets create mode 100644 lib/ace/snippets/snippets.js delete mode 100644 lib/ace/snippets/tmsnippet.js create mode 100644 lib/ace/snippets/twig.js create mode 100644 lib/ace/snippets/twig.snippets create mode 100644 lib/ace/snippets/verilog.js create mode 100644 lib/ace/snippets/verilog.snippets diff --git a/Makefile.dryice.js b/Makefile.dryice.js index 9ac8fc99..cf3a4148 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -155,7 +155,7 @@ function ace() { source: ACE_HOME + "/ChangeLog.txt", dest: BUILD_DIR + "/ChangeLog.txt" }); - + return project; } @@ -211,7 +211,7 @@ function demo(project) { }); var demo = copy.createDataObject(); - + project.assumeAllFilesLoaded(); copy({ source: [{ @@ -309,7 +309,7 @@ var buildAce = function(options) { for(var key in defaults) if (!options.hasOwnProperty(key)) options[key] = defaults[key]; - + generateThemesModule(options.themes); addSuffix(options); @@ -334,7 +334,7 @@ var buildAce = function(options) { filter: [ copy.filter.moduleDefines ], dest: ace }); - + if (options.coreOnly) return project; @@ -349,7 +349,7 @@ var buildAce = function(options) { project.assumeAllFilesLoaded(); options.modes.forEach(function(mode) { console.log("mode " + mode); - addSnippetFile(mode, project, targetDir, options); + addSnippetFile(mode, project, targetDir, options); copy({ source: [{ project: cloneProject(project), @@ -442,7 +442,7 @@ var buildAce = function(options) { dest: BUILD_DIR + '/ace-min.js' }); } - + return project; }; @@ -462,27 +462,27 @@ var buildAce = function(fn) { }(buildAce); var addSnippetFile = function(modeName, project, targetDir, options) { - var snippetFilePath = ACE_HOME + "/lib/ace/snippets/" + modeName; - if (!fs.existsSync(snippetFilePath + ".js")) { - copy({ - source: ACE_HOME + "/tool/snippet.tmpl.js", - dest: snippetFilePath + ".js", - filter: [ - function(t) {return t.replace("%modeName%", modeName);} - ] - }); - } - if (!fs.existsSync(snippetFilePath + ".snippets")) { - fs.writeFileSync(snippetFilePath + ".snippets", "") - } - copy({ - source: [{ - project: cloneProject(project), - require: [ 'ace/snippets/' + modeName ] - }], - filter: getWriteFilters(options, "mode"), - dest: targetDir + "/snippets/" + modeName + ".js" - }); + var snippetFilePath = ACE_HOME + "/lib/ace/snippets/" + modeName; + if (!fs.existsSync(snippetFilePath + ".js")) { + copy({ + source: ACE_HOME + "/tool/snippets.tmpl.js", + dest: snippetFilePath + ".js", + filter: [ + function(t) {return t.replace(/%modeName%/g, modeName);} + ] + }); + } + if (!fs.existsSync(snippetFilePath + ".snippets")) { + fs.writeFileSync(snippetFilePath + ".snippets", "") + } + copy({ + source: [{ + project: cloneProject(project), + require: [ 'ace/snippets/' + modeName ] + }], + filter: getWriteFilters(options, "mode"), + dest: targetDir + "/snippets/" + modeName + ".js" + }); } var textModules = {} @@ -494,7 +494,7 @@ var detectTextModules = function(input, source) { input = input.toString(); var module = source.isLocation ? source.path : source; - + input = input.replace(/\\/g, "\\\\").replace(/"/g, '\\"'); if (/\.css$/.test(module)) { // remove unnecessary whitespace from css diff --git a/lib/ace/snippets/abap.js b/lib/ace/snippets/abap.js index 40870ff7..902cb1bb 100644 --- a/lib/ace/snippets/abap.js +++ b/lib/ace/snippets/abap.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./abap.snippets"); - +exports.scope = "abap"; }); diff --git a/lib/ace/snippets/actionscript.js b/lib/ace/snippets/actionscript.js new file mode 100644 index 00000000..5d4e2168 --- /dev/null +++ b/lib/ace/snippets/actionscript.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./actionscript.snippets"); +exports.scope = "actionscript"; + +}); diff --git a/lib/ace/snippets/ada.js b/lib/ace/snippets/ada.js new file mode 100644 index 00000000..5b3ea215 --- /dev/null +++ b/lib/ace/snippets/ada.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./ada.snippets"); +exports.scope = "ada"; + +}); diff --git a/lib/ace/snippets/ada.snippets b/lib/ace/snippets/ada.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/asciidoc.js b/lib/ace/snippets/asciidoc.js index 0d8d353b..7857020c 100644 --- a/lib/ace/snippets/asciidoc.js +++ b/lib/ace/snippets/asciidoc.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./asciidoc.snippets"); - +exports.scope = "asciidoc"; }); diff --git a/lib/ace/snippets/assembly_x86.js b/lib/ace/snippets/assembly_x86.js new file mode 100644 index 00000000..747335be --- /dev/null +++ b/lib/ace/snippets/assembly_x86.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./assembly_x86.snippets"); +exports.scope = "assembly_x86"; + +}); diff --git a/lib/ace/snippets/assembly_x86.snippets b/lib/ace/snippets/assembly_x86.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/autohotkey.js b/lib/ace/snippets/autohotkey.js new file mode 100644 index 00000000..064647e3 --- /dev/null +++ b/lib/ace/snippets/autohotkey.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./autohotkey.snippets"); +exports.scope = "autohotkey"; + +}); diff --git a/lib/ace/snippets/autohotkey.snippets b/lib/ace/snippets/autohotkey.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/batchfile.js b/lib/ace/snippets/batchfile.js new file mode 100644 index 00000000..ec949d96 --- /dev/null +++ b/lib/ace/snippets/batchfile.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./batchfile.snippets"); +exports.scope = "batchfile"; + +}); diff --git a/lib/ace/snippets/batchfile.snippets b/lib/ace/snippets/batchfile.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/c9search.js b/lib/ace/snippets/c9search.js index da0d3101..62bc4403 100644 --- a/lib/ace/snippets/c9search.js +++ b/lib/ace/snippets/c9search.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./c9search.snippets"); - +exports.scope = "c9search"; }); diff --git a/lib/ace/snippets/c_cpp.js b/lib/ace/snippets/c_cpp.js index b9555c14..cf37a62a 100644 --- a/lib/ace/snippets/c_cpp.js +++ b/lib/ace/snippets/c_cpp.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./c_cpp.snippets"); - +exports.scope = "c_cpp"; }); diff --git a/lib/ace/snippets/clojure.js b/lib/ace/snippets/clojure.js index 8a1cf1c5..8f07e5fe 100644 --- a/lib/ace/snippets/clojure.js +++ b/lib/ace/snippets/clojure.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./clojure.snippets"); - +exports.scope = "clojure"; }); diff --git a/lib/ace/snippets/cobol.js b/lib/ace/snippets/cobol.js new file mode 100644 index 00000000..885f1c46 --- /dev/null +++ b/lib/ace/snippets/cobol.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./cobol.snippets"); +exports.scope = "cobol"; + +}); diff --git a/lib/ace/snippets/cobol.snippets b/lib/ace/snippets/cobol.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/coffee.js b/lib/ace/snippets/coffee.js index 788227b6..5511ed11 100644 --- a/lib/ace/snippets/coffee.js +++ b/lib/ace/snippets/coffee.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./coffee.snippets"); - +exports.scope = "coffee"; }); diff --git a/lib/ace/snippets/coldfusion.js b/lib/ace/snippets/coldfusion.js index 0002b081..6f44f9f7 100644 --- a/lib/ace/snippets/coldfusion.js +++ b/lib/ace/snippets/coldfusion.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./coldfusion.snippets"); - +exports.scope = "coldfusion"; }); diff --git a/lib/ace/snippets/csharp.js b/lib/ace/snippets/csharp.js index 99fbe4ce..3aafdf85 100644 --- a/lib/ace/snippets/csharp.js +++ b/lib/ace/snippets/csharp.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./csharp.snippets"); - +exports.scope = "csharp"; }); diff --git a/lib/ace/snippets/css.js b/lib/ace/snippets/css.js index a5d3e744..5d7e66ed 100644 --- a/lib/ace/snippets/css.js +++ b/lib/ace/snippets/css.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./css.snippets"); - +exports.scope = "css"; }); diff --git a/lib/ace/snippets/curly.js b/lib/ace/snippets/curly.js index ee584465..aa59f286 100644 --- a/lib/ace/snippets/curly.js +++ b/lib/ace/snippets/curly.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./curly.snippets"); - +exports.scope = "curly"; }); diff --git a/lib/ace/snippets/d.js b/lib/ace/snippets/d.js new file mode 100644 index 00000000..79446fdc --- /dev/null +++ b/lib/ace/snippets/d.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./d.snippets"); +exports.scope = "d"; + +}); diff --git a/lib/ace/snippets/d.snippets b/lib/ace/snippets/d.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/dart.js b/lib/ace/snippets/dart.js index be721176..949fcaa3 100644 --- a/lib/ace/snippets/dart.js +++ b/lib/ace/snippets/dart.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./dart.snippets"); - +exports.scope = "dart"; }); diff --git a/lib/ace/snippets/diff.js b/lib/ace/snippets/diff.js index 5ed1e646..eb48cbc1 100644 --- a/lib/ace/snippets/diff.js +++ b/lib/ace/snippets/diff.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./diff.snippets"); - +exports.scope = "diff"; }); diff --git a/lib/ace/snippets/django.js b/lib/ace/snippets/django.js index 7ecc97d1..b5af7a73 100644 --- a/lib/ace/snippets/django.js +++ b/lib/ace/snippets/django.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./django.snippets"); - +exports.scope = "django"; }); diff --git a/lib/ace/snippets/dot.js b/lib/ace/snippets/dot.js index 7a2f1792..420f4f01 100644 --- a/lib/ace/snippets/dot.js +++ b/lib/ace/snippets/dot.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./dot.snippets"); - +exports.scope = "dot"; }); diff --git a/lib/ace/snippets/ejs.js b/lib/ace/snippets/ejs.js new file mode 100644 index 00000000..be477738 --- /dev/null +++ b/lib/ace/snippets/ejs.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./ejs.snippets"); +exports.scope = "ejs"; + +}); diff --git a/lib/ace/snippets/ejs.snippets b/lib/ace/snippets/ejs.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/erlang.js b/lib/ace/snippets/erlang.js new file mode 100644 index 00000000..212e3640 --- /dev/null +++ b/lib/ace/snippets/erlang.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./erlang.snippets"); +exports.scope = "erlang"; + +}); diff --git a/lib/ace/snippets/forth.js b/lib/ace/snippets/forth.js new file mode 100644 index 00000000..c2bf9107 --- /dev/null +++ b/lib/ace/snippets/forth.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./forth.snippets"); +exports.scope = "forth"; + +}); diff --git a/lib/ace/snippets/forth.snippets b/lib/ace/snippets/forth.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/ftl.js b/lib/ace/snippets/ftl.js index ef9d12e0..1cbcc0be 100644 --- a/lib/ace/snippets/ftl.js +++ b/lib/ace/snippets/ftl.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./ftl.snippets"); - +exports.scope = "ftl"; }); diff --git a/lib/ace/snippets/glsl.js b/lib/ace/snippets/glsl.js index 729e0890..d9c5fc25 100644 --- a/lib/ace/snippets/glsl.js +++ b/lib/ace/snippets/glsl.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./glsl.snippets"); - +exports.scope = "glsl"; }); diff --git a/lib/ace/snippets/golang.js b/lib/ace/snippets/golang.js index e6b169c9..f7b0eecc 100644 --- a/lib/ace/snippets/golang.js +++ b/lib/ace/snippets/golang.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./golang.snippets"); - +exports.scope = "golang"; }); diff --git a/lib/ace/snippets/groovy.js b/lib/ace/snippets/groovy.js index 33bcb3d2..2fe4e111 100644 --- a/lib/ace/snippets/groovy.js +++ b/lib/ace/snippets/groovy.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./groovy.snippets"); - +exports.scope = "groovy"; }); diff --git a/lib/ace/snippets/haml.js b/lib/ace/snippets/haml.js index eb1b5fb2..efa8eb9c 100644 --- a/lib/ace/snippets/haml.js +++ b/lib/ace/snippets/haml.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./haml.snippets"); - +exports.scope = "haml"; }); diff --git a/lib/ace/snippets/haskell.js b/lib/ace/snippets/haskell.js new file mode 100644 index 00000000..8c583f1c --- /dev/null +++ b/lib/ace/snippets/haskell.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./haskell.snippets"); +exports.scope = "haskell"; + +}); diff --git a/lib/ace/snippets/haxe.js b/lib/ace/snippets/haxe.js index 660addb7..b67f91eb 100644 --- a/lib/ace/snippets/haxe.js +++ b/lib/ace/snippets/haxe.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./haxe.snippets"); - +exports.scope = "haxe"; }); diff --git a/lib/ace/snippets/html.js b/lib/ace/snippets/html.js index 18db8416..bac3bea3 100644 --- a/lib/ace/snippets/html.js +++ b/lib/ace/snippets/html.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./html.snippets"); - +exports.scope = "html"; }); diff --git a/lib/ace/snippets/html_ruby.js b/lib/ace/snippets/html_ruby.js new file mode 100644 index 00000000..d985d568 --- /dev/null +++ b/lib/ace/snippets/html_ruby.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./html_ruby.snippets"); +exports.scope = "html_ruby"; + +}); diff --git a/lib/ace/snippets/html_ruby.snippets b/lib/ace/snippets/html_ruby.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/ini.js b/lib/ace/snippets/ini.js new file mode 100644 index 00000000..df09d575 --- /dev/null +++ b/lib/ace/snippets/ini.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./ini.snippets"); +exports.scope = "ini"; + +}); diff --git a/lib/ace/snippets/ini.snippets b/lib/ace/snippets/ini.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/jade.js b/lib/ace/snippets/jade.js index e272e831..ca83d483 100644 --- a/lib/ace/snippets/jade.js +++ b/lib/ace/snippets/jade.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./jade.snippets"); - +exports.scope = "jade"; }); diff --git a/lib/ace/snippets/java.js b/lib/ace/snippets/java.js index 9b861bf5..7d05e84a 100644 --- a/lib/ace/snippets/java.js +++ b/lib/ace/snippets/java.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./java.snippets"); - +exports.scope = "java"; }); diff --git a/lib/ace/snippets/javascript.js b/lib/ace/snippets/javascript.js index fe370b06..bf59ba85 100644 --- a/lib/ace/snippets/javascript.js +++ b/lib/ace/snippets/javascript.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./javascript.snippets"); - +exports.scope = "javascript"; }); diff --git a/lib/ace/snippets/json.js b/lib/ace/snippets/json.js index cbecb6e1..d57fe6c5 100644 --- a/lib/ace/snippets/json.js +++ b/lib/ace/snippets/json.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./json.snippets"); - +exports.scope = "json"; }); diff --git a/lib/ace/snippets/jsoniq.js b/lib/ace/snippets/jsoniq.js new file mode 100644 index 00000000..9bde24cf --- /dev/null +++ b/lib/ace/snippets/jsoniq.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./jsoniq.snippets"); +exports.scope = "jsoniq"; + +}); diff --git a/lib/ace/snippets/jsoniq.snippets b/lib/ace/snippets/jsoniq.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/jsp.js b/lib/ace/snippets/jsp.js index 0f39d9af..2324c541 100644 --- a/lib/ace/snippets/jsp.js +++ b/lib/ace/snippets/jsp.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./jsp.snippets"); - +exports.scope = "jsp"; }); diff --git a/lib/ace/snippets/jsx.js b/lib/ace/snippets/jsx.js index 5c31e99f..9792a7a0 100644 --- a/lib/ace/snippets/jsx.js +++ b/lib/ace/snippets/jsx.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./jsx.snippets"); - +exports.scope = "jsx"; }); diff --git a/lib/ace/snippets/julia.js b/lib/ace/snippets/julia.js new file mode 100644 index 00000000..f83777ef --- /dev/null +++ b/lib/ace/snippets/julia.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./julia.snippets"); +exports.scope = "julia"; + +}); diff --git a/lib/ace/snippets/julia.snippets b/lib/ace/snippets/julia.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/latex.js b/lib/ace/snippets/latex.js index 98fc6a48..44bef369 100644 --- a/lib/ace/snippets/latex.js +++ b/lib/ace/snippets/latex.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./latex.snippets"); - +exports.scope = "latex"; }); diff --git a/lib/ace/snippets/less.js b/lib/ace/snippets/less.js index c2af7180..7acf02f2 100644 --- a/lib/ace/snippets/less.js +++ b/lib/ace/snippets/less.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./less.snippets"); - +exports.scope = "less"; }); diff --git a/lib/ace/snippets/liquid.js b/lib/ace/snippets/liquid.js index 1f76c3cc..2e320755 100644 --- a/lib/ace/snippets/liquid.js +++ b/lib/ace/snippets/liquid.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./liquid.snippets"); - +exports.scope = "liquid"; }); diff --git a/lib/ace/snippets/lisp.js b/lib/ace/snippets/lisp.js index 9dc94deb..2b6870bc 100644 --- a/lib/ace/snippets/lisp.js +++ b/lib/ace/snippets/lisp.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./lisp.snippets"); - +exports.scope = "lisp"; }); diff --git a/lib/ace/snippets/livescript.js b/lib/ace/snippets/livescript.js index 707ea6a4..ba20e7e4 100644 --- a/lib/ace/snippets/livescript.js +++ b/lib/ace/snippets/livescript.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./livescript.snippets"); - +exports.scope = "livescript"; }); diff --git a/lib/ace/snippets/logiql.js b/lib/ace/snippets/logiql.js index c879daac..7d0167da 100644 --- a/lib/ace/snippets/logiql.js +++ b/lib/ace/snippets/logiql.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./logiql.snippets"); - +exports.scope = "logiql"; }); diff --git a/lib/ace/snippets/lsl.js b/lib/ace/snippets/lsl.js index 342c8fb1..678ba41f 100644 --- a/lib/ace/snippets/lsl.js +++ b/lib/ace/snippets/lsl.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./lsl.snippets"); - +exports.scope = "lsl"; }); diff --git a/lib/ace/snippets/lua.js b/lib/ace/snippets/lua.js index 8ccd6fcb..0ab6fdcd 100644 --- a/lib/ace/snippets/lua.js +++ b/lib/ace/snippets/lua.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./lua.snippets"); - +exports.scope = "lua"; }); diff --git a/lib/ace/snippets/luapage.js b/lib/ace/snippets/luapage.js index b6671d63..86b22842 100644 --- a/lib/ace/snippets/luapage.js +++ b/lib/ace/snippets/luapage.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./luapage.snippets"); - +exports.scope = "luapage"; }); diff --git a/lib/ace/snippets/lucene.js b/lib/ace/snippets/lucene.js index 014daa76..01edb07d 100644 --- a/lib/ace/snippets/lucene.js +++ b/lib/ace/snippets/lucene.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./lucene.snippets"); - +exports.scope = "lucene"; }); diff --git a/lib/ace/snippets/makefile.js b/lib/ace/snippets/makefile.js index 3239254c..0ec05ac0 100644 --- a/lib/ace/snippets/makefile.js +++ b/lib/ace/snippets/makefile.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./makefile.snippets"); - +exports.scope = "makefile"; }); diff --git a/lib/ace/snippets/markdown.js b/lib/ace/snippets/markdown.js index 1a247b2c..3940bc90 100644 --- a/lib/ace/snippets/markdown.js +++ b/lib/ace/snippets/markdown.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./markdown.snippets"); - +exports.scope = "markdown"; }); diff --git a/lib/ace/snippets/matlab.js b/lib/ace/snippets/matlab.js new file mode 100644 index 00000000..698366ba --- /dev/null +++ b/lib/ace/snippets/matlab.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./matlab.snippets"); +exports.scope = "matlab"; + +}); diff --git a/lib/ace/snippets/matlab.snippets b/lib/ace/snippets/matlab.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/mushcode.js b/lib/ace/snippets/mushcode.js index 3c9f52fc..8b0d2dcb 100644 --- a/lib/ace/snippets/mushcode.js +++ b/lib/ace/snippets/mushcode.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./mushcode.snippets"); - +exports.scope = "mushcode"; }); diff --git a/lib/ace/snippets/mushcode_high_rules.js b/lib/ace/snippets/mushcode_high_rules.js index e4670deb..25d42827 100644 --- a/lib/ace/snippets/mushcode_high_rules.js +++ b/lib/ace/snippets/mushcode_high_rules.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./mushcode_high_rules.snippets"); - +exports.scope = "mushcode_high_rules"; }); diff --git a/lib/ace/snippets/mysql.js b/lib/ace/snippets/mysql.js new file mode 100644 index 00000000..e5462390 --- /dev/null +++ b/lib/ace/snippets/mysql.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./mysql.snippets"); +exports.scope = "mysql"; + +}); diff --git a/lib/ace/snippets/mysql.snippets b/lib/ace/snippets/mysql.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/objectivec.js b/lib/ace/snippets/objectivec.js index 2e200fbd..ed5d5fa8 100644 --- a/lib/ace/snippets/objectivec.js +++ b/lib/ace/snippets/objectivec.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./objectivec.snippets"); - +exports.scope = "objectivec"; }); diff --git a/lib/ace/snippets/ocaml.js b/lib/ace/snippets/ocaml.js index 805c6a37..a6e6842e 100644 --- a/lib/ace/snippets/ocaml.js +++ b/lib/ace/snippets/ocaml.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./ocaml.snippets"); - +exports.scope = "ocaml"; }); diff --git a/lib/ace/snippets/pascal.js b/lib/ace/snippets/pascal.js index 8d2fa6f4..cd8f19fe 100644 --- a/lib/ace/snippets/pascal.js +++ b/lib/ace/snippets/pascal.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./pascal.snippets"); - +exports.scope = "pascal"; }); diff --git a/lib/ace/snippets/perl.js b/lib/ace/snippets/perl.js index 70d2e8d6..9b1fbe8d 100644 --- a/lib/ace/snippets/perl.js +++ b/lib/ace/snippets/perl.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./perl.snippets"); - +exports.scope = "perl"; }); diff --git a/lib/ace/snippets/pgsql.js b/lib/ace/snippets/pgsql.js index 7b2bc647..9bbd9012 100644 --- a/lib/ace/snippets/pgsql.js +++ b/lib/ace/snippets/pgsql.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./pgsql.snippets"); - +exports.scope = "pgsql"; }); diff --git a/lib/ace/snippets/php.js b/lib/ace/snippets/php.js index e10929e9..b8f8ce0e 100644 --- a/lib/ace/snippets/php.js +++ b/lib/ace/snippets/php.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./php.snippets"); - +exports.scope = "php"; }); diff --git a/lib/ace/snippets/powershell.js b/lib/ace/snippets/powershell.js index 8b30a0b5..4639a304 100644 --- a/lib/ace/snippets/powershell.js +++ b/lib/ace/snippets/powershell.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./powershell.snippets"); - +exports.scope = "powershell"; }); diff --git a/lib/ace/snippets/prolog.js b/lib/ace/snippets/prolog.js new file mode 100644 index 00000000..7c9d0fbc --- /dev/null +++ b/lib/ace/snippets/prolog.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./prolog.snippets"); +exports.scope = "prolog"; + +}); diff --git a/lib/ace/snippets/prolog.snippets b/lib/ace/snippets/prolog.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/properties.js b/lib/ace/snippets/properties.js new file mode 100644 index 00000000..18bd3883 --- /dev/null +++ b/lib/ace/snippets/properties.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./properties.snippets"); +exports.scope = "properties"; + +}); diff --git a/lib/ace/snippets/properties.snippets b/lib/ace/snippets/properties.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/python.js b/lib/ace/snippets/python.js index bb17d22e..48ddba28 100644 --- a/lib/ace/snippets/python.js +++ b/lib/ace/snippets/python.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./python.snippets"); - +exports.scope = "python"; }); diff --git a/lib/ace/snippets/r.js b/lib/ace/snippets/r.js index f4fe2265..6b319194 100644 --- a/lib/ace/snippets/r.js +++ b/lib/ace/snippets/r.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./r.snippets"); - +exports.scope = "r"; }); diff --git a/lib/ace/snippets/rdoc.js b/lib/ace/snippets/rdoc.js index 758bdd9a..0d9e6c95 100644 --- a/lib/ace/snippets/rdoc.js +++ b/lib/ace/snippets/rdoc.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./rdoc.snippets"); - +exports.scope = "rdoc"; }); diff --git a/lib/ace/snippets/rhtml.js b/lib/ace/snippets/rhtml.js index a583b085..96707f21 100644 --- a/lib/ace/snippets/rhtml.js +++ b/lib/ace/snippets/rhtml.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./rhtml.snippets"); - +exports.scope = "rhtml"; }); diff --git a/lib/ace/snippets/ruby.js b/lib/ace/snippets/ruby.js index 4fccdbfa..f7050449 100644 --- a/lib/ace/snippets/ruby.js +++ b/lib/ace/snippets/ruby.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./ruby.snippets"); - +exports.scope = "ruby"; }); diff --git a/lib/ace/snippets/rust.js b/lib/ace/snippets/rust.js new file mode 100644 index 00000000..556d9a6b --- /dev/null +++ b/lib/ace/snippets/rust.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./rust.snippets"); +exports.scope = "rust"; + +}); diff --git a/lib/ace/snippets/rust.snippets b/lib/ace/snippets/rust.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/sass.js b/lib/ace/snippets/sass.js index 9ff1aa06..ba728ac2 100644 --- a/lib/ace/snippets/sass.js +++ b/lib/ace/snippets/sass.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./sass.snippets"); - +exports.scope = "sass"; }); diff --git a/lib/ace/snippets/scad.js b/lib/ace/snippets/scad.js index added1b4..28db2155 100644 --- a/lib/ace/snippets/scad.js +++ b/lib/ace/snippets/scad.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./scad.snippets"); - +exports.scope = "scad"; }); diff --git a/lib/ace/snippets/scala.js b/lib/ace/snippets/scala.js index d2281a49..2e5a8c57 100644 --- a/lib/ace/snippets/scala.js +++ b/lib/ace/snippets/scala.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./scala.snippets"); - +exports.scope = "scala"; }); diff --git a/lib/ace/snippets/scheme.js b/lib/ace/snippets/scheme.js index 208454f6..7d3c6f65 100644 --- a/lib/ace/snippets/scheme.js +++ b/lib/ace/snippets/scheme.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./scheme.snippets"); - +exports.scope = "scheme"; }); diff --git a/lib/ace/snippets/scss.js b/lib/ace/snippets/scss.js index cf621dd3..a940eabd 100644 --- a/lib/ace/snippets/scss.js +++ b/lib/ace/snippets/scss.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./scss.snippets"); - +exports.scope = "scss"; }); diff --git a/lib/ace/snippets/sh.js b/lib/ace/snippets/sh.js index ac859391..c48dc17f 100644 --- a/lib/ace/snippets/sh.js +++ b/lib/ace/snippets/sh.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./sh.snippets"); - +exports.scope = "sh"; }); diff --git a/lib/ace/snippets/snippets.js b/lib/ace/snippets/snippets.js new file mode 100644 index 00000000..0927805b --- /dev/null +++ b/lib/ace/snippets/snippets.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./snippets.snippets"); +exports.scope = "snippets"; + +}); diff --git a/lib/ace/snippets/sql.js b/lib/ace/snippets/sql.js index 34954dfa..c96f6cb2 100644 --- a/lib/ace/snippets/sql.js +++ b/lib/ace/snippets/sql.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./sql.snippets"); - +exports.scope = "sql"; }); diff --git a/lib/ace/snippets/stylus.js b/lib/ace/snippets/stylus.js index 97a414ef..86a79f7a 100644 --- a/lib/ace/snippets/stylus.js +++ b/lib/ace/snippets/stylus.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./stylus.snippets"); - +exports.scope = "stylus"; }); diff --git a/lib/ace/snippets/svg.js b/lib/ace/snippets/svg.js index db48fb32..aeb62456 100644 --- a/lib/ace/snippets/svg.js +++ b/lib/ace/snippets/svg.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./svg.snippets"); - +exports.scope = "svg"; }); diff --git a/lib/ace/snippets/tcl.js b/lib/ace/snippets/tcl.js index 1af7e59b..53482fc7 100644 --- a/lib/ace/snippets/tcl.js +++ b/lib/ace/snippets/tcl.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./tcl.snippets"); - +exports.scope = "tcl"; }); diff --git a/lib/ace/snippets/tex.js b/lib/ace/snippets/tex.js index d72e8320..267b6b69 100644 --- a/lib/ace/snippets/tex.js +++ b/lib/ace/snippets/tex.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./tex.snippets"); - +exports.scope = "tex"; }); diff --git a/lib/ace/snippets/text.js b/lib/ace/snippets/text.js index f88da241..434d75be 100644 --- a/lib/ace/snippets/text.js +++ b/lib/ace/snippets/text.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./text.snippets"); - +exports.scope = "text"; }); diff --git a/lib/ace/snippets/textile.js b/lib/ace/snippets/textile.js index 4bed9a59..f2622e05 100644 --- a/lib/ace/snippets/textile.js +++ b/lib/ace/snippets/textile.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./textile.snippets"); - +exports.scope = "textile"; }); diff --git a/lib/ace/snippets/tmsnippet.js b/lib/ace/snippets/tmsnippet.js deleted file mode 100644 index 38ea1af0..00000000 --- a/lib/ace/snippets/tmsnippet.js +++ /dev/null @@ -1,7 +0,0 @@ -define(function(require, exports, module) { -"use strict"; - -exports.snippetText = require("../requirejs/text!./tmsnippet.snippets"); - - -}); diff --git a/lib/ace/snippets/toml.js b/lib/ace/snippets/toml.js index 295bc824..419b06d8 100644 --- a/lib/ace/snippets/toml.js +++ b/lib/ace/snippets/toml.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./toml.snippets"); - +exports.scope = "toml"; }); diff --git a/lib/ace/snippets/twig.js b/lib/ace/snippets/twig.js new file mode 100644 index 00000000..b08b884c --- /dev/null +++ b/lib/ace/snippets/twig.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./twig.snippets"); +exports.scope = "twig"; + +}); diff --git a/lib/ace/snippets/twig.snippets b/lib/ace/snippets/twig.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/typescript.js b/lib/ace/snippets/typescript.js index fe01171e..495da3f3 100644 --- a/lib/ace/snippets/typescript.js +++ b/lib/ace/snippets/typescript.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./typescript.snippets"); - +exports.scope = "typescript"; }); diff --git a/lib/ace/snippets/vbscript.js b/lib/ace/snippets/vbscript.js index f6e370f3..5ab8e650 100644 --- a/lib/ace/snippets/vbscript.js +++ b/lib/ace/snippets/vbscript.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./vbscript.snippets"); - +exports.scope = "vbscript"; }); diff --git a/lib/ace/snippets/velocity.js b/lib/ace/snippets/velocity.js index 02f5b338..ef59f621 100644 --- a/lib/ace/snippets/velocity.js +++ b/lib/ace/snippets/velocity.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./velocity.snippets"); - +exports.scope = "velocity"; }); diff --git a/lib/ace/snippets/verilog.js b/lib/ace/snippets/verilog.js new file mode 100644 index 00000000..7360341e --- /dev/null +++ b/lib/ace/snippets/verilog.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./verilog.snippets"); +exports.scope = "verilog"; + +}); diff --git a/lib/ace/snippets/verilog.snippets b/lib/ace/snippets/verilog.snippets new file mode 100644 index 00000000..e69de29b diff --git a/lib/ace/snippets/xml.js b/lib/ace/snippets/xml.js index e9328060..83b1870c 100644 --- a/lib/ace/snippets/xml.js +++ b/lib/ace/snippets/xml.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./xml.snippets"); - +exports.scope = "xml"; }); diff --git a/lib/ace/snippets/xquery.js b/lib/ace/snippets/xquery.js index 0854dfb7..d96a0619 100644 --- a/lib/ace/snippets/xquery.js +++ b/lib/ace/snippets/xquery.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./xquery.snippets"); - +exports.scope = "xquery"; }); diff --git a/lib/ace/snippets/yaml.js b/lib/ace/snippets/yaml.js index bbdf8003..17e70a3c 100644 --- a/lib/ace/snippets/yaml.js +++ b/lib/ace/snippets/yaml.js @@ -2,6 +2,6 @@ define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./yaml.snippets"); - +exports.scope = "yaml"; }); From 36c166b9ed011d28cd4bd3a5991ca06d279a78b5 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 3 Jun 2013 14:44:57 +0400 Subject: [PATCH 24/31] force using tabs in makefile and snippets modes --- lib/ace/edit_session.js | 3 ++- lib/ace/mode/makefile.js | 4 +++- lib/ace/mode/snippets.js | 4 +--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index c8cb43ff..4f9ace1f 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -461,7 +461,8 @@ var EditSession = function(text, mode) { * @returns {Boolean} **/ this.getUseSoftTabs = function() { - return this.$useSoftTabs; + // todo might need more general way for changing settings from mode, but this is ok for now + return this.$useSoftTabs && !this.$mode.$indentWithTabs; }; /** * Set the number of spaces that define a soft tab; for example, passing in `4` transforms the soft tabs to be equivalent to four spaces. This function also emits the `changeTabSize` event. diff --git a/lib/ace/mode/makefile.js b/lib/ace/mode/makefile.js index a54171dd..e51a22bb 100644 --- a/lib/ace/mode/makefile.js +++ b/lib/ace/mode/makefile.js @@ -57,7 +57,9 @@ oop.inherits(Mode, TextMode); (function() { - this.lineCommentStart = "#"; + this.lineCommentStart = "#"; + this.$indentWithTabs = true; + }).call(Mode.prototype); exports.Mode = Mode; diff --git a/lib/ace/mode/snippets.js b/lib/ace/mode/snippets.js index d3e51863..ed394c8a 100644 --- a/lib/ace/mode/snippets.js +++ b/lib/ace/mode/snippets.js @@ -105,9 +105,7 @@ var Mode = function() { oop.inherits(Mode, TextMode); (function() { - this.getNextLineIndent = function(state, line, tab) { - return this.$getIndent(line); - }; + this.$indentWithTabs = true; }).call(Mode.prototype); exports.Mode = Mode; From 35a9dc5ba11365e849dc7c76c9099bab4a67ea34 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 9 Jun 2013 00:24:20 +0400 Subject: [PATCH 25/31] hide the popup when editor is scrolled --- lib/ace/autocomplete.js | 67 ++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index d2e8b4c7..1e65fc6b 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -43,6 +43,7 @@ var Autocomplete = function() { this.blurListener = this.blurListener.bind(this); this.changeListener = this.changeListener.bind(this); this.mousedownListener = this.mousedownListener.bind(this); + this.mousewheelListener = this.mousewheelListener.bind(this); }; (function() { @@ -82,12 +83,12 @@ var Autocomplete = function() { if (this.popup) this.popup.hide(); - this.editor.completer.activated = false; + this.activated = false; }; this.changeListener = function(e) { - if (this.editor.completer.activated) - this.complete(this.editor); + if (this.activated) + this.showPopup(this.editor); else this.detach(); }; @@ -98,13 +99,11 @@ var Autocomplete = function() { }; this.mousedownListener = function(e) { - var mouseX = e.clientX, mouseY = e.clientY; - var newRow = this.editor.renderer.pixelToScreenCoordinates(mouseX, mouseY).row; - var currentRow = e.editor.getCursorPosition().row; + this.detach(); + }; - if (newRow !== currentRow) { - this.detach(); - } + this.mousewheelListener = function(e) { + this.detach(); }; this.goTo = function(where) { @@ -126,15 +125,16 @@ var Autocomplete = function() { if (!data) data = this.popup.getData(this.popup.getRow()); if (!data) - return false; - if (data.completer && data.completer.insertMatch) { - data.completer.insertMatch(this.editor); - } else { - if (data.value) - data = data.value; - this.editor.removeWordLeft(); - this.editor.insert(data); - } + return false; + if (data.completer && data.completer.insertMatch) { + data.completer.insertMatch(this.editor); + } else { + if (data.value) + data = data.value; + if (data.prefix) + this.editor.removeWordLeft(); + this.editor.insert(data); + } }; this.commands = { @@ -153,13 +153,13 @@ var Autocomplete = function() { "PageDown": function(editor) { editor.completer.popup.gotoPageUp(); } }; - this.getCompletions = function(editor, callback) { + this.gatherCompletions = function(editor, callback) { var session = editor.getSession(); var pos = editor.getCursorPosition(); var line = session.getLine(pos.row); var prefix = util.retrievePrecedingIdentifier(line, pos.column); - + var matches = []; util.parForEach(editor.completers, function(completer, next) { completer.getCompletions(session, pos, prefix, function(err, results) { @@ -178,8 +178,8 @@ var Autocomplete = function() { }); return true; }; - - this.complete = function(editor) { + + this.showPopup = function(editor) { if (this.editor) this.detach(); @@ -195,20 +195,20 @@ var Autocomplete = function() { editor.on("blur", this.blurListener); editor.on("mousedown", this.mousedownListener); - this.getCompletions(this.editor, function(err, results) { - var matches = results && results.matches; - if (!matches || !matches.length) - return this.detach(); - if (matches.length == 1) - return this.insertMatch(matches[0]); + this.gatherCompletions(this.editor, function(err, results) { + var matches = results && results.matches; + if (!matches || !matches.length) + return this.detach(); + if (matches.length == 1) + return this.insertMatch(matches[0]); - this.completions = new FilteredList(matches); + this.completions = new FilteredList(matches); this.completions.setFilter(results.prefix); this.openPopup(editor); this.popup.setHighlight(results.prefix); - }.bind(this)); + }.bind(this)); }; - + this.cancelContextMenu = function() { var stop = function(e) { this.editor.off("nativecontextmenu", stop); @@ -218,8 +218,6 @@ var Autocomplete = function() { setTimeout(stop, 10); this.editor.on("nativecontextmenu", stop); }; - - this.completers = []; }).call(Autocomplete.prototype); @@ -228,8 +226,7 @@ Autocomplete.startCommand = { exec: function(editor) { if (!editor.completer) editor.completer = new Autocomplete(); - editor.completer.complete(editor); - editor.completer.activated = true; + editor.completer.showPopup(editor); // needed for firefox on mac editor.completer.cancelContextMenu(); }, From ac9bb727ccb7a9679a5235fe15958463021da345 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 9 Jun 2013 00:50:06 +0400 Subject: [PATCH 26/31] revert to simpler range tracking model for now --- lib/ace/autocomplete.js | 49 ++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 1e65fc6b..fef14ff4 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -35,6 +35,7 @@ var HashHandler = require("./keyboard/hash_handler").HashHandler; var AcePopup = require("./autocomplete/popup").AcePopup; var util = require("./autocomplete/util"); var event = require("./lib/event"); +var lang = require("./lib/lang"); var Autocomplete = function() { this.keyboardHandler = new HashHandler(); @@ -44,6 +45,10 @@ var Autocomplete = function() { this.changeListener = this.changeListener.bind(this); this.mousedownListener = this.mousedownListener.bind(this); this.mousewheelListener = this.mousewheelListener.bind(this); + + this.changeTimer = lang.delayedCall(function() { + this.updateCompletions(true); + }.bind(this)) }; (function() { @@ -55,22 +60,23 @@ var Autocomplete = function() { }.bind(this)); }; - this.openPopup = function(editor) { + this.openPopup = function(editor, keepPopupPosition) { if (!this.popup) this.$init(); this.popup.setData(this.completions.filtered); var renderer = editor.renderer; - var lineHeight = renderer.layerConfig.lineHeight; - var pos = renderer.$cursorLayer.getPixelPosition(null, true); - var rect = editor.container.getBoundingClientRect(); - pos.top += rect.top - renderer.layerConfig.offset; - pos.left += rect.left; - pos.left += renderer.$gutterLayer.gutterWidth; - - this.popup.show(pos, lineHeight); + if (!keepPopupPosition) { + var lineHeight = renderer.layerConfig.lineHeight; + var pos = renderer.$cursorLayer.getPixelPosition(null, true); + var rect = editor.container.getBoundingClientRect(); + pos.top += rect.top - renderer.layerConfig.offset; + pos.left += rect.left; + pos.left += renderer.$gutterLayer.gutterWidth; + this.popup.show(pos, lineHeight); + } renderer.updateText(); }; @@ -79,7 +85,8 @@ var Autocomplete = function() { this.editor.removeEventListener("changeSelection", this.changeListener); this.editor.removeEventListener("blur", this.changeListener); this.editor.removeEventListener("mousedown", this.changeListener); - + this.changeTimer.cancel(); + if (this.popup) this.popup.hide(); @@ -88,7 +95,7 @@ var Autocomplete = function() { this.changeListener = function(e) { if (this.activated) - this.showPopup(this.editor); + this.changeTimer.schedule(); else this.detach(); }; @@ -131,8 +138,8 @@ var Autocomplete = function() { } else { if (data.value) data = data.value; - if (data.prefix) - this.editor.removeWordLeft(); + if (this.completions.filterText) + this.editor.removeWordLeft(); this.editor.insert(data); } }; @@ -182,6 +189,8 @@ var Autocomplete = function() { this.showPopup = function(editor) { if (this.editor) this.detach(); + + this.activated = true; this.editor = editor; if (editor.completer != this) { @@ -194,17 +203,21 @@ var Autocomplete = function() { editor.on("changeSelection", this.changeListener); editor.on("blur", this.blurListener); editor.on("mousedown", this.mousedownListener); - + this.updateCompletions(); + } + + this.updateCompletions = function(keepPopupPosition) { this.gatherCompletions(this.editor, function(err, results) { var matches = results && results.matches; if (!matches || !matches.length) return this.detach(); - if (matches.length == 1) - return this.insertMatch(matches[0]); + // TODO reenable this when we have proper change tracking + // if (matches.length == 1) + // return this.insertMatch(matches[0]); this.completions = new FilteredList(matches); this.completions.setFilter(results.prefix); - this.openPopup(editor); + this.openPopup(this.editor, keepPopupPosition); this.popup.setHighlight(results.prefix); }.bind(this)); }; @@ -243,7 +256,7 @@ var FilteredList = function(array, mutateData) { }; (function(){ this.setFilter = function(str) { - + this.filterText = str; }; }).call(FilteredList.prototype); From b36c4c67b2a1e38773e3cfb8b92954a6e9fae7cd Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 9 Jun 2013 00:55:57 +0400 Subject: [PATCH 27/31] include split in build --- lib/ace/ext/split.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lib/ace/ext/split.js diff --git a/lib/ace/ext/split.js b/lib/ace/ext/split.js new file mode 100644 index 00000000..8316562f --- /dev/null +++ b/lib/ace/ext/split.js @@ -0,0 +1,40 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +/** + * this is experimental, and subject to change, use at your own risk! + */ +module.exports = require("../split"); + +}); + From 917e4b925c87ccdb93935fcf9882cff62cc36300 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 9 Jun 2013 01:06:25 +0400 Subject: [PATCH 28/31] fix typo in clojure mode --- lib/ace/mode/clojure.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/mode/clojure.js b/lib/ace/mode/clojure.js index cbbaace5..df67dc06 100644 --- a/lib/ace/mode/clojure.js +++ b/lib/ace/mode/clojure.js @@ -41,7 +41,7 @@ var Range = require("../range").Range; var Mode = function() { var highlighter = new ClojureHighlightRules(); this.$tokenizer = new Tokenizer(highlighter.getRules()); - this.$keywordList = new Rules(rules.$keywordList); + this.$keywordList = highlighter.$keywordList; this.$outdent = new MatchingParensOutdent(); }; oop.inherits(Mode, TextMode); From af2a2e272b6e9ed9c5a9676efa3201d284730910 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 9 Jun 2013 01:09:48 +0400 Subject: [PATCH 29/31] revert change to config.js --- lib/ace/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ace/config.js b/lib/ace/config.js index 605abe1e..db36d59f 100644 --- a/lib/ace/config.js +++ b/lib/ace/config.js @@ -208,7 +208,7 @@ var optionsProvider = { return; var opt = this.$options[name]; if (!opt) - return false; + return undefined; if (opt.forwardTo) return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value); @@ -220,7 +220,7 @@ var optionsProvider = { getOption: function(name) { var opt = this.$options[name]; if (!opt) - return false; + return undefined; if (opt.forwardTo) return this[opt.forwardTo] && this[opt.forwardTo].getOption(name); return opt && opt.get ? opt.get.call(this) : this["$" + name]; From 156d9a7eebd3ec8135fc39cb33d97725da509966 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 9 Jun 2013 17:49:11 +0400 Subject: [PATCH 30/31] load snippet files automatically --- demo/kitchen-sink/demo.js | 48 ++++++++++++-------------- lib/ace/autocomplete/text_completer.js | 2 +- lib/ace/ext/language_tools.js | 41 ++++++++++++++++++++-- 3 files changed, 61 insertions(+), 30 deletions(-) diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index 41ed5b19..253c0dda 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -517,17 +517,9 @@ net.loadScript("https://rawgithub.com/nightwing/emmet-core/master/emmet.js", fun }) -require("ace/placeholder").PlaceHolder; +// require("ace/placeholder").PlaceHolder; -var snippetManager = require("ace/snippets").snippetManager -var jsSnippets = require("ace/snippets/javascript"); -window.snippetManager = snippetManager -saveSnippets() - -function saveSnippets() { - jsSnippets.snippets = snippetManager.parseSnippetFile(jsSnippets.snippetText); - snippetManager.register(jsSnippets.snippets, "javascript") -} +var snippetManager = require("ace/snippets").snippetManager; env.editSnippets = function() { var sp = env.split; @@ -538,28 +530,32 @@ env.editSnippets = function() { sp.setSplits(1); sp.setSplits(2); sp.setOrientation(sp.BESIDE); - var editor = sp.$editors[1] - if (!env.snippetSession) { - var file = jsSnippets.snippetText; - env.snippetSession = doclist.initDoc(file, "", {}); - env.snippetSession.setMode("ace/mode/tmsnippet"); - env.snippetSession.setUseSoftTabs(false); + var editor = sp.$editors[1]; + var id = sp.$editors[0].session.$mode.$id || ""; + var m = snippetManager.files[id]; + if (!doclist["snippets/" + id]) { + var text = m.snippetText; + var s = doclist.initDoc(text, "", {}); + s.setMode("ace/mode/snippets"); + doclist["snippets/" + id] = s } editor.on("blur", function() { - jsSnippets.snippetText = editor.getValue(); - saveSnippets(); + m.snippetText = editor.getValue(); + snippetManager.unregister(m.snippets); + m.snippets = snippetManager.parseSnippetFile(m.snippetText); + snippetManager.register(m.snippets); }) - editor.setSession(env.snippetSession, 1); + sp.$editors[0].once("changeMode", function() { + sp.setSplits(1); + }) + editor.setSession(doclist["snippets/" + id], 1); editor.focus(); } -ace.commands.bindKey("Tab", function(editor) { - var success = snippetManager.expandWithTab(editor); - if (!success) - editor.execCommand("indent"); +require("ace/ext/language_tools"); +env.editor.setOptions({ + enableBasicAutocompletion: true, + enableSnippets: true }) -require("ace/ext/language_tools"); - - }); diff --git a/lib/ace/autocomplete/text_completer.js b/lib/ace/autocomplete/text_completer.js index 30b9352f..2808ff6f 100644 --- a/lib/ace/autocomplete/text_completer.js +++ b/lib/ace/autocomplete/text_completer.js @@ -42,7 +42,7 @@ define(function(require, exports, module) { function filterPrefix(prefix, words) { var results = []; for (var i = 0; i < words.length; i++) { - if (words[i].indexOf(prefix) === 0) { + if (words[i].lastIndexOf(prefix, 0) === 0) { results.push(words[i]); } } diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index 05e00129..1d54d3b9 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -33,10 +33,27 @@ define(function(require, exports, module) { var snippetManager = require("../snippets").snippetManager; var Autocomplete = require("../autocomplete").Autocomplete; +var config = require("../config"); var textCompleter = require("../autocomplete/text_completer"); +var keyWordCompleter = { + getCompletions: function(session, pos, prefix, callback) { + var keywords = session.$mode.$keywordList || []; + keywords.filter(function(w) { + return w.lastIndexOf(prefix, 0); + }); + callback(null, keywords.map(function(word) { + return { + name: word, + value: word, + score: 0, + meta: "keyword" + }; + })); + } +}; -var completers = [textCompleter]; +var completers = [textCompleter, keyWordCompleter]; // todo add snippets completer exports.addCompleter = function(completer) { completers.push(completer); }; @@ -51,6 +68,21 @@ var expandSnippet = { bindKey: "tab" } +var onChangeMode = function(e, editor) { + var mode = editor.session.$mode; + var id = mode.$id + if (!snippetManager.files) snippetManager.files = {}; + if (id && !snippetManager.files[id]) { + var snippetFilePath = id.replace("mode", "snippets"); + config.loadModule(snippetFilePath, function(m) { + if (m) { + snippetManager.files[id] = m; + m.snippets = snippetManager.parseSnippetFile(m.snippetText); + snippetManager.register(m.snippets, m.scope); + } + }); + } +}; var Editor = require("../editor").Editor; require("../config").defineOptions(Editor.prototype, "editor", { @@ -63,17 +95,20 @@ require("../config").defineOptions(Editor.prototype, "editor", { this.commands.removeCommand(Autocomplete.startCommand); } }, - value: true + value: false }, enableSnippets: { set: function(val) { if (val) { this.commands.addCommand(expandSnippet); + this.on("changeMode", onChangeMode); + onChangeMode(null, this) } else { this.commands.removeCommand(expandSnippet); + this.off("changeMode", onChangeMode); } }, - value: true + value: false } }); From db1118c258e079b97fe376f54d05a4c6a7ef9c3f Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 9 Jun 2013 18:57:49 +0400 Subject: [PATCH 31/31] fix typo --- lib/ace/ext/language_tools.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index 1d54d3b9..7133d740 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -39,8 +39,8 @@ var textCompleter = require("../autocomplete/text_completer"); var keyWordCompleter = { getCompletions: function(session, pos, prefix, callback) { var keywords = session.$mode.$keywordList || []; - keywords.filter(function(w) { - return w.lastIndexOf(prefix, 0); + keywords = keywords.filter(function(w) { + return w.lastIndexOf(prefix, 0) == 0; }); callback(null, keywords.map(function(word) { return {