Use DOM methods to update gutter
This commit is contained in:
parent
6a76d63491
commit
53440ea548
1 changed files with 72 additions and 31 deletions
|
|
@ -46,6 +46,8 @@ var Gutter = function(parentEl) {
|
||||||
|
|
||||||
this.$annotations = [];
|
this.$annotations = [];
|
||||||
this.$updateAnnotations = this.$updateAnnotations.bind(this);
|
this.$updateAnnotations = this.$updateAnnotations.bind(this);
|
||||||
|
|
||||||
|
this.$cells = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
@ -117,11 +119,9 @@ var Gutter = function(parentEl) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.update = function(config) {
|
this.update = function(config) {
|
||||||
var emptyAnno = {className: ""};
|
var firstRow = config.firstRow;
|
||||||
var html = [];
|
|
||||||
var i = config.firstRow;
|
|
||||||
var lastRow = config.lastRow;
|
var lastRow = config.lastRow;
|
||||||
var fold = this.session.getNextFoldLine(i);
|
var fold = this.session.getNextFoldLine(firstRow);
|
||||||
var foldStart = fold ? fold.start.row : Infinity;
|
var foldStart = fold ? fold.start.row : Infinity;
|
||||||
var foldWidgets = this.$showFoldWidgets && this.session.foldWidgets;
|
var foldWidgets = this.$showFoldWidgets && this.session.foldWidgets;
|
||||||
var breakpoints = this.session.$breakpoints;
|
var breakpoints = this.session.$breakpoints;
|
||||||
|
|
@ -129,49 +129,90 @@ var Gutter = function(parentEl) {
|
||||||
var firstLineNumber = this.session.$firstLineNumber;
|
var firstLineNumber = this.session.$firstLineNumber;
|
||||||
var lastLineNumber = 0;
|
var lastLineNumber = 0;
|
||||||
|
|
||||||
|
var cell = null;
|
||||||
|
var index = -1;
|
||||||
|
var row = firstRow;
|
||||||
while (true) {
|
while (true) {
|
||||||
if(i > foldStart) {
|
if (row > foldStart) {
|
||||||
i = fold.end.row + 1;
|
row = fold.end.row + 1;
|
||||||
fold = this.session.getNextFoldLine(i, fold);
|
fold = this.session.getNextFoldLine(row, fold);
|
||||||
foldStart = fold ?fold.start.row :Infinity;
|
foldStart = fold ? fold.start.row : Infinity;
|
||||||
|
}
|
||||||
|
if (row > lastRow) {
|
||||||
|
while (this.$cells.length > index + 1) {
|
||||||
|
cell = this.$cells.pop();
|
||||||
|
this.element.removeChild(cell.element);
|
||||||
}
|
}
|
||||||
if(i > lastRow)
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
var annotation = this.$annotations[i] || emptyAnno;
|
cell = this.$cells[++index];
|
||||||
html.push(
|
if (!cell) {
|
||||||
"<div class='ace_gutter-cell ",
|
cell = {element: null, textNode: null, foldWidget: null};
|
||||||
breakpoints[i] || "", decorations[i] || "", annotation.className,
|
cell.element = dom.createElement("div");
|
||||||
"' style='height:", this.session.getRowLength(i) * config.lineHeight, "px;'>",
|
cell.textNode = document.createTextNode('');
|
||||||
lastLineNumber = i + firstLineNumber
|
cell.element.appendChild(cell.textNode);
|
||||||
);
|
this.element.appendChild(cell.element);
|
||||||
|
this.$cells[index] = cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
var className = "ace_gutter-cell";
|
||||||
|
if (breakpoints[row])
|
||||||
|
className += breakpoints[row];
|
||||||
|
if (decorations[row])
|
||||||
|
className += decorations[row];
|
||||||
|
if (this.$annotations[row])
|
||||||
|
className += this.$annotations[row].className;
|
||||||
|
if (cell.element.className != className)
|
||||||
|
cell.element.className = className;
|
||||||
|
|
||||||
|
var height = this.session.getRowLength(row) * config.lineHeight + "px";
|
||||||
|
if (height != cell.element.style.height)
|
||||||
|
cell.element.style.height = height;
|
||||||
|
|
||||||
|
var text = lastLineNumber = row + firstLineNumber;
|
||||||
|
if (text != cell.textNode.data)
|
||||||
|
cell.textNode.data = text;
|
||||||
|
|
||||||
if (foldWidgets) {
|
if (foldWidgets) {
|
||||||
var c = foldWidgets[i];
|
var c = foldWidgets[row];
|
||||||
// check if cached value is invalidated and we need to recompute
|
// check if cached value is invalidated and we need to recompute
|
||||||
if (c == null)
|
if (c == null)
|
||||||
c = foldWidgets[i] = this.session.getFoldWidget(i);
|
c = foldWidgets[row] = this.session.getFoldWidget(row);
|
||||||
if (c)
|
|
||||||
html.push(
|
|
||||||
"<span class='ace_fold-widget ace_", c,
|
|
||||||
c == "start" && i == foldStart && i < fold.end.row ? " ace_closed" : " ace_open",
|
|
||||||
"' style='height:", config.lineHeight, "px",
|
|
||||||
"'></span>"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html.push("</div>");
|
if (c) {
|
||||||
|
if (!cell.foldWidget) {
|
||||||
|
cell.foldWidget = dom.createElement("span");
|
||||||
|
cell.element.appendChild(cell.foldWidget);
|
||||||
|
}
|
||||||
|
var className = "ace_fold-widget ace_" + c;
|
||||||
|
if (c == "start" && row == foldStart && row < fold.end.row)
|
||||||
|
className += " ace_closed";
|
||||||
|
else
|
||||||
|
className += " ace_open";
|
||||||
|
if (cell.foldWidget.className != className)
|
||||||
|
cell.foldWidget.className = className;
|
||||||
|
|
||||||
i++;
|
var height = config.lineHeight + "px";
|
||||||
|
if (cell.foldWidget.style.height != height)
|
||||||
|
cell.foldWidget.style.height = height;
|
||||||
|
} else {
|
||||||
|
if (cell.foldWidget != null) {
|
||||||
|
cell.element.removeChild(cell.foldWidget);
|
||||||
|
cell.foldWidget = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.element = dom.setInnerHtml(this.element, html.join(""));
|
|
||||||
this.element.style.height = config.minHeight + "px";
|
this.element.style.height = config.minHeight + "px";
|
||||||
|
|
||||||
if (this.$fixedWidth || this.session.$useWrapMode)
|
if (this.$fixedWidth || this.session.$useWrapMode)
|
||||||
lastLineNumber = this.session.getLength();
|
lastLineNumber = this.session.getLength();
|
||||||
|
|
||||||
var gutterWidth = ("" + lastLineNumber).length * config.characterWidth;
|
var gutterWidth = lastLineNumber.toString().length * config.characterWidth;
|
||||||
var padding = this.$padding || this.$computePadding();
|
var padding = this.$padding || this.$computePadding();
|
||||||
gutterWidth += padding.left + padding.right;
|
gutterWidth += padding.left + padding.right;
|
||||||
if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
|
if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue