MCPcopy Create free account
hub / github.com/feiyu563/PrometheusAlert / markText

Function markText

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

Source from the content-addressed store, hash-verified

5968
5969 // Create a marker, wire it up to the right lines, and
5970 function markText(doc, from, to, options, type) {
5971 // Shared markers (across linked documents) are handled separately
5972 // (markTextShared will call out to this again, once per
5973 // document).
5974 if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
5975 // Ensure we are in an operation.
5976 if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
5977
5978 var marker = new TextMarker(doc, type), diff = cmp(from, to);
5979 if (options) { copyObj(options, marker, false); }
5980 // Don't connect empty markers unless clearWhenEmpty is false
5981 if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
5982 { return marker }
5983 if (marker.replacedWith) {
5984 // Showing up as a widget implies collapsed (widget replaces text)
5985 marker.collapsed = true;
5986 marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget");
5987 if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true"); }
5988 if (options.insertLeft) { marker.widgetNode.insertLeft = true; }
5989 }
5990 if (marker.collapsed) {
5991 if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
5992 from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
5993 { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
5994 seeCollapsedSpans();
5995 }
5996
5997 if (marker.addToHistory)
5998 { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); }
5999
6000 var curLine = from.line, cm = doc.cm, updateMaxLine;
6001 doc.iter(curLine, to.line + 1, function (line) {
6002 if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
6003 { updateMaxLine = true; }
6004 if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0); }
6005 addMarkedSpan(line, new MarkedSpan(marker,
6006 curLine == from.line ? from.ch : null,
6007 curLine == to.line ? to.ch : null), doc.cm && doc.cm.curOp);
6008 ++curLine;
6009 });
6010 // lineIsHidden depends on the presence of the spans, so needs a second pass
6011 if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
6012 if (lineIsHidden(doc, line)) { updateLineHeight(line, 0); }
6013 }); }
6014
6015 if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }); }
6016
6017 if (marker.readOnly) {
6018 seeReadOnlySpans();
6019 if (doc.history.done.length || doc.history.undone.length)
6020 { doc.clearHistory(); }
6021 }
6022 if (marker.collapsed) {
6023 marker.id = ++nextMarkerId;
6024 marker.atomic = true;
6025 }
6026 if (cm) {
6027 // Sync editor state

Callers 3

markTextSharedFunction · 0.85
copySharedMarkersFunction · 0.85
codemirror.jsFile · 0.85

Calls 15

markTextSharedFunction · 0.85
operationFunction · 0.85
eltPFunction · 0.85
seeCollapsedSpansFunction · 0.85
addChangeToHistoryFunction · 0.85
visualLineFunction · 0.85
updateLineHeightFunction · 0.85
addMarkedSpanFunction · 0.85
lineIsHiddenFunction · 0.85
seeReadOnlySpansFunction · 0.85
regChangeFunction · 0.85

Tested by

no test coverage detected