no need to pass around the layer config anymore

This commit is contained in:
Fabian Jakobs 2011-07-29 13:39:43 +02:00
commit 3cf7ef9a61
5 changed files with 85 additions and 90 deletions

View file

@ -67,10 +67,10 @@ var Cursor = function(model, parentEl) {
this.isVisible = true;
dom.removeCssClass(this.cursor, "ace_hidden");
this.cursor.style.visibility = "visible";
this.restartTimer();
this._restartTimer();
};
this.restartTimer = function() {
this._restartTimer = function() {
clearInterval(this.blinkId);
if (!this.isVisible) {
return;
@ -85,17 +85,18 @@ var Cursor = function(model, parentEl) {
}, 1000);
};
this.update = function(config) {
this.pixelPos = this.model.getCursorPixelPosition(true);
var charSize = this.model.charSize;
this.update = function() {
var model = this.model;
this.pixelPos = model.getCursorPixelPosition(true);
var charSize = model.charSize;
this.cursor.style.left = this.pixelPos.left + "px";
this.cursor.style.top = this.pixelPos.top + "px";
this.cursor.style.width = charSize.width + "px";
this.cursor.style.height = charSize.height + "px";
var overwrite = this.model.buffer.getOverwrite()
var overwrite = model.buffer.getOverwrite()
if (overwrite != this.overwrite) {
this.overwrite = overwrite;
if (overwrite)
@ -104,7 +105,7 @@ var Cursor = function(model, parentEl) {
dom.removeCssClass(this.cursor, "ace_overwrite");
}
this.restartTimer();
this._restartTimer();
};
this.destroy = function() {

View file

@ -94,9 +94,8 @@ var Gutter = function(model, parentEl) {
}
};
this.update = function(config) {
this.$config = config;
this.update = function() {
var config = this.model.layerConfig;
var emptyAnno = {className: "", text: []};
var html = [];
var i = config.firstRow;

View file

@ -56,13 +56,9 @@ var Marker = function(model, parentEl) {
this.markers = markers;
};
this.update = function(config) {
var config = config || this.config;
if (!config)
return;
this.config = config;
this.update = function() {
var model = this.model;
var config = model.layerConfig;
var html = [];
for ( var key in this.markers) {
@ -73,7 +69,7 @@ var Marker = function(model, parentEl) {
range = range.toScreenRange(this.model.buffer);
if (marker.renderer) {
var top = this.$getTop(range.start.row);
var top = this._top(range.start.row);
var left = Math.round(
this.model.padding + range.start.column * model.charSize.width
);
@ -81,17 +77,17 @@ var Marker = function(model, parentEl) {
}
else if (range.isMultiLine()) {
if (marker.type == "text") {
this.drawTextMarker(html, range, marker.clazz, config);
this._drawTextMarker(html, range, marker.clazz);
} else {
this.drawMultiLineMarker(
html, range, marker.clazz, config,
this._drawMultiLineMarker(
html, range, marker.clazz,
marker.type
);
}
}
else {
this.drawSingleLineMarker(
html, range, marker.clazz, config,
this._drawSingleLineMarker(
html, range, marker.clazz,
null, marker.type
);
}
@ -99,14 +95,14 @@ var Marker = function(model, parentEl) {
this.element = dom.setInnerHtml(this.element, html.join(""));
};
this.$getTop = function(row) {
this._top = function(row) {
return (row - this.model.layerConfig.firstRowScreen) * this.model.charSize.height;
};
/**
* Draws a marker, which spans a range of text in a single line
*/
this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig) {
this._drawTextMarker = function(stringBuilder, range, clazz) {
// selection start
var row = range.start.row;
@ -114,31 +110,32 @@ var Marker = function(model, parentEl) {
row, range.start.column,
row, this.model.buffer.getScreenLastRowColumn(row)
);
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1, "text");
this._drawSingleLineMarker(stringBuilder, lineRange, clazz, 1, "text");
// selection end
row = range.end.row;
lineRange = new Range(row, 0, row, range.end.column);
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 0, "text");
this._drawSingleLineMarker(stringBuilder, lineRange, clazz, 0, "text");
for (row = range.start.row + 1; row < range.end.row; row++) {
lineRange.start.row = row;
lineRange.end.row = row;
lineRange.end.column = this.model.buffer.getScreenLastRowColumn(row);
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1, "text");
this._drawSingleLineMarker(stringBuilder, lineRange, clazz, 1, "text");
}
};
/**
* Draws a multi line marker, where lines span the full width
*/
this.drawMultiLineMarker = function(stringBuilder, range, clazz, layerConfig, type) {
this._drawMultiLineMarker = function(stringBuilder, range, clazz, type) {
// from selection start to the end of the line
var layerConfig = this.model.config;
var charSize = this.model.charSize;
var padding = type === "background" ? 0 : this.model.padding;
var height = charSize.height;
var width = Math.round(layerConfig.width - (range.start.column * charSize.width));
var top = this.$getTop(range.start.row);
var top = this._top(range.start.row);
var left = Math.round(padding + range.start.column * charSize.width);
stringBuilder.push(
@ -150,7 +147,7 @@ var Marker = function(model, parentEl) {
);
// from start of the last line to the selection end
top = this.$getTop(range.end.row);
top = this._top(range.end.row);
width = Math.round(range.end.column * charSize.width);
stringBuilder.push(
@ -165,7 +162,7 @@ var Marker = function(model, parentEl) {
height = (range.end.row - range.start.row - 1) * charSize.height;
if (height < 0)
return;
top = this.$getTop(range.start.row + 1);
top = this._top(range.start.row + 1);
width = layerConfig.width;
stringBuilder.push(
@ -180,17 +177,17 @@ var Marker = function(model, parentEl) {
/**
* Draws a marker which covers one single full line
*/
this.drawSingleLineMarker = function(stringBuilder, range, clazz, layerConfig, extraLength, type) {
this._drawSingleLineMarker = function(stringBuilder, range, clazz, extraLength, type) {
var charSize = this.model.charSize;
var padding = type === "background" ? 0 : this.model.padding;
var height = charSize.height;
if (type === "background")
var width = layerConfig.width;
var width = this.model.layerConfig.width;
else
width = Math.round((range.end.column + (extraLength || 0) - range.start.column) * charSize.width);
var top = this.$getTop(range.start.row);
var top = this._top(range.start.row);
var left = Math.round(padding + range.start.column * charSize.width);
stringBuilder.push(

View file

@ -68,10 +68,10 @@ var Text = function(model, parentEl) {
this.session = session;
};
this.$tabStrings = [];
this.$computeTabString = function() {
this._tabStrings = [];
this._computeTabString = function() {
var tabSize = this.session.getTabSize();
var tabStr = this.$tabStrings = [0];
var tabStr = this._tabStrings = [0];
for (var i = 1; i < tabSize + 1; i++) {
if (this.model.showInvisibles) {
tabStr.push("<span class='ace_invisible'>"
@ -82,16 +82,16 @@ var Text = function(model, parentEl) {
tabStr.push(new Array(i+1).join("&#160;"));
}
}
};
this.updateLines = function(config, firstRow, lastRow) {
this.$computeTabString();
this.updateLines = function(firstRow, lastRow) {
var config = this.model.layerConfig;
this._computeTabString();
// Due to wrap line changes there can be new lines if e.g.
// the line to updated wrapped in the meantime.
if (this.config.lastRow != config.lastRow ||
this.config.firstRow != config.firstRow) {
this.scrollLines(config);
this.scrollLines();
}
this.config = config;
@ -120,15 +120,16 @@ var Text = function(model, parentEl) {
var html = [];
var tokens = this.session.getTokens(i, i);
this.$renderLine(html, i, tokens[0].tokens, !this.$useLineGroups());
this._renderLine(html, i, tokens[0].tokens, !this.$useLineGroups());
lineElement = dom.setInnerHtml(lineElement, html.join(""));
i = this.session.getRowFoldEnd(i);
}
};
this.scrollLines = function(config) {
this.$computeTabString();
this.scrollLines = function() {
this._computeTabString();
var config = this.model.layerConfig;
var oldConfig = this.config;
this.config = config;
@ -148,7 +149,7 @@ var Text = function(model, parentEl) {
el.removeChild(el.lastChild);
if (config.firstRow < oldConfig.firstRow) {
var fragment = this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1);
var fragment = this._renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1);
if (el.firstChild)
el.insertBefore(fragment, el.firstChild);
else
@ -156,12 +157,12 @@ var Text = function(model, parentEl) {
}
if (config.lastRow > oldConfig.lastRow) {
var fragment = this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow);
var fragment = this._renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow);
el.appendChild(fragment);
}
};
this.$renderLinesFragment = function(config, firstRow, lastRow) {
this._renderLinesFragment = function(config, firstRow, lastRow) {
var fragment = document.createDocumentFragment(),
row = firstRow,
fold = this.session.getNextFold(row),
@ -185,7 +186,7 @@ var Text = function(model, parentEl) {
// this call once for that big block of unfolded lines.
var tokens = this.session.getTokens(row, row);
if (tokens.length == 1)
this.$renderLine(html, row, tokens[0].tokens, false);
this._renderLine(html, row, tokens[0].tokens, false);
// don't use setInnerHtml since we are working with an empty DIV
container.innerHTML = html.join("");
@ -203,8 +204,9 @@ var Text = function(model, parentEl) {
return fragment;
};
this.update = function(config) {
this.$computeTabString();
this.update = function() {
this._computeTabString();
var config = this.model.layerConfig;
this.config = config;
var html = [];
@ -232,7 +234,7 @@ var Text = function(model, parentEl) {
// this call once for that big block of unfolded lines.
var tokens = this.session.getTokens(row, row);
if (tokens.length == 1)
this.$renderLine(html, row, tokens[0].tokens, false);
this._renderLine(html, row, tokens[0].tokens, false);
if (this.$useLineGroups())
html.push("</div>"); // end the line group
@ -242,13 +244,13 @@ var Text = function(model, parentEl) {
this.element = dom.setInnerHtml(this.element, html.join(""));
};
this.$textToken = {
this._textToken = {
"text": true,
"rparen": true,
"lparen": true
};
this.$renderToken = function(stringBuilder, screenColumn, token, value) {
this._renderToken = function(stringBuilder, screenColumn, token, value) {
var self = this;
var replaceReg = /\t|&|<|( +)|([\v\f \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000])|[\u1100-\u115F]|[\u11A3-\u11A7]|[\u11FA-\u11FF]|[\u2329-\u232A]|[\u2E80-\u2E99]|[\u2E9B-\u2EF3]|[\u2F00-\u2FD5]|[\u2FF0-\u2FFB]|[\u3000-\u303E]|[\u3041-\u3096]|[\u3099-\u30FF]|[\u3105-\u312D]|[\u3131-\u318E]|[\u3190-\u31BA]|[\u31C0-\u31E3]|[\u31F0-\u321E]|[\u3220-\u3247]|[\u3250-\u32FE]|[\u3300-\u4DBF]|[\u4E00-\uA48C]|[\uA490-\uA4C6]|[\uA960-\uA97C]|[\uAC00-\uD7A3]|[\uD7B0-\uD7C6]|[\uD7CB-\uD7FB]|[\uF900-\uFAFF]|[\uFE10-\uFE19]|[\uFE30-\uFE52]|[\uFE54-\uFE66]|[\uFE68-\uFE6B]|[\uFF01-\uFF60]|[\uFFE0-\uFFE6]/g;
var replaceFunc = function(c, a, b, tabIdx, idx4) {
@ -257,7 +259,7 @@ var Text = function(model, parentEl) {
} else if (c == "\t") {
var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
screenColumn += tabSize - 1;
return self.$tabStrings[tabSize];
return self._tabStrings[tabSize];
} else if (c == "&") {
if (useragent.isOldGecko)
return "&";
@ -290,7 +292,7 @@ var Text = function(model, parentEl) {
var output = value.replace(replaceReg, replaceFunc);
if (!this.$textToken[token.type]) {
if (!this._textToken[token.type]) {
var classes = "ace_" + token.type.replace(/\./g, " ace_");
stringBuilder.push("<span class='", classes, "'>", output, "</span>");
}
@ -300,7 +302,7 @@ var Text = function(model, parentEl) {
return screenColumn + value.length;
};
this.$renderLineCore = function(stringBuilder, lastRow, tokens, splits, onlyContents) {
this._renderLineCore = function(stringBuilder, lastRow, tokens, splits, onlyContents) {
var chars = 0;
var split = 0;
var splitChars;
@ -325,14 +327,14 @@ var Text = function(model, parentEl) {
var value = token.value;
if (chars + value.length < splitChars) {
screenColumn = self.$renderToken(
screenColumn = self._renderToken(
stringBuilder, screenColumn, token, value
);
chars += value.length;
}
else {
while (chars + value.length >= splitChars) {
screenColumn = self.$renderToken(
screenColumn = self._renderToken(
stringBuilder, screenColumn,
token, value.substring(0, splitChars - chars)
);
@ -353,7 +355,7 @@ var Text = function(model, parentEl) {
}
if (value.length != 0) {
chars += value.length;
screenColumn = self.$renderToken(
screenColumn = self._renderToken(
stringBuilder, screenColumn, token, value
);
}
@ -370,18 +372,18 @@ var Text = function(model, parentEl) {
stringBuilder.push("</div>");
};
this.$renderLine = function(stringBuilder, row, tokens, onlyContents) {
this._renderLine = function(stringBuilder, row, tokens, onlyContents) {
// Check if the line to render is folded or not. If not, things are
// simple, otherwise, we need to fake some things...
if (!this.session.isRowFolded(row)) {
var splits = this.session.getRowSplitData(row);
this.$renderLineCore(stringBuilder, row, tokens, splits, onlyContents);
this._renderLineCore(stringBuilder, row, tokens, splits, onlyContents);
} else {
this.$renderFoldLine(stringBuilder, row, tokens, onlyContents);
this._renderFoldLine(stringBuilder, row, tokens, onlyContents);
}
};
this.$renderFoldLine = function(stringBuilder, row, tokens, onlyContents) {
this._renderFoldLine = function(stringBuilder, row, tokens, onlyContents) {
var session = this.session,
foldLine = session.getFoldLine(row),
renderTokens = [];
@ -443,8 +445,8 @@ var Text = function(model, parentEl) {
}.bind(this), foldLine.end.row, this.session.getLine(foldLine.end.row).length);
// TODO: Build a fake splits array!
var splits = this.session.$useWrapMode?this.session.$wrapData[row]:null;
this.$renderLineCore(stringBuilder, row, renderTokens, splits, onlyContents);
var splits = this.session._useWrapMode?this.session._wrapData[row]:null;
this._renderLineCore(stringBuilder, row, renderTokens, splits, onlyContents);
};
this.$useLineGroups = function() {
@ -457,10 +459,6 @@ var Text = function(model, parentEl) {
};
this.destroy = function() {
clearInterval(this.$pollSizeChangesTimer);
if (this.$measureNode)
this.$measureNode.parentNode.removeChild(this.$measureNode);
delete this.$measureNode;
};
}).call(Text.prototype);

View file

@ -326,12 +326,12 @@ var WindowView = function(windowModel, container) {
// full
if (changes & this.CHANGE_FULL) {
this.$textLayer.update(this.model.layerConfig);
this.$textLayer.update();
if (this.model.showGutter)
this.$gutterLayer.update(this.model.layerConfig);
this.$markerBack.update(this.model.layerConfig);
this.$markerFront.update(this.model.layerConfig);
this.$cursorLayer.update(this.model.layerConfig);
this.$gutterLayer.update();
this.$markerBack.update();
this.$markerFront.update();
this.$cursorLayer.update();
this.$updateScrollBar();
return;
}
@ -339,43 +339,43 @@ var WindowView = function(windowModel, container) {
// scrolling
if (changes & this.CHANGE_SCROLL) {
if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
this.$textLayer.update(this.model.layerConfig);
this.$textLayer.update();
else
this.$textLayer.scrollLines(this.model.layerConfig);
this.$textLayer.scrollLines();
if (this.model.showGutter)
this.$gutterLayer.update(this.model.layerConfig);
this.$markerBack.update(this.model.layerConfig);
this.$markerFront.update(this.model.layerConfig);
this.$cursorLayer.update(this.model.layerConfig);
this.$gutterLayer.update();
this.$markerBack.update();
this.$markerFront.update();
this.$cursorLayer.update();
this.$updateScrollBar();
return;
}
if (changes & this.CHANGE_TEXT) {
this.$textLayer.update(this.model.layerConfig);
this.$textLayer.update();
if (this.model.showGutter)
this.$gutterLayer.update(this.model.layerConfig);
this.$gutterLayer.update();
}
else if (changes & this.CHANGE_LINES) {
this.$updateLines();
this.$updateScrollBar();
if (this.model.showGutter)
this.$gutterLayer.update(this.model.layerConfig);
this.$gutterLayer.update();
} else if (changes & this.CHANGE_GUTTER) {
if (this.model.showGutter)
this.$gutterLayer.update(this.model.layerConfig);
this.$gutterLayer.update();
}
if (changes & this.CHANGE_CURSOR)
this.$cursorLayer.update(this.model.layerConfig);
this.$cursorLayer.update();
if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
this.$markerFront.update(this.model.layerConfig);
this.$markerFront.update();
}
if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
this.$markerBack.update(this.model.layerConfig);
this.$markerBack.update();
}
if (changes & this.CHANGE_SIZE)
@ -461,7 +461,7 @@ var WindowView = function(windowModel, container) {
// if the update changes the width of the document do a full redraw
if (layerConfig.width != this.$getLongestLine())
return this.$textLayer.update(layerConfig);
return this.$textLayer.update();
if (firstRow > layerConfig.lastRow + 1) { return; }
if (lastRow < layerConfig.firstRow) { return; }
@ -469,7 +469,7 @@ var WindowView = function(windowModel, container) {
// if the last row is unknown -> redraw everything
if (lastRow === Infinity) {
if (this.model.showGutter)
this.$gutterLayer.update(layerConfig);
this.$gutterLayer.update();
this.$textLayer.update(layerConfig);
return;
}