Simplify update method of cursor layer
This commit is contained in:
parent
f38a4e0e5b
commit
c2c650db1c
1 changed files with 24 additions and 34 deletions
|
|
@ -141,13 +141,15 @@ 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, sel, cursorIndex = 0;
|
var i = 0, cursorIndex = 0;
|
||||||
|
|
||||||
|
if (selections === undefined || selections.length === 0){
|
||||||
|
selections = [{cursor: null}];
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = selections.length; i--; ) {
|
for (var i = selections.length; i--; ) {
|
||||||
sel = selections[i];
|
var pixelPos = this.getPixelPosition(selections[i].cursor, true);
|
||||||
var pixelPos = this.getPixelPosition(sel.cursor, true);
|
|
||||||
if ((pixelPos.top > config.height + config.offset ||
|
if ((pixelPos.top > config.height + config.offset ||
|
||||||
pixelPos.top < -config.offset) && i > 1) {
|
pixelPos.top < -config.offset) && i > 1) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -160,32 +162,19 @@ var Cursor = function(parentEl) {
|
||||||
style.width = config.characterWidth + "px";
|
style.width = config.characterWidth + "px";
|
||||||
style.height = config.lineHeight + "px";
|
style.height = config.lineHeight + "px";
|
||||||
}
|
}
|
||||||
if (cursorIndex > 1)
|
|
||||||
while (this.cursors.length > cursorIndex)
|
while (this.cursors.length > cursorIndex)
|
||||||
this.removeCursor();
|
this.removeCursor();
|
||||||
} else {
|
|
||||||
var pixelPos = this.getPixelPosition(null, true);
|
|
||||||
var style = this.cursor.style;
|
|
||||||
style.left = pixelPos.left + "px";
|
|
||||||
style.top = pixelPos.top + "px";
|
|
||||||
style.width = config.characterWidth + "px";
|
|
||||||
style.height = config.lineHeight + "px";
|
|
||||||
|
|
||||||
while (this.cursors.length > 1)
|
|
||||||
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) {
|
||||||
|
if (overwrite != this.overwrite) {
|
||||||
this.overwrite = overwrite;
|
this.overwrite = overwrite;
|
||||||
for (var i = this.cursors.length; i--; ) {
|
for (var i = this.cursors.length; i--; ) {
|
||||||
if (overwrite)
|
if (overwrite)
|
||||||
|
|
@ -193,6 +182,7 @@ var Cursor = function(parentEl) {
|
||||||
else
|
else
|
||||||
dom.removeCssClass(this.cursors[i], "ace_overwrite");
|
dom.removeCssClass(this.cursors[i], "ace_overwrite");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.destroy = function() {
|
this.destroy = function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue