MCPcopy
hub / github.com/ether/etherpad / _createDeletionChangeset

Method _createDeletionChangeset

src/node/utils/padDiff.ts:239–453  ·  view source on GitHub ↗
(cs: any, startAText: any, apool: any)

Source from the content-addressed store, hash-verified

237 return pack(unpacked.oldLen, unpacked.newLen, assem.toString(), unpacked.charBank);
238 }
239 _createDeletionChangeset(cs: any, startAText: any, apool: any){
240 const lines = splitTextLines(startAText.text);
241 const alines = splitAttributionLines(startAText.attribs, startAText.text);
242
243 // lines and alines are what the exports is meant to apply to.
244 // They may be arrays or objects with .get(i) and .length methods.
245 // They include final newlines on lines.
246
247 const linesGet = (idx: number) => {
248 // @ts-ignore
249 if (lines.get) {
250 // @ts-ignore
251 return lines.get(idx);
252 } else {
253 // @ts-ignore
254 return lines[idx];
255 }
256 };
257
258 const aLinesGet = (idx: number) => {
259 // @ts-ignore
260 if (alines.get) {
261 // @ts-ignore
262 return alines.get(idx);
263 } else {
264 return alines[idx];
265 }
266 };
267
268 let curLine = 0;
269 let curChar = 0;
270 let curLineOps: { next: () => any; } | null = null;
271 let curLineOpsNext: { done: any; value: any; } | null = null;
272 let curLineOpsLine: number;
273 let curLineNextOp = new Op('+');
274
275 const unpacked = unpack(cs);
276 const builder = new Builder(unpacked.newLen);
277
278 const consumeAttribRuns = (numChars: number, func: Function /* (len, attribs, endsLine)*/) => {
279 if (!curLineOps || curLineOpsLine !== curLine) {
280 curLineOps = deserializeOps(aLinesGet(curLine));
281 curLineOpsNext = curLineOps!.next();
282 curLineOpsLine = curLine;
283 let indexIntoLine = 0;
284 while (!curLineOpsNext!.done) {
285 curLineNextOp = curLineOpsNext!.value;
286 curLineOpsNext = curLineOps!.next();
287 if (indexIntoLine + curLineNextOp.chars >= curChar) {
288 curLineNextOp.chars -= (curChar - indexIntoLine);
289 break;
290 }
291 indexIntoLine += curLineNextOp.chars;
292 }
293 }
294
295 while (numChars > 0) {
296 if (!curLineNextOp.chars && curLineOpsNext!.done) {

Callers 1

_createDiffAtextMethod · 0.95

Calls 13

splitTextLinesFunction · 0.90
splitAttributionLinesFunction · 0.90
unpackFunction · 0.90
checkRepFunction · 0.90
nextTextFunction · 0.85
consumeAttribRunsFunction · 0.85
skipFunction · 0.85
fromStringMethod · 0.80
setMethod · 0.80
getMethod · 0.80
cachedStrFuncFunction · 0.50
toStringMethod · 0.45

Tested by

no test coverage detected