reduce flickering of annotations while editing

This commit is contained in:
nightwing 2012-09-02 18:33:27 +04:00
commit b44bcb50ce

View file

@ -44,6 +44,7 @@ var Gutter = function(parentEl) {
this.gutterWidth = 0;
this.$annotations = [];
this.$updateAnnotations = this.$updateAnnotations.bind(this);
};
(function() {
@ -51,7 +52,10 @@ var Gutter = function(parentEl) {
oop.implement(this, EventEmitter);
this.setSession = function(session) {
if (this.session)
this.session.removeEventListener("change", this.$updateAnnotations);
this.session = session;
session.on("change", this.$updateAnnotations);
};
this.addGutterDecoration = function(row, className){
@ -93,6 +97,24 @@ var Gutter = function(parentEl) {
}
};
this.$updateAnnotations = function (e) {
if (!this.$annotations.length)
return;
var delta = e.data;
var range = delta.range;
var firstRow = range.start.row;
var len = range.end.row - firstRow;
if (len === 0) {
// do nothing
} else if (delta.action == "removeText" || delta.action == "removeLines") {
this.$annotations.splice(firstRow, len + 1, null);
} else {
var args = Array(len + 1);
args.unshift(firstRow, 1);
this.$annotations.splice.apply(this.$annotations, args);
}
};
this.update = function(config) {
var emptyAnno = {className: ""};
var html = [];