MCPcopy Create free account
hub / github.com/TruthHun/BookStack / makeChangeSingleDocInEditor

Function makeChangeSingleDocInEditor

static/mergely/lib/codemirror.js:4513–4570  ·  view source on GitHub ↗
(cm, change, spans)

Source from the content-addressed store, hash-verified

4511 // Handle the interaction of a change to a document with the editor
4512 // that this document is part of.
4513 function makeChangeSingleDocInEditor(cm, change, spans) {
4514 var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
4515
4516 var recomputeMaxLength = false, checkWidthStart = from.line;
4517 if (!cm.options.lineWrapping) {
4518 checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
4519 doc.iter(checkWidthStart, to.line + 1, function(line) {
4520 if (line == display.maxLine) {
4521 recomputeMaxLength = true;
4522 return true;
4523 }
4524 });
4525 }
4526
4527 if (doc.sel.contains(change.from, change.to) > -1)
4528 signalCursorActivity(cm);
4529
4530 updateDoc(doc, change, spans, estimateHeight(cm));
4531
4532 if (!cm.options.lineWrapping) {
4533 doc.iter(checkWidthStart, from.line + change.text.length, function(line) {
4534 var len = lineLength(line);
4535 if (len > display.maxLineLength) {
4536 display.maxLine = line;
4537 display.maxLineLength = len;
4538 display.maxLineChanged = true;
4539 recomputeMaxLength = false;
4540 }
4541 });
4542 if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
4543 }
4544
4545 // Adjust frontier, schedule worker
4546 doc.frontier = Math.min(doc.frontier, from.line);
4547 startWorker(cm, 400);
4548
4549 var lendiff = change.text.length - (to.line - from.line) - 1;
4550 // Remember that these lines changed, for updating the display
4551 if (change.full)
4552 regChange(cm);
4553 else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
4554 regLineChange(cm, from.line, "text");
4555 else
4556 regChange(cm, from.line, to.line + 1, lendiff);
4557
4558 var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
4559 if (changeHandler || changesHandler) {
4560 var obj = {
4561 from: from, to: to,
4562 text: change.text,
4563 removed: change.removed,
4564 origin: change.origin
4565 };
4566 if (changeHandler) signalLater(cm, "change", cm, obj);
4567 if (changesHandler) (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
4568 }
4569 cm.display.selForContextMenu = null;
4570 }

Callers 1

makeChangeSingleDocFunction · 0.70

Calls 13

lineNoFunction · 0.70
visualLineFunction · 0.70
getLineFunction · 0.70
signalCursorActivityFunction · 0.70
updateDocFunction · 0.70
estimateHeightFunction · 0.70
lineLengthFunction · 0.70
startWorkerFunction · 0.70
regChangeFunction · 0.70
isWholeLineUpdateFunction · 0.70
regLineChangeFunction · 0.70
hasHandlerFunction · 0.70

Tested by

no test coverage detected