From 91df7cd6635110dca0a97e7419150739f8d9ffd6 Mon Sep 17 00:00:00 2001 From: aldendaniels Date: Wed, 8 Jan 2014 21:39:30 -0600 Subject: [PATCH] Revert "Stop using splice.appy() in ace" This reverts commit 8624ab8dcb9bac917488feb8856e8b709418adb7. --- lib/ace/background_tokenizer.js | 14 ++++++-------- lib/ace/edit_session.js | 14 +++++++------- lib/ace/edit_session/folding.js | 6 +++--- lib/ace/layer/gutter.js | 5 +++-- lib/ace/lib/lang.js | 14 -------------- lib/ace/line_widgets.js | 5 +++-- lib/ace/mode/asciidoc_highlight_rules.js | 8 +++----- lib/ace/mode/text_highlight_rules.js | 6 +++--- lib/ace/snippets.js | 18 +++++++++--------- 9 files changed, 37 insertions(+), 53 deletions(-) diff --git a/lib/ace/background_tokenizer.js b/lib/ace/background_tokenizer.js index 4b82f19a..cb3ffe23 100644 --- a/lib/ace/background_tokenizer.js +++ b/lib/ace/background_tokenizer.js @@ -32,7 +32,6 @@ define(function(require, exports, module) { "use strict"; var oop = require("./lib/oop"); -var lang = require("./lib/lang"); var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -188,15 +187,14 @@ var BackgroundTokenizer = function(tokenizer, editor) { this.lines.splice(startRow, len + 1, null); this.states.splice(startRow, len + 1, null); } else { - this.lines.splice( startRow, 1); - this.states.splice(startRow, 1); - var toInsert = Array(len + 1); - lang.spliceIntoArray(this.lines, startRow, toInsert); - lang.spliceIntoArray(this.states, startRow, toInsert); + var args = Array(len + 1); + args.unshift(startRow, 1); + this.lines.splice.apply(this.lines, args); + this.states.splice.apply(this.states, args); } - + this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength()); - + this.stop(); }; diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index cd14c1a5..0d4df080 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -1723,15 +1723,15 @@ var EditSession = function(text, mode) { } else { var args; if (useWrapMode) { - var toInsert = []; - for (var i = 0; i < len; i++) - toInsert.push([]); - lang.spliceIntoArray(this.$wrapData, firstRow, toInsert); + args = [firstRow, 0]; + for (var i = 0; i < len; i++) args.push([]); + this.$wrapData.splice.apply(this.$wrapData, args); } else { - var toInsert = Array(len); - lang.spliceIntoArray(this.$rowLengthCache, firstRow, toInsert); + args = Array(len); + args.unshift(firstRow, 0); + this.$rowLengthCache.splice.apply(this.$rowLengthCache, args); } - + // If some new line is added inside of a foldLine, then split // the fold line up. var foldLines = this.$foldData; diff --git a/lib/ace/edit_session/folding.js b/lib/ace/edit_session/folding.js index 1563bd67..9df35593 100644 --- a/lib/ace/edit_session/folding.js +++ b/lib/ace/edit_session/folding.js @@ -31,7 +31,6 @@ define(function(require, exports, module) { "use strict"; -var lang = require("../lib/lang"); var Range = require("../range").Range; var FoldLine = require("./fold_line").FoldLine; var Fold = require("./fold").Fold; @@ -837,8 +836,9 @@ function Folding() { } else if (delta.action == "delete") { this.foldWidgets.splice(firstRow, len + 1, null); } else { - this.foldWidgets.splice(firstRow, 1); - lang.spliceIntoArray(this.foldWidgets, firstRow, Array(len + 1)); + var args = Array(len + 1); + args.unshift(firstRow, 1); + this.foldWidgets.splice.apply(this.foldWidgets, args); } }; diff --git a/lib/ace/layer/gutter.js b/lib/ace/layer/gutter.js index 24f9c430..82dcf245 100644 --- a/lib/ace/layer/gutter.js +++ b/lib/ace/layer/gutter.js @@ -111,8 +111,9 @@ var Gutter = function(parentEl) { } else if (delta.action == "delete") { this.$annotations.splice(firstRow, len + 1, null); } else { - this.$annotations.splice(firstRow, 1); - lang.spliceIntoArray(this.$annotations, firstRow, new Array(len + 1)); + var args = new Array(len + 1); + args.unshift(firstRow, 1); + this.$annotations.splice.apply(this.$annotations, args); } }; diff --git a/lib/ace/lib/lang.js b/lib/ace/lib/lang.js index e0e9d826..4405b5c2 100644 --- a/lib/ace/lib/lang.js +++ b/lib/ace/lib/lang.js @@ -123,20 +123,6 @@ exports.arrayRemove = function(array, value) { } }; -/* - * Splice the items in `a2` into `a1` at position `offset`. - */ -exports.spliceIntoArray = function(a1, offset, a2) { - - // Handle negative offsets. - if (offset < 0) - offset = Math.max(a1.length + offset, 0); - - // Splice. - for (var i = 0; i < a2.length; i++) - a1.splice(i + offset, 0, a2[i]); -} - exports.escapeRegExp = function(str) { return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); }; diff --git a/lib/ace/line_widgets.js b/lib/ace/line_widgets.js index 7cbe9809..4023bd55 100644 --- a/lib/ace/line_widgets.js +++ b/lib/ace/line_widgets.js @@ -32,7 +32,6 @@ define(function(require, exports, module) { "use strict"; var oop = require("./lib/oop"); -var lang = require("./lib/lang"); var dom = require("./lib/dom"); var Range = require("./range").Range; @@ -131,7 +130,9 @@ function LineWidgets(session) { }, this); this.$updateRows(); } else { - lang.spliceIntoArray(cells, startRow, new Array(len)); + var args = Array(len); + args.unshift(startRow, 0); + cells.splice.apply(cells, args); this.$updateRows(); } }; diff --git a/lib/ace/mode/asciidoc_highlight_rules.js b/lib/ace/mode/asciidoc_highlight_rules.js index 308fc8e4..c0d1a305 100644 --- a/lib/ace/mode/asciidoc_highlight_rules.js +++ b/lib/ace/mode/asciidoc_highlight_rules.js @@ -32,7 +32,6 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var AsciidocHighlightRules = function() { @@ -216,14 +215,13 @@ var AsciidocHighlightRules = function() { for (var i = stateRules.length; i--; ) { var rule = stateRules[i]; if (rule.include || typeof rule == "string") { - var toInsert = this.$rules[rule.include || rule]; + var args = [i, 1].concat(this.$rules[rule.include || rule]); if (rule.noEscape) { - toInsert = toInsert.filter(function(x) { + args = args.filter(function(x) { return !x.next; }); } - stateRules.splice(i, 1); - lang.spliceIntoArray(stateRules, i, toInsert); + stateRules.splice.apply(stateRules, args); } else if (rule.token in tokenMap) { rule.token = tokenMap[rule.token]; } diff --git a/lib/ace/mode/text_highlight_rules.js b/lib/ace/mode/text_highlight_rules.js index 9e304a53..48e016b0 100644 --- a/lib/ace/mode/text_highlight_rules.js +++ b/lib/ace/mode/text_highlight_rules.js @@ -181,10 +181,10 @@ var TextHighlightRules = function() { toInsert = rule; if (toInsert) { + var args = [i, 1].concat(toInsert); if (rule.noEscape) - toInsert = toInsert.filter(function(x) {return !x.next;}); - state.splice(i, 1); - lang.spliceIntoArray(state, i, toInsert); + args = args.filter(function(x) {return !x.next;}); + state.splice.apply(state, args); // skip included rules since they are already processed //i += args.length - 3; i--; diff --git a/lib/ace/snippets.js b/lib/ace/snippets.js index e5d585bb..ee1a5498 100644 --- a/lib/ace/snippets.js +++ b/lib/ace/snippets.js @@ -335,12 +335,12 @@ var SnippetManager = function() { } var ts = tabstops[id]; - var toInsert = typeof ts.value == "string" ? [ts.value] : copyValue(ts.value); - toInsert.push(p); + var arg = typeof ts.value == "string" ? [ts.value] : copyValue(ts.value); + arg.unshift(i + 1, Math.max(0, i1 - i)); + arg.push(p); expanding[id] = p; - tokens.splice(i + 1, Math.max(0, i1 - i)); - lang.spliceIntoArray(tokens, i + 1, toInsert); - + tokens.splice.apply(tokens, arg); + if (ts.indexOf(p) === -1) ts.push(p); }; @@ -755,7 +755,7 @@ var TabstopManager = function(editor) { } var i = this.index; - var toInsert = []; + var arg = [i, 0]; var ranges = this.ranges; var editor = this.editor; tabstops.forEach(function(ts) { @@ -776,12 +776,12 @@ var TabstopManager = function(editor) { } if (!ts.firstNonLinked) ts.hasLinkedRanges = false; - toInsert.push(ts); + arg.push(ts); this.addTabstopMarkers(ts); }, this); // tabstop 0 is the last one - toInsert.push(toInsert.splice(0, 1)[0]); - lang.spliceIntoArray(this.tabstops, this.index, toInsert); + arg.push(arg.splice(2, 1)[0]); + this.tabstops.splice.apply(this.tabstops, arg); }; this.addTabstopMarkers = function(ts) {