From 1bd38560b4c3d75d692bdd4c3db71dc11ce17a7f Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 1 Aug 2014 21:31:40 +0400 Subject: [PATCH 1/3] code style --- lib/ace/autocomplete/popup.js | 9 ++++--- lib/ace/edit_session/fold_line.js | 41 +++++++++++++++---------------- lib/ace/editor.js | 16 ++++++------ lib/ace/selection.js | 36 +++++++++++++-------------- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/ace/autocomplete/popup.js b/lib/ace/autocomplete/popup.js index a34ebf09..f580e391 100644 --- a/lib/ace/autocomplete/popup.js +++ b/lib/ace/autocomplete/popup.js @@ -52,6 +52,7 @@ var $singleLineEditor = function(el) { editor.renderer.setHighlightGutterLine(false); editor.$mouseHandler.$focusWaitTimout = 0; + editor.$highlightTagPending = true; return editor; }; @@ -103,7 +104,7 @@ var AcePopup = function(parentNode) { popup.session.removeMarker(hoverMarker.id); hoverMarker.id = null; } - } + }; popup.setSelectOnHover(false); popup.on("mousemove", function(e) { if (!lastMouseEvent) { @@ -171,8 +172,8 @@ var AcePopup = function(parentNode) { }; var bgTokenizer = popup.session.bgTokenizer; - bgTokenizer.$tokenizeRow = function(i) { - var data = popup.data[i]; + bgTokenizer.$tokenizeRow = function(row) { + var data = popup.data[row]; var tokens = []; if (!data) return tokens; @@ -206,7 +207,7 @@ var AcePopup = function(parentNode) { popup.session.$computeWidth = function() { return this.screenWidth = 0; - } + }; // public popup.isOpen = false; diff --git a/lib/ace/edit_session/fold_line.js b/lib/ace/edit_session/fold_line.js index 0218195e..d976de98 100644 --- a/lib/ace/edit_session/fold_line.js +++ b/lib/ace/edit_session/fold_line.js @@ -44,7 +44,7 @@ function FoldLine(foldData, folds) { folds = this.folds = [ folds ]; } - var last = folds[folds.length - 1] + var last = folds[folds.length - 1]; this.range = new Range(folds[0].start.row, folds[0].start.column, last.end.row, last.end.column); this.start = this.range.start; @@ -66,7 +66,7 @@ function FoldLine(foldData, folds) { fold.start.row += shift; fold.end.row += shift; }); - } + }; this.addFold = function(fold) { if (fold.sameRow) { @@ -96,17 +96,17 @@ function FoldLine(foldData, folds) { throw new Error("Trying to add fold to FoldRow that doesn't have a matching row"); } fold.foldLine = this; - } + }; this.containsRow = function(row) { return row >= this.start.row && row <= this.end.row; - } + }; this.walk = function(callback, endRow, endColumn) { var lastEnd = 0, folds = this.folds, fold, - comp, stop, isNewRow = true; + cmp, stop, isNewRow = true; if (endRow == null) { endRow = this.end.row; @@ -116,9 +116,9 @@ function FoldLine(foldData, folds) { for (var i = 0; i < folds.length; i++) { fold = folds[i]; - comp = fold.range.compareStart(endRow, endColumn); + cmp = fold.range.compareStart(endRow, endColumn); // This fold is after the endRow/Column. - if (comp == -1) { + if (cmp == -1) { callback(null, endRow, endColumn, lastEnd, isNewRow); return; } @@ -127,8 +127,8 @@ function FoldLine(foldData, folds) { stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd); // If the user requested to stop the walk or endRow/endColumn is - // inside of this fold (comp == 0), then end here. - if (stop || comp == 0) { + // inside of this fold (cmp == 0), then end here. + if (stop || cmp === 0) { return; } @@ -138,7 +138,7 @@ function FoldLine(foldData, folds) { lastEnd = fold.end.column; } callback(null, endRow, endColumn, lastEnd, isNewRow); - } + }; this.getNextFoldTo = function(row, column) { var fold, cmp; @@ -150,15 +150,15 @@ function FoldLine(foldData, folds) { fold: fold, kind: "after" }; - } else if (cmp == 0) { + } else if (cmp === 0) { return { fold: fold, kind: "inside" - } + }; } } return null; - } + }; this.addRemoveChars = function(row, column, len) { var ret = this.getNextFoldTo(row, column), @@ -175,7 +175,7 @@ function FoldLine(foldData, folds) { } else if (fold.start.row == row) { folds = this.folds; var i = folds.indexOf(fold); - if (i == 0) { + if (i === 0) { this.start.column += len; } for (i; i < folds.length; i++) { @@ -189,7 +189,7 @@ function FoldLine(foldData, folds) { this.end.column += len; } } - } + }; this.split = function(row, column) { var fold = this.getNextFoldTo(row, column).fold; @@ -211,7 +211,7 @@ function FoldLine(foldData, folds) { var newFoldLine = new FoldLine(foldData, folds); foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine); return newFoldLine; - } + }; this.merge = function(foldLineNext) { var folds = foldLineNext.folds; @@ -222,7 +222,7 @@ function FoldLine(foldData, folds) { // it's merged now with foldLineNext. var foldData = this.foldData; foldData.splice(foldData.indexOf(foldLineNext), 1); - } + }; this.toString = function() { var ret = [this.range.toString() + ": [" ]; @@ -230,13 +230,12 @@ function FoldLine(foldData, folds) { this.folds.forEach(function(fold) { ret.push(" " + fold.toString()); }); - ret.push("]") + ret.push("]"); return ret.join("\n"); - } + }; this.idxToPosition = function(idx) { var lastFoldEndColumn = 0; - var fold; for (var i = 0; i < this.folds.length; i++) { var fold = this.folds[i]; @@ -261,7 +260,7 @@ function FoldLine(foldData, folds) { row: this.end.row, column: this.end.column + idx }; - } + }; }).call(FoldLine.prototype); exports.FoldLine = FoldLine; diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 83782f06..022653da 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -572,28 +572,28 @@ var Editor = function(renderer, session) { token = iterator.stepForward(); if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) { - if (prevToken.value==='<'){ + if (prevToken.value === '<'){ depth++; - } else if (prevToken.value==='=0); - }else{ + } while (token && depth >= 0); + } else { //find opening tag do { token = prevToken; prevToken = iterator.stepBackward(); - if(token && token.value === tag && token.type.indexOf('tag-name') !== -1) { - if (prevToken.value==='<') { + if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) { + if (prevToken.value === '<') { depth++; - } else if( prevToken.value===' 0) { this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length); @@ -639,7 +639,7 @@ var Selection = function(session) { var str = this.session.getFoldStringAt(row, column, -1); if (str == null) { - str = this.doc.getLine(row).substring(0, column) + str = this.doc.getLine(row).substring(0, column); } var leftOfCursor = lang.stringReverse(str); @@ -691,13 +691,13 @@ var Selection = function(session) { index ++; if (whitespaceRe.test(ch)) { if (index > 2) { - index-- + index--; break; } else { while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch)) index ++; if (index > 2) - break + break; } } } @@ -722,11 +722,11 @@ var Selection = function(session) { var l = this.doc.getLength(); do { row++; - rightOfCursor = this.doc.getLine(row) - } while (row < l && /^\s*$/.test(rightOfCursor)) + rightOfCursor = this.doc.getLine(row); + } while (row < l && /^\s*$/.test(rightOfCursor)); if (!/^\s+/.test(rightOfCursor)) - rightOfCursor = "" + rightOfCursor = ""; column = 0; } @@ -744,15 +744,15 @@ var Selection = function(session) { return this.moveCursorTo(fold.start.row, fold.start.column); var line = this.session.getLine(row).substring(0, column); - if (column == 0) { + if (column === 0) { do { row--; line = this.doc.getLine(row); - } while (row > 0 && /^\s*$/.test(line)) + } while (row > 0 && /^\s*$/.test(line)); column = line.length; if (!/\s+$/.test(line)) - line = "" + line = ""; } var leftOfCursor = lang.stringReverse(line); @@ -859,12 +859,12 @@ var Selection = function(session) { this.lead.detach(); this.anchor.detach(); this.session = this.doc = null; - } + }; this.fromOrientedRange = function(range) { this.setSelectionRange(range, range.cursor == range.start); this.$desiredColumn = range.desiredColumn || this.$desiredColumn; - } + }; this.toOrientedRange = function(range) { var r = this.getRange(); @@ -880,7 +880,7 @@ var Selection = function(session) { range.cursor = this.isBackwards() ? range.start : range.end; range.desiredColumn = this.$desiredColumn; return range; - } + }; /** * Saves the current cursor position and calls `func` that can change the cursor @@ -901,7 +901,7 @@ var Selection = function(session) { } finally { this.moveCursorToPosition(start); } - } + }; this.toJSON = function() { if (this.rangeCount) { @@ -944,10 +944,10 @@ var Selection = function(session) { for (var i = this.ranges.length; i--; ) { if (!this.ranges[i].isEqual(data[i])) - return false + return false; } return true; - } + }; }).call(Selection.prototype); From 10860343abc0da0a4c0fbfe8f64230921d9ec42f Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 1 Aug 2014 21:40:31 +0400 Subject: [PATCH 2/3] fix error when inserting text inside code --- lib/ace/edit_session/fold_line.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/ace/edit_session/fold_line.js b/lib/ace/edit_session/fold_line.js index d976de98..9d73154d 100644 --- a/lib/ace/edit_session/fold_line.js +++ b/lib/ace/edit_session/fold_line.js @@ -192,13 +192,15 @@ function FoldLine(foldData, folds) { }; this.split = function(row, column) { - var fold = this.getNextFoldTo(row, column).fold; + var pos = this.getNextFoldTo(row, column); + + if (!pos || pos.kind == "inside") + return null; + + var fold = pos.fold; var folds = this.folds; var foldData = this.foldData; - - if (!fold) - return null; - + var i = folds.indexOf(fold); var foldBefore = folds[i - 1]; this.end.row = foldBefore.end.row; From 9b489c752b43cef55b81739fa7506871ab002b99 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 22 Jul 2014 03:20:43 +0400 Subject: [PATCH 3/3] minor fixes --- lib/ace/edit_session.js | 10 ++- lib/ace/editor.js | 99 ++++++++++++++-------------- lib/ace/ext/whitespace.js | 9 ++- lib/ace/keyboard/vim/maps/motions.js | 10 +-- lib/ace/lib/dom.js | 2 +- lib/ace/multi_select.js | 6 +- lib/ace/placeholder.js | 13 ++-- lib/ace/snippets.js | 6 +- lib/ace/virtual_renderer.js | 2 + 9 files changed, 88 insertions(+), 69 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 9689ea5c..6c7f1c53 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -950,6 +950,9 @@ var EditSession = function(text, mode) { if (!$isPlaceholder) { + // experimental method, used by c9 findiniles + if (mode.attachToSession) + mode.attachToSession(this); this.$options.wrapMethod.set.call(this, this.$wrapMethod); this.$setFolding(mode.foldingRules); this.bgTokenizer.start(0); @@ -1731,9 +1734,10 @@ var EditSession = function(text, mode) { // Inside of the foldLine range. Need to split stuff up. if (cmp == 0) { foldLine = foldLine.split(start.row, start.column); - foldLine.shiftRow(len); - foldLine.addRemoveChars( - lastRow, 0, end.column - start.column); + if (foldLine) { + foldLine.shiftRow(len); + foldLine.addRemoveChars(lastRow, 0, end.column - start.column); + } } else // Infront of the foldLine but same row. Need to shift column. if (cmp == -1) { diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 022653da..df0133ad 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -525,25 +525,23 @@ var Editor = function(renderer, session) { this.$highlightPending = true; setTimeout(function() { self.$highlightPending = false; - - var pos = self.session.findMatchingBracket(self.getCursorPosition()); + var session = self.session; + if (!session || !session.bgTokenizer) return; + var pos = session.findMatchingBracket(self.getCursorPosition()); if (pos) { - var range = new Range(pos.row, pos.column, pos.row, pos.column+1); - } else if (self.session.$mode.getMatching) { - var range = self.session.$mode.getMatching(self.session); + var range = new Range(pos.row, pos.column, pos.row, pos.column + 1); + } else if (session.$mode.getMatching) { + var range = session.$mode.getMatching(self.session); } if (range) - self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text"); + session.$bracketHighlight = session.addMarker(range, "ace_bracket", "text"); }, 50); }; // todo: move to mode.getMatching this.$highlightTags = function() { - var session = this.session; - - if (this.$highlightTagPending) { + if (this.$highlightTagPending) return; - } // perform highlight async to not block the browser during navigation var self = this; @@ -551,6 +549,9 @@ var Editor = function(renderer, session) { setTimeout(function() { self.$highlightTagPending = false; + var session = self.session; + if (!session || !session.bgTokenizer) return; + var pos = self.getCursorPosition(); var iterator = new TokenIterator(self.session, pos.row, pos.column); var token = iterator.getCurrentToken(); @@ -2005,17 +2006,13 @@ var Editor = function(renderer, session) { * Moves the cursor's row and column to the next matching bracket or HTML tag. * **/ - this.jumpToMatching = function(select) { + this.jumpToMatching = function(select, expand) { var cursor = this.getCursorPosition(); var iterator = new TokenIterator(this.session, cursor.row, cursor.column); var prevToken = iterator.getCurrentToken(); - var token = prevToken; + var token = prevToken || iterator.stepForward(); - if (!token) - token = iterator.stepForward(); - - if (!token) - return; + if (!token) return; //get next closing tag or bracket var matchType; @@ -2034,12 +2031,12 @@ var Editor = function(renderer, session) { do { if (token.value.match(/[{}()\[\]]/g)) { - for (; i 1)) - var column = util.getRightNthChar(editor, cursor, param, 2); + column = util.getRightNthChar(editor, cursor, param, 2); if (typeof column === "number") { cursor.column += column + (isSel ? 1 : 0); @@ -444,8 +444,8 @@ module.exports = { var cursor = editor.getCursorPosition(); var column = util.getLeftNthChar(editor, cursor, param, count || 1); - if (isRepeat && column == 0 && !(count > 1)) - var column = util.getLeftNthChar(editor, cursor, param, 2); + if (isRepeat && column === 0 && !(count > 1)) + column = util.getLeftNthChar(editor, cursor, param, 2); if (typeof column === "number") { cursor.column -= column; @@ -558,7 +558,7 @@ module.exports = { content += "\n"; if (content.length) { - editor.navigateLineEnd() + editor.navigateLineEnd(); editor.insert(content); util.insertMode(editor); } @@ -575,7 +575,7 @@ module.exports = { if (content.length) { if(row > 0) { editor.navigateUp(); - editor.navigateLineEnd() + editor.navigateLineEnd(); editor.insert(content); } else { editor.session.insert({row: 0, column: 0}, content); diff --git a/lib/ace/lib/dom.js b/lib/ace/lib/dom.js index b3724009..65f20d7d 100644 --- a/lib/ace/lib/dom.js +++ b/lib/ace/lib/dom.js @@ -49,7 +49,7 @@ exports.createElement = function(tag, ns) { }; exports.hasCssClass = function(el, name) { - var classes = el.className.split(/\s+/g); + var classes = (el.className || "").split(/\s+/g); return classes.indexOf(name) !== -1; }; diff --git a/lib/ace/multi_select.js b/lib/ace/multi_select.js index ef0f7a2e..dd158010 100644 --- a/lib/ace/multi_select.js +++ b/lib/ace/multi_select.js @@ -720,7 +720,7 @@ var Editor = require("./editor").Editor; * @param {Boolean} skip If `true`, removes the active selection range * @method Editor.selectMore **/ - this.selectMore = function(dir, skip) { + this.selectMore = function(dir, skip, stopAtFirst) { var session = this.session; var sel = session.multiSelect; @@ -729,8 +729,8 @@ var Editor = require("./editor").Editor; range = session.getWordRange(range.start.row, range.start.column); range.cursor = dir == -1 ? range.start : range.end; this.multiSelect.addRange(range); - // todo add option for sublime like behavior - // return; + if (stopAtFirst) + return; } var needle = session.getTextRange(range); diff --git a/lib/ace/placeholder.js b/lib/ace/placeholder.js index bcb44ce2..582e2c2b 100644 --- a/lib/ace/placeholder.js +++ b/lib/ace/placeholder.js @@ -37,7 +37,6 @@ var oop = require("./lib/oop"); /** * @class PlaceHolder * - * **/ /** @@ -47,7 +46,6 @@ var oop = require("./lib/oop"); * - others (String): * - mainClass (String): * - othersClass (String): - * * * @constructor **/ @@ -93,6 +91,10 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) var doc = this.doc; var session = this.session; var pos = this.$pos; + + this.selectionBefore = session.selection.toJSON(); + if (session.selection.inMultiSelectMode) + session.selection.toSingleRange(); this.pos = doc.createAnchor(pos.row, pos.column); this.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false); @@ -218,9 +220,9 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) **/ this.onCursorChange = function(event) { - if (this.$updating) return; + if (this.$updating || !this.session) return; var pos = this.session.selection.getCursor(); - if(pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) { + if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) { this.showOtherMarkers(); this._emit("cursorEnter", event); } else { @@ -245,6 +247,7 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) this.others[i].detach(); } this.session.setUndoSelect(true); + this.session = null; }; /** @@ -261,6 +264,8 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) for (var i = 0; i < undosRequired; i++) { undoManager.undo(true); } + if (this.selectionBefore) + this.session.selection.fromJSON(this.selectionBefore); }; }).call(PlaceHolder.prototype); diff --git a/lib/ace/snippets.js b/lib/ace/snippets.js index 4fd301c2..10c34bf0 100644 --- a/lib/ace/snippets.js +++ b/lib/ace/snippets.js @@ -497,6 +497,10 @@ var SnippetManager = function() { var snippetMap = this.snippetMap; var snippetNameMap = this.snippetNameMap; var self = this; + + if (!snippets) + snippets = []; + function wrapRegexp(src) { if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src)) src = "(?:" + src + ")"; @@ -549,7 +553,7 @@ var SnippetManager = function() { s.endTriggerRe = new RegExp(s.endTrigger, "", true); } - if (snippets.content) + if (snippets && snippets.content) addSnippet(snippets); else if (Array.isArray(snippets)) snippets.forEach(addSnippet); diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index d3e26758..af49b52e 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -915,6 +915,8 @@ var VirtualRenderer = function(container, theme) { this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight); // this.$loop.changes = 0; this.desiredHeight = desiredHeight; + + this._signal("autosize"); } };