fix foldwidgets getting out of sync with document

This commit is contained in:
nightwing 2012-05-22 23:15:34 +04:00
commit 505b1fc3c6
4 changed files with 14 additions and 28 deletions

View file

@ -42,7 +42,7 @@ var oop = require("./lib/oop");
var EventEmitter = require("./lib/event_emitter").EventEmitter;
var Range = require("./range").Range;
var Anchor = require("./anchor").Anchor;
var lang = require("./lib/lang");
/**
* class Document
*
@ -326,8 +326,15 @@ var Document = function(text) {
if (lines.length == 0)
return {row: row, column: 0};
if (lines.length > 0xFFFF) {
var end = this.insertLines(row, lines.slice(0xFFFF));
lines = lines.slice(0, 0xFFFF);
}
var args = [row, 0];
this.$lines = lang.chunkLines(lines, this.$lines, args, true);
args.push.apply(args, lines);
this.$lines.splice.apply(this.$lines, args);
var range = new Range(row, 0, row + lines.length, 0);
var delta = {
action: "insertLines",
@ -335,7 +342,7 @@ var Document = function(text) {
lines: lines
};
this._emit("change", { data: delta });
return range.end;
return end || range.end;
};
/**

View file

@ -43,7 +43,7 @@ var Range = require("../range").Range;
var FoldLine = require("./fold_line").FoldLine;
var Fold = require("./fold").Fold;
var TokenIterator = require("../token_iterator").TokenIterator;
var lang = require("../lib/lang");
function Folding() {
/*
* Looks up a fold at a given row/column. Possible values for side:
@ -748,8 +748,7 @@ function Folding() {
} else {
var args = Array(len + 1);
args.unshift(firstRow, 1);
this.foldWidgets = lang.chunkLines(args, this.foldWidgets);
this.foldWidgets.splice.apply(this.foldWidgets, args);
}
};

View file

@ -147,24 +147,4 @@ exports.deferredCall = function(fcn) {
return deferred;
};
// because of Document, this is confusing as shit
exports.chunkLines = function(args, thingToSplice, thingtoApply, isDocument) {
if (thingtoApply === undefined)
thingtoApply = thingToSplice;
var step = 100000;
var l = Math.ceil(args.length / step);
for (var targs, i = 0; i < l; i++) {
targs = args.slice(i * step, step);
if (isDocument) {
thingtoApply.push.apply(thingtoApply, targs);
thingToSplice.splice.apply(thingToSplice, thingtoApply);
}
else
thingToSplice.slice.apply(thingtoApply, targs);
}
return thingToSplice;
};
});

View file

@ -1,5 +1,5 @@
"no use strict";
var lang = require("../lib/lang");
var console = {
log: function(msg) {
postMessage({type: "log", data: msg});
@ -123,7 +123,7 @@ var sender;
onmessage = function(e) {
var msg = e.data;
if (msg.command) {
main[msg.command] = lang.chunkLines(msg.args, main[msg.command], main);
main[msg.command].apply(main, msg.args);
}
else if (msg.init) {
initBaseUrls(msg.tlns);