MCPcopy Index your code
hub / github.com/ronreiter/interactive-tutorials / markText

Function markText

static/js/codemirror/codemirror.js:3458–3509  ·  view source on GitHub ↗
(doc, from, to, options, type)

Source from the content-addressed store, hash-verified

3456 };
3457
3458 function markText(doc, from, to, options, type) {
3459 if (options && options.shared) return markTextShared(doc, from, to, options, type);
3460 if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type);
3461
3462 var marker = new TextMarker(doc, type);
3463 if (type == "range" && !posLess(from, to)) return marker;
3464 if (options) copyObj(options, marker);
3465 if (marker.replacedWith) {
3466 marker.collapsed = true;
3467 marker.replacedWith = elt("span", [marker.replacedWith], "CodeMirror-widget");
3468 }
3469 if (marker.collapsed) sawCollapsedSpans = true;
3470
3471 var curLine = from.line, size = 0, collapsedAtStart, collapsedAtEnd, cm = doc.cm, updateMaxLine;
3472 doc.iter(curLine, to.line + 1, function(line) {
3473 if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(doc, line) == cm.display.maxLine)
3474 updateMaxLine = true;
3475 var span = {from: null, to: null, marker: marker};
3476 size += line.text.length;
3477 if (curLine == from.line) {span.from = from.ch; size -= from.ch;}
3478 if (curLine == to.line) {span.to = to.ch; size -= line.text.length - to.ch;}
3479 if (marker.collapsed) {
3480 if (curLine == to.line) collapsedAtEnd = collapsedSpanAt(line, to.ch);
3481 if (curLine == from.line) collapsedAtStart = collapsedSpanAt(line, from.ch);
3482 else updateLineHeight(line, 0);
3483 }
3484 addMarkedSpan(line, span);
3485 ++curLine;
3486 });
3487 if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
3488 if (lineIsHidden(doc, line)) updateLineHeight(line, 0);
3489 });
3490
3491 if (marker.readOnly) {
3492 sawReadOnlySpans = true;
3493 if (doc.history.done.length || doc.history.undone.length)
3494 doc.clearHistory();
3495 }
3496 if (marker.collapsed) {
3497 if (collapsedAtStart != collapsedAtEnd)
3498 throw new Error("Inserting collapsed marker overlapping an existing one");
3499 marker.size = size;
3500 marker.atomic = true;
3501 }
3502 if (cm) {
3503 if (updateMaxLine) cm.curOp.updateMaxLine = true;
3504 if (marker.className || marker.startStyle || marker.endStyle || marker.collapsed)
3505 regChange(cm, from.line, to.line + 1);
3506 if (marker.atomic) reCheckSelection(cm);
3507 }
3508 return marker;
3509 }
3510
3511 // SHARED TEXTMARKERS
3512

Callers 2

markTextSharedFunction · 0.85
codemirror.jsFile · 0.85

Calls 12

markTextSharedFunction · 0.85
operationFunction · 0.85
posLessFunction · 0.85
copyObjFunction · 0.85
eltFunction · 0.85
visualLineFunction · 0.85
collapsedSpanAtFunction · 0.85
updateLineHeightFunction · 0.85
addMarkedSpanFunction · 0.85
lineIsHiddenFunction · 0.85
regChangeFunction · 0.85
reCheckSelectionFunction · 0.85

Tested by

no test coverage detected