mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
beautified all static js files
This commit is contained in:
parent
2fa1d8768b
commit
271ee1776b
36 changed files with 9456 additions and 6035 deletions
|
@ -25,7 +25,7 @@ function AttribPool()
|
|||
p.attribToNum = {}; // e.g. {'foo,bar': 0}
|
||||
p.nextNum = 0;
|
||||
|
||||
p.putAttrib = function (attrib, dontAddIfAbsent)
|
||||
p.putAttrib = function(attrib, dontAddIfAbsent)
|
||||
{
|
||||
var str = String(attrib);
|
||||
if (str in p.attribToNum)
|
||||
|
@ -42,28 +42,28 @@ function AttribPool()
|
|||
return num;
|
||||
};
|
||||
|
||||
p.getAttrib = function (num)
|
||||
p.getAttrib = function(num)
|
||||
{
|
||||
var pair = p.numToAttrib[num];
|
||||
if (!pair) return pair;
|
||||
return [pair[0], pair[1]]; // return a mutable copy
|
||||
};
|
||||
|
||||
p.getAttribKey = function (num)
|
||||
p.getAttribKey = function(num)
|
||||
{
|
||||
var pair = p.numToAttrib[num];
|
||||
if (!pair) return '';
|
||||
return pair[0];
|
||||
};
|
||||
|
||||
p.getAttribValue = function (num)
|
||||
p.getAttribValue = function(num)
|
||||
{
|
||||
var pair = p.numToAttrib[num];
|
||||
if (!pair) return '';
|
||||
return pair[1];
|
||||
};
|
||||
|
||||
p.eachAttrib = function (func)
|
||||
p.eachAttrib = function(func)
|
||||
{
|
||||
for (var n in p.numToAttrib)
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ function AttribPool()
|
|||
}
|
||||
};
|
||||
|
||||
p.toJsonable = function ()
|
||||
p.toJsonable = function()
|
||||
{
|
||||
return {
|
||||
numToAttrib: p.numToAttrib,
|
||||
|
@ -80,7 +80,7 @@ function AttribPool()
|
|||
};
|
||||
};
|
||||
|
||||
p.fromJsonable = function (obj)
|
||||
p.fromJsonable = function(obj)
|
||||
{
|
||||
p.numToAttrib = obj.numToAttrib;
|
||||
p.nextNum = obj.nextNum;
|
||||
|
@ -112,35 +112,35 @@ Changeset.assert = function assert(b, msgParts)
|
|||
}
|
||||
};
|
||||
|
||||
Changeset.parseNum = function (str)
|
||||
Changeset.parseNum = function(str)
|
||||
{
|
||||
return parseInt(str, 36);
|
||||
};
|
||||
Changeset.numToString = function (num)
|
||||
Changeset.numToString = function(num)
|
||||
{
|
||||
return num.toString(36).toLowerCase();
|
||||
};
|
||||
Changeset.toBaseTen = function (cs)
|
||||
Changeset.toBaseTen = function(cs)
|
||||
{
|
||||
var dollarIndex = cs.indexOf('$');
|
||||
var beforeDollar = cs.substring(0, dollarIndex);
|
||||
var fromDollar = cs.substring(dollarIndex);
|
||||
return beforeDollar.replace(/[0-9a-z]+/g, function (s)
|
||||
return beforeDollar.replace(/[0-9a-z]+/g, function(s)
|
||||
{
|
||||
return String(Changeset.parseNum(s));
|
||||
}) + fromDollar;
|
||||
};
|
||||
|
||||
Changeset.oldLen = function (cs)
|
||||
Changeset.oldLen = function(cs)
|
||||
{
|
||||
return Changeset.unpack(cs).oldLen;
|
||||
};
|
||||
Changeset.newLen = function (cs)
|
||||
Changeset.newLen = function(cs)
|
||||
{
|
||||
return Changeset.unpack(cs).newLen;
|
||||
};
|
||||
|
||||
Changeset.opIterator = function (opsStr, optStartIndex)
|
||||
Changeset.opIterator = function(opsStr, optStartIndex)
|
||||
{
|
||||
//print(opsStr);
|
||||
var regex = /((?:\*[0-9a-z]+)*)(?:\|([0-9a-z]+))?([-+=])([0-9a-z]+)|\?|/g;
|
||||
|
@ -221,14 +221,14 @@ Changeset.opIterator = function (opsStr, optStartIndex)
|
|||
};
|
||||
};
|
||||
|
||||
Changeset.clearOp = function (op)
|
||||
Changeset.clearOp = function(op)
|
||||
{
|
||||
op.opcode = '';
|
||||
op.chars = 0;
|
||||
op.lines = 0;
|
||||
op.attribs = '';
|
||||
};
|
||||
Changeset.newOp = function (optOpcode)
|
||||
Changeset.newOp = function(optOpcode)
|
||||
{
|
||||
return {
|
||||
opcode: (optOpcode || ''),
|
||||
|
@ -237,7 +237,7 @@ Changeset.newOp = function (optOpcode)
|
|||
attribs: ''
|
||||
};
|
||||
};
|
||||
Changeset.cloneOp = function (op)
|
||||
Changeset.cloneOp = function(op)
|
||||
{
|
||||
return {
|
||||
opcode: op.opcode,
|
||||
|
@ -246,14 +246,14 @@ Changeset.cloneOp = function (op)
|
|||
attribs: op.attribs
|
||||
};
|
||||
};
|
||||
Changeset.copyOp = function (op1, op2)
|
||||
Changeset.copyOp = function(op1, op2)
|
||||
{
|
||||
op2.opcode = op1.opcode;
|
||||
op2.chars = op1.chars;
|
||||
op2.lines = op1.lines;
|
||||
op2.attribs = op1.attribs;
|
||||
};
|
||||
Changeset.opString = function (op)
|
||||
Changeset.opString = function(op)
|
||||
{
|
||||
// just for debugging
|
||||
if (!op.opcode) return 'null';
|
||||
|
@ -261,13 +261,13 @@ Changeset.opString = function (op)
|
|||
assem.append(op);
|
||||
return assem.toString();
|
||||
};
|
||||
Changeset.stringOp = function (str)
|
||||
Changeset.stringOp = function(str)
|
||||
{
|
||||
// just for debugging
|
||||
return Changeset.opIterator(str).next();
|
||||
};
|
||||
|
||||
Changeset.checkRep = function (cs)
|
||||
Changeset.checkRep = function(cs)
|
||||
{
|
||||
// doesn't check things that require access to attrib pool (e.g. attribute order)
|
||||
// or original string (e.g. newline positions)
|
||||
|
@ -320,7 +320,7 @@ Changeset.checkRep = function (cs)
|
|||
return cs;
|
||||
}
|
||||
|
||||
Changeset.smartOpAssembler = function ()
|
||||
Changeset.smartOpAssembler = function()
|
||||
{
|
||||
// Like opAssembler but able to produce conforming changesets
|
||||
// from slightly looser input, at the cost of speed.
|
||||
|
@ -444,7 +444,7 @@ Changeset.smartOpAssembler = function ()
|
|||
|
||||
if (_opt)
|
||||
{
|
||||
Changeset.mergingOpAssembler = function ()
|
||||
Changeset.mergingOpAssembler = function()
|
||||
{
|
||||
var assem = _opt.mergingOpAssembler();
|
||||
|
||||
|
@ -478,7 +478,7 @@ if (_opt)
|
|||
}
|
||||
else
|
||||
{
|
||||
Changeset.mergingOpAssembler = function ()
|
||||
Changeset.mergingOpAssembler = function()
|
||||
{
|
||||
// This assembler can be used in production; it efficiently
|
||||
// merges consecutive operations that are mergeable, ignores
|
||||
|
@ -575,12 +575,11 @@ else
|
|||
|
||||
if (_opt)
|
||||
{
|
||||
Changeset.opAssembler = function ()
|
||||
Changeset.opAssembler = function()
|
||||
{
|
||||
var assem = _opt.opAssembler();
|
||||
// this function allows op to be mutated later (doesn't keep a ref)
|
||||
|
||||
|
||||
function append(op)
|
||||
{
|
||||
assem.append(op.opcode, op.chars, op.lines, op.attribs);
|
||||
|
@ -604,12 +603,11 @@ if (_opt)
|
|||
}
|
||||
else
|
||||
{
|
||||
Changeset.opAssembler = function ()
|
||||
Changeset.opAssembler = function()
|
||||
{
|
||||
var pieces = [];
|
||||
// this function allows op to be mutated later (doesn't keep a ref)
|
||||
|
||||
|
||||
function append(op)
|
||||
{
|
||||
pieces.push(op.attribs);
|
||||
|
@ -638,7 +636,7 @@ else
|
|||
};
|
||||
}
|
||||
|
||||
Changeset.stringIterator = function (str)
|
||||
Changeset.stringIterator = function(str)
|
||||
{
|
||||
var curIndex = 0;
|
||||
|
||||
|
@ -680,7 +678,7 @@ Changeset.stringIterator = function (str)
|
|||
};
|
||||
};
|
||||
|
||||
Changeset.stringAssembler = function ()
|
||||
Changeset.stringAssembler = function()
|
||||
{
|
||||
var pieces = [];
|
||||
|
||||
|
@ -700,7 +698,7 @@ Changeset.stringAssembler = function ()
|
|||
};
|
||||
|
||||
// "lines" need not be an array as long as it supports certain calls (lines_foo inside).
|
||||
Changeset.textLinesMutator = function (lines)
|
||||
Changeset.textLinesMutator = function(lines)
|
||||
{
|
||||
// Mutates lines, an array of strings, in place.
|
||||
// Mutation operations have the same constraints as changeset operations
|
||||
|
@ -743,7 +741,6 @@ Changeset.textLinesMutator = function (lines)
|
|||
}
|
||||
// can be unimplemented if removeLines's return value not needed
|
||||
|
||||
|
||||
function lines_slice(start, end)
|
||||
{
|
||||
if (lines.slice)
|
||||
|
@ -1024,7 +1021,7 @@ Changeset.textLinesMutator = function (lines)
|
|||
return self;
|
||||
};
|
||||
|
||||
Changeset.applyZip = function (in1, idx1, in2, idx2, func)
|
||||
Changeset.applyZip = function(in1, idx1, in2, idx2, func)
|
||||
{
|
||||
var iter1 = Changeset.opIterator(in1, idx1);
|
||||
var iter2 = Changeset.opIterator(in2, idx2);
|
||||
|
@ -1048,7 +1045,7 @@ Changeset.applyZip = function (in1, idx1, in2, idx2, func)
|
|||
return assem.toString();
|
||||
};
|
||||
|
||||
Changeset.unpack = function (cs)
|
||||
Changeset.unpack = function(cs)
|
||||
{
|
||||
var headerRegex = /Z:([0-9a-z]+)([><])([0-9a-z]+)|/;
|
||||
var headerMatch = headerRegex.exec(cs);
|
||||
|
@ -1071,7 +1068,7 @@ Changeset.unpack = function (cs)
|
|||
};
|
||||
};
|
||||
|
||||
Changeset.pack = function (oldLen, newLen, opsStr, bank)
|
||||
Changeset.pack = function(oldLen, newLen, opsStr, bank)
|
||||
{
|
||||
var lenDiff = newLen - oldLen;
|
||||
var lenDiffStr = (lenDiff >= 0 ? '>' + Changeset.numToString(lenDiff) : '<' + Changeset.numToString(-lenDiff));
|
||||
|
@ -1080,7 +1077,7 @@ Changeset.pack = function (oldLen, newLen, opsStr, bank)
|
|||
return a.join('');
|
||||
};
|
||||
|
||||
Changeset.applyToText = function (cs, str)
|
||||
Changeset.applyToText = function(cs, str)
|
||||
{
|
||||
var unpacked = Changeset.unpack(cs);
|
||||
Changeset.assert(str.length == unpacked.oldLen, "mismatched apply: ", str.length, " / ", unpacked.oldLen);
|
||||
|
@ -1108,7 +1105,7 @@ Changeset.applyToText = function (cs, str)
|
|||
return assem.toString();
|
||||
};
|
||||
|
||||
Changeset.mutateTextLines = function (cs, lines)
|
||||
Changeset.mutateTextLines = function(cs, lines)
|
||||
{
|
||||
var unpacked = Changeset.unpack(cs);
|
||||
var csIter = Changeset.opIterator(unpacked.ops);
|
||||
|
@ -1133,7 +1130,7 @@ Changeset.mutateTextLines = function (cs, lines)
|
|||
mut.close();
|
||||
};
|
||||
|
||||
Changeset.composeAttributes = function (att1, att2, resultIsMutation, pool)
|
||||
Changeset.composeAttributes = function(att1, att2, resultIsMutation, pool)
|
||||
{
|
||||
// att1 and att2 are strings like "*3*f*1c", asMutation is a boolean.
|
||||
// Sometimes attribute (key,value) pairs are treated as attribute presence
|
||||
|
@ -1158,12 +1155,12 @@ Changeset.composeAttributes = function (att1, att2, resultIsMutation, pool)
|
|||
}
|
||||
if (!att2) return att1;
|
||||
var atts = [];
|
||||
att1.replace(/\*([0-9a-z]+)/g, function (_, a)
|
||||
att1.replace(/\*([0-9a-z]+)/g, function(_, a)
|
||||
{
|
||||
atts.push(pool.getAttrib(Changeset.parseNum(a)));
|
||||
return '';
|
||||
});
|
||||
att2.replace(/\*([0-9a-z]+)/g, function (_, a)
|
||||
att2.replace(/\*([0-9a-z]+)/g, function(_, a)
|
||||
{
|
||||
var pair = pool.getAttrib(Changeset.parseNum(a));
|
||||
var found = false;
|
||||
|
@ -1201,7 +1198,7 @@ Changeset.composeAttributes = function (att1, att2, resultIsMutation, pool)
|
|||
return buf.toString();
|
||||
};
|
||||
|
||||
Changeset._slicerZipperFunc = function (attOp, csOp, opOut, pool)
|
||||
Changeset._slicerZipperFunc = function(attOp, csOp, opOut, pool)
|
||||
{
|
||||
// attOp is the op from the sequence that is being operated on, either an
|
||||
// attribution string or the earlier of two changesets being composed.
|
||||
|
@ -1304,11 +1301,11 @@ Changeset._slicerZipperFunc = function (attOp, csOp, opOut, pool)
|
|||
}
|
||||
};
|
||||
|
||||
Changeset.applyToAttribution = function (cs, astr, pool)
|
||||
Changeset.applyToAttribution = function(cs, astr, pool)
|
||||
{
|
||||
var unpacked = Changeset.unpack(cs);
|
||||
|
||||
return Changeset.applyZip(astr, 0, unpacked.ops, 0, function (op1, op2, opOut)
|
||||
return Changeset.applyZip(astr, 0, unpacked.ops, 0, function(op1, op2, opOut)
|
||||
{
|
||||
return Changeset._slicerZipperFunc(op1, op2, opOut, pool);
|
||||
});
|
||||
|
@ -1320,7 +1317,7 @@ Changeset.applyToAttribution = function (cs, astr, pool)
|
|||
|
||||
};*/
|
||||
|
||||
Changeset.mutateAttributionLines = function (cs, lines, pool)
|
||||
Changeset.mutateAttributionLines = function(cs, lines, pool)
|
||||
{
|
||||
//dmesg(cs);
|
||||
//dmesg(lines.toSource()+" ->");
|
||||
|
@ -1438,7 +1435,7 @@ Changeset.mutateAttributionLines = function (cs, lines, pool)
|
|||
//dmesg("-> "+lines.toSource());
|
||||
};
|
||||
|
||||
Changeset.joinAttributionLines = function (theAlines)
|
||||
Changeset.joinAttributionLines = function(theAlines)
|
||||
{
|
||||
var assem = Changeset.mergingOpAssembler();
|
||||
for (var i = 0; i < theAlines.length; i++)
|
||||
|
@ -1453,7 +1450,7 @@ Changeset.joinAttributionLines = function (theAlines)
|
|||
return assem.toString();
|
||||
};
|
||||
|
||||
Changeset.splitAttributionLines = function (attrOps, text)
|
||||
Changeset.splitAttributionLines = function(attrOps, text)
|
||||
{
|
||||
var iter = Changeset.opIterator(attrOps);
|
||||
var assem = Changeset.mergingOpAssembler();
|
||||
|
@ -1497,12 +1494,12 @@ Changeset.splitAttributionLines = function (attrOps, text)
|
|||
return lines;
|
||||
};
|
||||
|
||||
Changeset.splitTextLines = function (text)
|
||||
Changeset.splitTextLines = function(text)
|
||||
{
|
||||
return text.match(/[^\n]*(?:\n|[^\n]$)/g);
|
||||
};
|
||||
|
||||
Changeset.compose = function (cs1, cs2, pool)
|
||||
Changeset.compose = function(cs1, cs2, pool)
|
||||
{
|
||||
var unpacked1 = Changeset.unpack(cs1);
|
||||
var unpacked2 = Changeset.unpack(cs2);
|
||||
|
@ -1514,7 +1511,7 @@ Changeset.compose = function (cs1, cs2, pool)
|
|||
var bankIter2 = Changeset.stringIterator(unpacked2.charBank);
|
||||
var bankAssem = Changeset.stringAssembler();
|
||||
|
||||
var newOps = Changeset.applyZip(unpacked1.ops, 0, unpacked2.ops, 0, function (op1, op2, opOut)
|
||||
var newOps = Changeset.applyZip(unpacked1.ops, 0, unpacked2.ops, 0, function(op1, op2, opOut)
|
||||
{
|
||||
//var debugBuilder = Changeset.stringAssembler();
|
||||
//debugBuilder.append(Changeset.opString(op1));
|
||||
|
@ -1551,7 +1548,7 @@ Changeset.compose = function (cs1, cs2, pool)
|
|||
return Changeset.pack(len1, len3, newOps, bankAssem.toString());
|
||||
};
|
||||
|
||||
Changeset.attributeTester = function (attribPair, pool)
|
||||
Changeset.attributeTester = function(attribPair, pool)
|
||||
{
|
||||
// returns a function that tests if a string of attributes
|
||||
// (e.g. *3*4) contains a given attribute key,value that
|
||||
|
@ -1568,7 +1565,7 @@ Changeset.attributeTester = function (attribPair, pool)
|
|||
else
|
||||
{
|
||||
var re = new RegExp('\\*' + Changeset.numToString(attribNum) + '(?!\\w)');
|
||||
return function (attribs)
|
||||
return function(attribs)
|
||||
{
|
||||
return re.test(attribs);
|
||||
};
|
||||
|
@ -1580,12 +1577,12 @@ Changeset.attributeTester = function (attribPair, pool)
|
|||
}
|
||||
};
|
||||
|
||||
Changeset.identity = function (N)
|
||||
Changeset.identity = function(N)
|
||||
{
|
||||
return Changeset.pack(N, N, "", "");
|
||||
};
|
||||
|
||||
Changeset.makeSplice = function (oldFullText, spliceStart, numRemoved, newText, optNewTextAPairs, pool)
|
||||
Changeset.makeSplice = function(oldFullText, spliceStart, numRemoved, newText, optNewTextAPairs, pool)
|
||||
{
|
||||
var oldLen = oldFullText.length;
|
||||
|
||||
|
@ -1608,7 +1605,7 @@ Changeset.makeSplice = function (oldFullText, spliceStart, numRemoved, newText,
|
|||
return Changeset.pack(oldLen, newLen, assem.toString(), newText);
|
||||
};
|
||||
|
||||
Changeset.toSplices = function (cs)
|
||||
Changeset.toSplices = function(cs)
|
||||
{
|
||||
// get a list of splices, [startChar, endChar, newText]
|
||||
var unpacked = Changeset.unpack(cs);
|
||||
|
@ -1648,7 +1645,7 @@ Changeset.toSplices = function (cs)
|
|||
return splices;
|
||||
};
|
||||
|
||||
Changeset.characterRangeFollow = function (cs, startChar, endChar, insertionsAfter)
|
||||
Changeset.characterRangeFollow = function(cs, startChar, endChar, insertionsAfter)
|
||||
{
|
||||
var newStartChar = startChar;
|
||||
var newEndChar = endChar;
|
||||
|
@ -1708,7 +1705,7 @@ Changeset.characterRangeFollow = function (cs, startChar, endChar, insertionsAft
|
|||
return [newStartChar, newEndChar];
|
||||
};
|
||||
|
||||
Changeset.moveOpsToNewPool = function (cs, oldPool, newPool)
|
||||
Changeset.moveOpsToNewPool = function(cs, oldPool, newPool)
|
||||
{
|
||||
// works on changeset or attribution string
|
||||
var dollarPos = cs.indexOf('$');
|
||||
|
@ -1719,7 +1716,7 @@ Changeset.moveOpsToNewPool = function (cs, oldPool, newPool)
|
|||
var upToDollar = cs.substring(0, dollarPos);
|
||||
var fromDollar = cs.substring(dollarPos);
|
||||
// order of attribs stays the same
|
||||
return upToDollar.replace(/\*([0-9a-z]+)/g, function (_, a)
|
||||
return upToDollar.replace(/\*([0-9a-z]+)/g, function(_, a)
|
||||
{
|
||||
var oldNum = Changeset.parseNum(a);
|
||||
var pair = oldPool.getAttrib(oldNum);
|
||||
|
@ -1728,7 +1725,7 @@ Changeset.moveOpsToNewPool = function (cs, oldPool, newPool)
|
|||
}) + fromDollar;
|
||||
};
|
||||
|
||||
Changeset.makeAttribution = function (text)
|
||||
Changeset.makeAttribution = function(text)
|
||||
{
|
||||
var assem = Changeset.smartOpAssembler();
|
||||
assem.appendOpWithText('+', text);
|
||||
|
@ -1736,7 +1733,7 @@ Changeset.makeAttribution = function (text)
|
|||
};
|
||||
|
||||
// callable on a changeset, attribution string, or attribs property of an op
|
||||
Changeset.eachAttribNumber = function (cs, func)
|
||||
Changeset.eachAttribNumber = function(cs, func)
|
||||
{
|
||||
var dollarPos = cs.indexOf('$');
|
||||
if (dollarPos < 0)
|
||||
|
@ -1745,7 +1742,7 @@ Changeset.eachAttribNumber = function (cs, func)
|
|||
}
|
||||
var upToDollar = cs.substring(0, dollarPos);
|
||||
|
||||
upToDollar.replace(/\*([0-9a-z]+)/g, function (_, a)
|
||||
upToDollar.replace(/\*([0-9a-z]+)/g, function(_, a)
|
||||
{
|
||||
func(Changeset.parseNum(a));
|
||||
return '';
|
||||
|
@ -1754,12 +1751,12 @@ Changeset.eachAttribNumber = function (cs, func)
|
|||
|
||||
// callable on a changeset, attribution string, or attribs property of an op,
|
||||
// though it may easily create adjacent ops that can be merged.
|
||||
Changeset.filterAttribNumbers = function (cs, filter)
|
||||
Changeset.filterAttribNumbers = function(cs, filter)
|
||||
{
|
||||
return Changeset.mapAttribNumbers(cs, filter);
|
||||
};
|
||||
|
||||
Changeset.mapAttribNumbers = function (cs, func)
|
||||
Changeset.mapAttribNumbers = function(cs, func)
|
||||
{
|
||||
var dollarPos = cs.indexOf('$');
|
||||
if (dollarPos < 0)
|
||||
|
@ -1768,7 +1765,7 @@ Changeset.mapAttribNumbers = function (cs, func)
|
|||
}
|
||||
var upToDollar = cs.substring(0, dollarPos);
|
||||
|
||||
var newUpToDollar = upToDollar.replace(/\*([0-9a-z]+)/g, function (s, a)
|
||||
var newUpToDollar = upToDollar.replace(/\*([0-9a-z]+)/g, function(s, a)
|
||||
{
|
||||
var n = func(Changeset.parseNum(a));
|
||||
if (n === true)
|
||||
|
@ -1788,7 +1785,7 @@ Changeset.mapAttribNumbers = function (cs, func)
|
|||
return newUpToDollar + cs.substring(dollarPos);
|
||||
};
|
||||
|
||||
Changeset.makeAText = function (text, attribs)
|
||||
Changeset.makeAText = function(text, attribs)
|
||||
{
|
||||
return {
|
||||
text: text,
|
||||
|
@ -1796,7 +1793,7 @@ Changeset.makeAText = function (text, attribs)
|
|||
};
|
||||
};
|
||||
|
||||
Changeset.applyToAText = function (cs, atext, pool)
|
||||
Changeset.applyToAText = function(cs, atext, pool)
|
||||
{
|
||||
return {
|
||||
text: Changeset.applyToText(cs, atext.text),
|
||||
|
@ -1804,7 +1801,7 @@ Changeset.applyToAText = function (cs, atext, pool)
|
|||
};
|
||||
};
|
||||
|
||||
Changeset.cloneAText = function (atext)
|
||||
Changeset.cloneAText = function(atext)
|
||||
{
|
||||
return {
|
||||
text: atext.text,
|
||||
|
@ -1812,13 +1809,13 @@ Changeset.cloneAText = function (atext)
|
|||
};
|
||||
};
|
||||
|
||||
Changeset.copyAText = function (atext1, atext2)
|
||||
Changeset.copyAText = function(atext1, atext2)
|
||||
{
|
||||
atext2.text = atext1.text;
|
||||
atext2.attribs = atext1.attribs;
|
||||
};
|
||||
|
||||
Changeset.appendATextToAssembler = function (atext, assem)
|
||||
Changeset.appendATextToAssembler = function(atext, assem)
|
||||
{
|
||||
// intentionally skips last newline char of atext
|
||||
var iter = Changeset.opIterator(atext.attribs);
|
||||
|
@ -1860,7 +1857,7 @@ Changeset.appendATextToAssembler = function (atext, assem)
|
|||
}
|
||||
};
|
||||
|
||||
Changeset.prepareForWire = function (cs, pool)
|
||||
Changeset.prepareForWire = function(cs, pool)
|
||||
{
|
||||
var newPool = new AttribPool();
|
||||
var newCs = Changeset.moveOpsToNewPool(cs, pool, newPool);
|
||||
|
@ -1870,23 +1867,23 @@ Changeset.prepareForWire = function (cs, pool)
|
|||
};
|
||||
};
|
||||
|
||||
Changeset.isIdentity = function (cs)
|
||||
Changeset.isIdentity = function(cs)
|
||||
{
|
||||
var unpacked = Changeset.unpack(cs);
|
||||
return unpacked.ops == "" && unpacked.oldLen == unpacked.newLen;
|
||||
};
|
||||
|
||||
Changeset.opAttributeValue = function (op, key, pool)
|
||||
Changeset.opAttributeValue = function(op, key, pool)
|
||||
{
|
||||
return Changeset.attribsAttributeValue(op.attribs, key, pool);
|
||||
};
|
||||
|
||||
Changeset.attribsAttributeValue = function (attribs, key, pool)
|
||||
Changeset.attribsAttributeValue = function(attribs, key, pool)
|
||||
{
|
||||
var value = '';
|
||||
if (attribs)
|
||||
{
|
||||
Changeset.eachAttribNumber(attribs, function (n)
|
||||
Changeset.eachAttribNumber(attribs, function(n)
|
||||
{
|
||||
if (pool.getAttribKey(n) == key)
|
||||
{
|
||||
|
@ -1897,7 +1894,7 @@ Changeset.attribsAttributeValue = function (attribs, key, pool)
|
|||
return value;
|
||||
};
|
||||
|
||||
Changeset.builder = function (oldLen)
|
||||
Changeset.builder = function(oldLen)
|
||||
{
|
||||
var assem = Changeset.smartOpAssembler();
|
||||
var o = Changeset.newOp();
|
||||
|
@ -1905,7 +1902,7 @@ Changeset.builder = function (oldLen)
|
|||
|
||||
var self = {
|
||||
// attribs are [[key1,value1],[key2,value2],...] or '*0*1...' (no pool needed in latter case)
|
||||
keep: function (N, L, attribs, pool)
|
||||
keep: function(N, L, attribs, pool)
|
||||
{
|
||||
o.opcode = '=';
|
||||
o.attribs = (attribs && Changeset.makeAttribsString('=', attribs, pool)) || '';
|
||||
|
@ -1914,18 +1911,18 @@ Changeset.builder = function (oldLen)
|
|||
assem.append(o);
|
||||
return self;
|
||||
},
|
||||
keepText: function (text, attribs, pool)
|
||||
keepText: function(text, attribs, pool)
|
||||
{
|
||||
assem.appendOpWithText('=', text, attribs, pool);
|
||||
return self;
|
||||
},
|
||||
insert: function (text, attribs, pool)
|
||||
insert: function(text, attribs, pool)
|
||||
{
|
||||
assem.appendOpWithText('+', text, attribs, pool);
|
||||
charBank.append(text);
|
||||
return self;
|
||||
},
|
||||
remove: function (N, L)
|
||||
remove: function(N, L)
|
||||
{
|
||||
o.opcode = '-';
|
||||
o.attribs = '';
|
||||
|
@ -1934,7 +1931,7 @@ Changeset.builder = function (oldLen)
|
|||
assem.append(o);
|
||||
return self;
|
||||
},
|
||||
toString: function ()
|
||||
toString: function()
|
||||
{
|
||||
assem.endDocument();
|
||||
var newLen = oldLen + assem.getLengthChange();
|
||||
|
@ -1945,7 +1942,7 @@ Changeset.builder = function (oldLen)
|
|||
return self;
|
||||
};
|
||||
|
||||
Changeset.makeAttribsString = function (opcode, attribs, pool)
|
||||
Changeset.makeAttribsString = function(opcode, attribs, pool)
|
||||
{
|
||||
// makeAttribsString(opcode, '*3') or makeAttribsString(opcode, [['foo','bar']], myPool) work
|
||||
if (!attribs)
|
||||
|
@ -1977,7 +1974,7 @@ Changeset.makeAttribsString = function (opcode, attribs, pool)
|
|||
};
|
||||
|
||||
// like "substring" but on a single-line attribution string
|
||||
Changeset.subattribution = function (astr, start, optEnd)
|
||||
Changeset.subattribution = function(astr, start, optEnd)
|
||||
{
|
||||
var iter = Changeset.opIterator(astr, 0);
|
||||
var assem = Changeset.smartOpAssembler();
|
||||
|
@ -2035,13 +2032,12 @@ Changeset.subattribution = function (astr, start, optEnd)
|
|||
return assem.toString();
|
||||
};
|
||||
|
||||
Changeset.inverse = function (cs, lines, alines, pool)
|
||||
Changeset.inverse = function(cs, lines, alines, pool)
|
||||
{
|
||||
// lines and alines are what the changeset is meant to apply to.
|
||||
// They may be arrays or objects with .get(i) and .length methods.
|
||||
// They include final newlines on lines.
|
||||
|
||||
|
||||
function lines_get(idx)
|
||||
{
|
||||
if (lines.get)
|
||||
|
@ -2164,7 +2160,7 @@ Changeset.inverse = function (cs, lines, alines, pool)
|
|||
{
|
||||
if (curLineOpIter && curLineOpIterLine == curLine)
|
||||
{
|
||||
consumeAttribRuns(N, function ()
|
||||
consumeAttribRuns(N, function()
|
||||
{});
|
||||
}
|
||||
else
|
||||
|
@ -2197,7 +2193,7 @@ Changeset.inverse = function (cs, lines, alines, pool)
|
|||
function cachedStrFunc(func)
|
||||
{
|
||||
var cache = {};
|
||||
return function (s)
|
||||
return function(s)
|
||||
{
|
||||
if (!cache[s])
|
||||
{
|
||||
|
@ -2218,12 +2214,12 @@ Changeset.inverse = function (cs, lines, alines, pool)
|
|||
{
|
||||
attribKeys.length = 0;
|
||||
attribValues.length = 0;
|
||||
Changeset.eachAttribNumber(csOp.attribs, function (n)
|
||||
Changeset.eachAttribNumber(csOp.attribs, function(n)
|
||||
{
|
||||
attribKeys.push(pool.getAttribKey(n));
|
||||
attribValues.push(pool.getAttribValue(n));
|
||||
});
|
||||
var undoBackToAttribs = cachedStrFunc(function (attribs)
|
||||
var undoBackToAttribs = cachedStrFunc(function(attribs)
|
||||
{
|
||||
var backAttribs = [];
|
||||
for (var i = 0; i < attribKeys.length; i++)
|
||||
|
@ -2238,7 +2234,7 @@ Changeset.inverse = function (cs, lines, alines, pool)
|
|||
}
|
||||
return Changeset.makeAttribsString('=', backAttribs, pool);
|
||||
});
|
||||
consumeAttribRuns(csOp.chars, function (len, attribs, endsLine)
|
||||
consumeAttribRuns(csOp.chars, function(len, attribs, endsLine)
|
||||
{
|
||||
builder.keep(len, endsLine ? 1 : 0, undoBackToAttribs(attribs));
|
||||
});
|
||||
|
@ -2257,7 +2253,7 @@ Changeset.inverse = function (cs, lines, alines, pool)
|
|||
{
|
||||
var textBank = nextText(csOp.chars);
|
||||
var textBankIndex = 0;
|
||||
consumeAttribRuns(csOp.chars, function (len, attribs, endsLine)
|
||||
consumeAttribRuns(csOp.chars, function(len, attribs, endsLine)
|
||||
{
|
||||
builder.insert(textBank.substr(textBankIndex, len), attribs);
|
||||
textBankIndex += len;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue