only update text layer if the document changes
This commit is contained in:
parent
f74b72b0fb
commit
8135c9a612
4 changed files with 65 additions and 36 deletions
24
Editor.js
24
Editor.js
|
|
@ -122,9 +122,7 @@ function Editor(doc, renderer)
|
||||||
addTripleClickListener(container, bind(this.selectCurrentLine, this));
|
addTripleClickListener(container, bind(this.selectCurrentLine, this));
|
||||||
|
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
doc.addChangeListener(function(startRow, endRow) {
|
doc.addChangeListener(bind(this.onDocumentChange, this));
|
||||||
console.log(startRow, endRow);
|
|
||||||
});
|
|
||||||
renderer.setDocument(doc);
|
renderer.setDocument(doc);
|
||||||
|
|
||||||
this.cursor = {
|
this.cursor = {
|
||||||
|
|
@ -136,17 +134,11 @@ function Editor(doc, renderer)
|
||||||
this.selectionLead = null;
|
this.selectionLead = null;
|
||||||
this.selection = null;
|
this.selection = null;
|
||||||
|
|
||||||
this.draw();
|
this.renderer.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor.prototype =
|
Editor.prototype =
|
||||||
{
|
{
|
||||||
draw : function()
|
|
||||||
{
|
|
||||||
this.renderer.draw();
|
|
||||||
this.renderer.updateCursor(this.cursor);
|
|
||||||
},
|
|
||||||
|
|
||||||
resize : function() {
|
resize : function() {
|
||||||
this.renderer.draw();
|
this.renderer.draw();
|
||||||
},
|
},
|
||||||
|
|
@ -165,6 +157,10 @@ Editor.prototype =
|
||||||
this.renderer.visualizeBlur();
|
this.renderer.visualizeBlur();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onDocumentChange : function(startRow, endRow) {
|
||||||
|
this.renderer.updateLines(startRow, endRow);
|
||||||
|
},
|
||||||
|
|
||||||
onMouseDown : function(e)
|
onMouseDown : function(e)
|
||||||
{
|
{
|
||||||
this.textInput.focus();
|
this.textInput.focus();
|
||||||
|
|
@ -265,7 +261,7 @@ Editor.prototype =
|
||||||
{
|
{
|
||||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.draw();
|
this.renderer.updateCursor(this.cursor);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -278,7 +274,7 @@ Editor.prototype =
|
||||||
} else {
|
} else {
|
||||||
this.cursor = this.doc.insert(this.cursor, text);
|
this.cursor = this.doc.insert(this.cursor, text);
|
||||||
}
|
}
|
||||||
this.draw();
|
this.renderer.updateCursor(this.cursor);
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -287,6 +283,7 @@ Editor.prototype =
|
||||||
if (this.hasSelection())
|
if (this.hasSelection())
|
||||||
{
|
{
|
||||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||||
|
this.renderer.updateCursor(this.cursor);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -301,7 +298,6 @@ Editor.prototype =
|
||||||
this.doc.remove({start: this.cursor, end: renageEnd});
|
this.doc.remove({start: this.cursor, end: renageEnd});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.draw();
|
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -329,7 +325,7 @@ Editor.prototype =
|
||||||
this.cursor = this.doc.remove({start: rangeStart, end: this.cursor});
|
this.cursor = this.doc.remove({start: rangeStart, end: this.cursor});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.draw();
|
this.renderer.updateCursor(this.cursor);
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,6 @@ TextDocument.prototype =
|
||||||
|
|
||||||
fireChangeEvent : function(firstRow, lastRow)
|
fireChangeEvent : function(firstRow, lastRow)
|
||||||
{
|
{
|
||||||
if (lastRow === undefined) {
|
|
||||||
lastRow = this.lines.length-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i=0; i < this.listeners.length; i++) {
|
for (var i=0; i < this.listeners.length; i++) {
|
||||||
this.listeners[i](firstRow, lastRow);
|
this.listeners[i](firstRow, lastRow);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
17
TextLayer.js
17
TextLayer.js
|
|
@ -42,6 +42,23 @@ TextLayer.prototype._measureSizes = function()
|
||||||
this.element.removeChild(measureNode);
|
this.element.removeChild(measureNode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow)
|
||||||
|
{
|
||||||
|
var first = Math.max(firstRow, layerConfig.firstRow);
|
||||||
|
var last = Math.min(lastRow, layerConfig.lastRow);
|
||||||
|
|
||||||
|
var lineElements = this.element.childNodes;
|
||||||
|
|
||||||
|
for (var i=first; i <= last; i++)
|
||||||
|
{
|
||||||
|
var html = [];
|
||||||
|
this.renderLine(html, i);
|
||||||
|
|
||||||
|
var lineElement = lineElements[i-layerConfig.firstRow];
|
||||||
|
lineElement.innerHTML = html.join("");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
TextLayer.prototype.update = function(config)
|
TextLayer.prototype.update = function(config)
|
||||||
{
|
{
|
||||||
var html = [];
|
var html = [];
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,26 @@ VirtualRenderer.prototype.getContainerElement = function() {
|
||||||
return this.container;
|
return this.container;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
|
||||||
|
{
|
||||||
|
var layerConfig = this.layerConfig;
|
||||||
|
|
||||||
|
// if the first row is below the viewport -> ignore it
|
||||||
|
if (firstRow > layerConfig.lastRow+1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the last row is unknow -> redraw everything
|
||||||
|
if (lastRow === undefined)
|
||||||
|
{
|
||||||
|
this.draw()
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// else update only the changed rows
|
||||||
|
this.textLayer.updateLines(layerConfig, firstRow, lastRow);
|
||||||
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.draw = function()
|
VirtualRenderer.prototype.draw = function()
|
||||||
{
|
{
|
||||||
var lines = this.lines;
|
var lines = this.lines;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue