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

Function markText

static/mergely/lib/codemirror.js:6167–6234  ·  view source on GitHub ↗
(doc, from, to, options, type)

Source from the content-addressed store, hash-verified

6165
6166 // Create a marker, wire it up to the right lines, and
6167 function markText(doc, from, to, options, type) {
6168 // Shared markers (across linked documents) are handled separately
6169 // (markTextShared will call out to this again, once per
6170 // document).
6171 if (options && options.shared) return markTextShared(doc, from, to, options, type);
6172 // Ensure we are in an operation.
6173 if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type);
6174
6175 var marker = new TextMarker(doc, type), diff = cmp(from, to);
6176 if (options) copyObj(options, marker, false);
6177 // Don't connect empty markers unless clearWhenEmpty is false
6178 if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
6179 return marker;
6180 if (marker.replacedWith) {
6181 // Showing up as a widget implies collapsed (widget replaces text)
6182 marker.collapsed = true;
6183 marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget");
6184 if (!options.handleMouseEvents) marker.widgetNode.setAttribute("cm-ignore-events", "true");
6185 if (options.insertLeft) marker.widgetNode.insertLeft = true;
6186 }
6187 if (marker.collapsed) {
6188 if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
6189 from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
6190 throw new Error("Inserting collapsed marker partially overlapping an existing one");
6191 sawCollapsedSpans = true;
6192 }
6193
6194 if (marker.addToHistory)
6195 addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN);
6196
6197 var curLine = from.line, cm = doc.cm, updateMaxLine;
6198 doc.iter(curLine, to.line + 1, function(line) {
6199 if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
6200 updateMaxLine = true;
6201 if (marker.collapsed && curLine != from.line) updateLineHeight(line, 0);
6202 addMarkedSpan(line, new MarkedSpan(marker,
6203 curLine == from.line ? from.ch : null,
6204 curLine == to.line ? to.ch : null));
6205 ++curLine;
6206 });
6207 // lineIsHidden depends on the presence of the spans, so needs a second pass
6208 if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
6209 if (lineIsHidden(doc, line)) updateLineHeight(line, 0);
6210 });
6211
6212 if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); });
6213
6214 if (marker.readOnly) {
6215 sawReadOnlySpans = true;
6216 if (doc.history.done.length || doc.history.undone.length)
6217 doc.clearHistory();
6218 }
6219 if (marker.collapsed) {
6220 marker.id = ++nextMarkerId;
6221 marker.atomic = true;
6222 }
6223 if (cm) {
6224 // Sync editor state

Callers 3

markTextSharedFunction · 0.70
copySharedMarkersFunction · 0.70
codemirror.jsFile · 0.70

Calls 15

markTextSharedFunction · 0.70
operationFunction · 0.70
copyObjFunction · 0.70
eltFunction · 0.70
addChangeToHistoryFunction · 0.70
visualLineFunction · 0.70
updateLineHeightFunction · 0.70
addMarkedSpanFunction · 0.70
lineIsHiddenFunction · 0.70
regChangeFunction · 0.70
regLineChangeFunction · 0.70

Tested by

no test coverage detected