From 817ff7ce5eff811a97f791f91ddb03d11201cfbe Mon Sep 17 00:00:00 2001 From: Joe Walker Date: Thu, 7 Apr 2011 16:27:09 +0100 Subject: [PATCH] fix setInnerHtml to work without side effects, and introduce rebuildWith to have perf gains, also fix some warnings in the code in related files --- lib/ace/keyboard/state_handler.js | 2 +- lib/ace/keyboard/textinput.js | 10 +++++----- lib/ace/layer/gutter.js | 9 +++++---- lib/ace/layer/marker.js | 8 ++++---- lib/ace/layer/text.js | 10 +++++----- lib/ace/mode/textile_highlight_rules.js | 6 +++--- support/cockpit | 2 +- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/ace/keyboard/state_handler.js b/lib/ace/keyboard/state_handler.js index 5861ad23..a05b9424 100644 --- a/lib/ace/keyboard/state_handler.js +++ b/lib/ace/keyboard/state_handler.js @@ -213,7 +213,7 @@ StateHandler.prototype = { return r; } -} +}; /** * This is a useful matching function and therefore is defined here so that diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index 2ecb1b6e..5a7de4cd 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -164,7 +164,7 @@ var TextInput = function(parentNode, host) { }; if (useragent.isIE) { - event.addListener(text, "beforecopy", function(e) { + event.addListener(text, "beforecopy", function(e) { var copyText = host.getCopyText(); if(copyText) clipboardData.setData("Text", copyText); @@ -178,7 +178,7 @@ var TextInput = function(parentNode, host) { clipboardData.setData("Text", copyText); host.onCut(); } - event.preventDefault(e) + event.preventDefault(e); } }); } @@ -224,12 +224,12 @@ var TextInput = function(parentNode, host) { if(!tempStyle) tempStyle = text.style.cssText; text.style.cssText = 'position:fixed; z-index:1000;' + - 'left:' + (mousePos.x - 2) + 'px; top:' + (mousePos.y - 2) + 'px;' + 'left:' + (mousePos.x - 2) + 'px; top:' + (mousePos.y - 2) + 'px;'; } if (isEmpty) text.value=''; - } + }; this.onContextMenuClose = function(){ setTimeout(function () { @@ -239,7 +239,7 @@ var TextInput = function(parentNode, host) { } sendText(); }, 0); - } + }; }; exports.TextInput = TextInput; diff --git a/lib/ace/layer/gutter.js b/lib/ace/layer/gutter.js index b4354b5b..5edf038d 100644 --- a/lib/ace/layer/gutter.js +++ b/lib/ace/layer/gutter.js @@ -61,7 +61,7 @@ var Gutter = function(parentEl) { if (!this.$decorations[row]) this.$decorations[row] = ""; this.$decorations[row] += " ace_" + className; - } + }; this.removeGutterDecoration = function(row, className){ this.$decorations[row] = this.$decorations[row].replace(" ace_" + className, ""); @@ -73,12 +73,12 @@ var Gutter = function(parentEl) { this.setAnnotations = function(annotations) { // iterate over sparse array - this.$annotations = []; + this.$annotations = []; for (var row in annotations) if (annotations.hasOwnProperty(row)) { var rowAnnotations = annotations[row]; if (!rowAnnotations) continue; - + var rowInfo = this.$annotations[row] = { text: [] }; @@ -112,7 +112,8 @@ var Gutter = function(parentEl) { "' title='", annotation.text.join("\n"), "' style='height:", this.session.getRowHeight(config, i), "px;'>", (i+1), ""); } - this.element = dom.setInnerHtml(this.element, html.join("")); + + this.element = dom.rebuildWith(this.element, html.join("")); this.element.style.height = config.minHeight + "px"; }; diff --git a/lib/ace/layer/marker.js b/lib/ace/layer/marker.js index 028bef33..c58422a9 100644 --- a/lib/ace/layer/marker.js +++ b/lib/ace/layer/marker.js @@ -53,7 +53,7 @@ var Marker = function(parentEl) { this.setSession = function(session) { this.session = session; }; - + this.setMarkers = function(markers) { this.markers = markers; }; @@ -65,7 +65,7 @@ var Marker = function(parentEl) { this.config = config; - var html = []; + var html = []; for ( var key in this.markers) { var marker = this.markers[key]; @@ -76,7 +76,7 @@ var Marker = function(parentEl) { if (marker.renderer) { var top = this.$getTop(range.start.row, config); - var left = Math.round(range.start.column * config.characterWidth); + var left = Math.round(range.start.column * config.characterWidth); marker.renderer(html, range, left, top, config); } else if (range.isMultiLine()) { @@ -90,7 +90,7 @@ var Marker = function(parentEl) { this.drawSingleLineMarker(html, range, marker.clazz, config); } } - this.element = dom.setInnerHtml(this.element, html.join("")); + this.element = dom.rebuildWith(this.element, html.join("")); }; this.$getTop = function(row, layerConfig) { diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index 833338c6..9290431c 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -199,7 +199,7 @@ var Text = function(parentEl) { var html = []; this.$renderLine(html, i, tokens[i-first].tokens); - lineElement = dom.setInnerHtml(lineElement, html.join("")); + lineElement = dom.rebuildWith(lineElement, html.join("")); lineElement.style.height = this.session.getRowHeight(config, i) + "px"; } @@ -253,7 +253,7 @@ var Text = function(parentEl) { var html = []; if (tokens.length > row-firstRow) this.$renderLine(html, row, tokens[row-firstRow].tokens); - // don't use setInnerHtml since we are working with an empty DIV + // don't use dom.rebuildWith since we are working with an empty DIV lineEl.innerHTML = html.join(""); fragment.appendChild(lineEl); } @@ -265,7 +265,7 @@ var Text = function(parentEl) { this.config = config; var html = []; - var tokens = this.tokenizer.getTokens(config.firstRow, config.lastRow) + var tokens = this.tokenizer.getTokens(config.firstRow, config.lastRow); var fragment = this.$renderLinesFragment(config, config.firstRow, config.lastRow); // Clear the current content of the element and add the rendered fragment. @@ -303,11 +303,11 @@ var Text = function(parentEl) { var space = new Array(c.length+1).join(self.SPACE_CHAR); return "" + space + ""; } else { - return " " + return " "; } } else { screenColumn += 1; - return "" + c + "" + return "" + c + ""; } }); screenColumn += value.length; diff --git a/lib/ace/mode/textile_highlight_rules.js b/lib/ace/mode/textile_highlight_rules.js index b005d1b7..148d2be8 100644 --- a/lib/ace/mode/textile_highlight_rules.js +++ b/lib/ace/mode/textile_highlight_rules.js @@ -46,7 +46,7 @@ var TextileHighlightRules = function() var phraseModifiers = lang.arrayToMap( ("_|*|__|**|??|-|+|^|%|@").split("|") ); - + var blockModifiers = lang.arrayToMap( ("h1|h2|h3|h4|h5|h6|bq|p|bc|pre").split("|") ); @@ -56,7 +56,7 @@ var TextileHighlightRules = function() ("-|--|(tm)|(r)|(c)").split("|") ); */ - + this.$rules = { "start" : [ { @@ -77,7 +77,7 @@ var TextileHighlightRules = function() { token : "keyword", regex : "\\. ", - next : "start", + next : "start" }, { token : "keyword", diff --git a/support/cockpit b/support/cockpit index 7a14c62f..5ab8377d 160000 --- a/support/cockpit +++ b/support/cockpit @@ -1 +1 @@ -Subproject commit 7a14c62f84cf51e83a31b14d9a79f875bcabeacc +Subproject commit 5ab8377de0c2b6bf31e4295e5bb9288cb943e8e8