From c2c650db1cd1db06126bbd9faa2b894f64e9be2f Mon Sep 17 00:00:00 2001 From: DanyaPostfactum Date: Tue, 2 Oct 2012 03:36:42 +1000 Subject: [PATCH] Simplify update method of cursor layer --- lib/ace/layer/cursor.js | 58 +++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/lib/ace/layer/cursor.js b/lib/ace/layer/cursor.js index 9d688b57..db208f3d 100644 --- a/lib/ace/layer/cursor.js +++ b/lib/ace/layer/cursor.js @@ -141,57 +141,47 @@ var Cursor = function(parentEl) { this.update = function(config) { this.config = config; - if (this.session.selectionMarkerCount > 0) { - var selections = this.session.$selectionMarkers; - var i = 0, sel, cursorIndex = 0; + var selections = this.session.$selectionMarkers; + var i = 0, cursorIndex = 0; - for (var i = selections.length; i--; ) { - sel = selections[i]; - var pixelPos = this.getPixelPosition(sel.cursor, true); - if ((pixelPos.top > config.height + config.offset || - pixelPos.top < -config.offset) && i > 1) { - continue; - } + if (selections === undefined || selections.length === 0){ + selections = [{cursor: null}]; + } - var style = (this.cursors[cursorIndex++] || this.addCursor()).style; - - style.left = pixelPos.left + "px"; - style.top = pixelPos.top + "px"; - style.width = config.characterWidth + "px"; - style.height = config.lineHeight + "px"; + for (var i = selections.length; i--; ) { + var pixelPos = this.getPixelPosition(selections[i].cursor, true); + if ((pixelPos.top > config.height + config.offset || + pixelPos.top < -config.offset) && i > 1) { + continue; } - if (cursorIndex > 1) - while (this.cursors.length > cursorIndex) - this.removeCursor(); - } else { - var pixelPos = this.getPixelPosition(null, true); - var style = this.cursor.style; + + var style = (this.cursors[cursorIndex++] || this.addCursor()).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(); } + while (this.cursors.length > cursorIndex) + this.removeCursor(); var overwrite = this.session.getOverwrite(); - if (overwrite != this.overwrite) - this.$setOverwrite(overwrite); + this.$setOverwrite(overwrite); // cache for textarea and gutter highlight this.$pixelPos = pixelPos; - this.restartTimer(); }; this.$setOverwrite = function(overwrite) { - this.overwrite = overwrite; - for (var i = this.cursors.length; i--; ) { - if (overwrite) - dom.addCssClass(this.cursors[i], "ace_overwrite"); - else - dom.removeCssClass(this.cursors[i], "ace_overwrite"); + if (overwrite != this.overwrite) { + this.overwrite = overwrite; + for (var i = this.cursors.length; i--; ) { + if (overwrite) + dom.addCssClass(this.cursors[i], "ace_overwrite"); + else + dom.removeCssClass(this.cursors[i], "ace_overwrite"); + } } };