diff --git a/lib/ace/layer/gutter.js b/lib/ace/layer/gutter.js index be34f3c9..798df279 100644 --- a/lib/ace/layer/gutter.js +++ b/lib/ace/layer/gutter.js @@ -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 = [];