Simplify update method of cursor layer

This commit is contained in:
DanyaPostfactum 2012-10-02 03:36:42 +10:00 • committed by nightwing
commit c2c650db1c

View file

@ -141,57 +141,47 @@ var Cursor = function(parentEl) {
this.update = function(config) { this.update = function(config) {
this.config = config; this.config = config;
if (this.session.selectionMarkerCount > 0) { var selections = this.session.$selectionMarkers;
var selections = this.session.$selectionMarkers; var i = 0, cursorIndex = 0;
var i = 0, sel, cursorIndex = 0;
for (var i = selections.length; i--; ) { if (selections === undefined || selections.length === 0){
sel = selections[i]; selections = [{cursor: null}];
var pixelPos = this.getPixelPosition(sel.cursor, true); }
if ((pixelPos.top > config.height + config.offset ||
pixelPos.top < -config.offset) && i > 1) {
continue;
}
var style = (this.cursors[cursorIndex++] || this.addCursor()).style; for (var i = selections.length; i--; ) {
var pixelPos = this.getPixelPosition(selections[i].cursor, true);
style.left = pixelPos.left + "px"; if ((pixelPos.top > config.height + config.offset ||
style.top = pixelPos.top + "px"; pixelPos.top < -config.offset) && i > 1) {
style.width = config.characterWidth + "px"; continue;
style.height = config.lineHeight + "px";
} }
if (cursorIndex > 1)
while (this.cursors.length > cursorIndex) var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
this.removeCursor();
} else {
var pixelPos = this.getPixelPosition(null, true);
var style = this.cursor.style;
style.left = pixelPos.left + "px"; style.left = pixelPos.left + "px";
style.top = pixelPos.top + "px"; style.top = pixelPos.top + "px";
style.width = config.characterWidth + "px"; style.width = config.characterWidth + "px";
style.height = config.lineHeight + "px"; style.height = config.lineHeight + "px";
while (this.cursors.length > 1)
this.removeCursor();
} }
while (this.cursors.length > cursorIndex)
this.removeCursor();
var overwrite = this.session.getOverwrite(); var overwrite = this.session.getOverwrite();
if (overwrite != this.overwrite) this.$setOverwrite(overwrite);
this.$setOverwrite(overwrite);
// cache for textarea and gutter highlight // cache for textarea and gutter highlight
this.$pixelPos = pixelPos; this.$pixelPos = pixelPos;
this.restartTimer(); this.restartTimer();
}; };
this.$setOverwrite = function(overwrite) { this.$setOverwrite = function(overwrite) {
this.overwrite = overwrite; if (overwrite != this.overwrite) {
for (var i = this.cursors.length; i--; ) { this.overwrite = overwrite;
if (overwrite) for (var i = this.cursors.length; i--; ) {
dom.addCssClass(this.cursors[i], "ace_overwrite"); if (overwrite)
else dom.addCssClass(this.cursors[i], "ace_overwrite");
dom.removeCssClass(this.cursors[i], "ace_overwrite"); else
dom.removeCssClass(this.cursors[i], "ace_overwrite");
}
} }
}; };