From 10c2f72720628c952138bc87dffd6505576fdcd0 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Thu, 4 Dec 2014 16:01:39 +0100 Subject: [PATCH] dont remove more lines than exist in the whole text --- src/static/js/Changeset.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index 355bef4a9..366ad15f9 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -903,6 +903,8 @@ exports.pack = function (oldLen, newLen, opsStr, bank) { * @params str {string} String to which a Changeset should be applied */ exports.applyToText = function (cs, str) { + var totalNrOfLines = str.split("\n").length; + var removedLines = 0; var unpacked = exports.unpack(cs); exports.assert(str.length == unpacked.oldLen, "mismatched apply: ", str.length, " / ", unpacked.oldLen); var csIter = exports.opIterator(unpacked.ops); @@ -916,6 +918,7 @@ exports.applyToText = function (cs, str) { assem.append(bankIter.take(op.chars)); break; case '-': + removedLines += op.lines; strIter.skip(op.chars); break; case '=': @@ -923,6 +926,7 @@ exports.applyToText = function (cs, str) { break; } } + exports.assert(totalNrOfLines >= removedLines,"cannot remove ", removedLines, " lines from text with ", totalNrOfLines, " lines"); assem.append(strIter.take(strIter.remaining())); return assem.toString(); };