use objects instead of sparse arrays

This commit is contained in:
Fabian Jakobs 2011-02-02 18:10:42 +01:00
commit 4010fad254
2 changed files with 7 additions and 4 deletions

View file

@ -214,7 +214,7 @@ var EditSession = function(text, mode) {
* }
*/
this.setAnnotations = function(annotations) {
this.$annotations = [];
this.$annotations = {};
for (var i=0; i<annotations.length; i++) {
var annotation = annotations[i];
var row = annotation.row;
@ -231,7 +231,7 @@ var EditSession = function(text, mode) {
};
this.clearAnnotations = function() {
this.$annotations = [];
this.$annotations = {};
this._dispatchEvent("changeAnnotation", {});
};

View file

@ -72,12 +72,15 @@ var Gutter = function(parentEl) {
this.setAnnotations = function(annotations) {
// iterate over sparse array
this.$annotations = [];
this.$annotations = [];
for (var row in annotations) {
var rowAnnotations = annotations[row];
if (!rowAnnotations)
continue;
var rowInfo = this.$annotations[row] = {
text: []
};
var rowAnnotations = annotations[row];
for (var i=0; i<rowAnnotations.length; i++) {
var annotation = rowAnnotations[i];
rowInfo.text.push(annotation.text.replace(/"/g, "&quot;").replace(/'/g, "&rsquo;").replace(/</, "&lt;"));