MCPcopy Index your code
hub / github.com/DHTMLX/gantt / markText

Function markText

samples/common/codehighlight/codemirror.js:5927–5995  ·  view source on GitHub ↗
(doc, from, to, options, type)

Source from the content-addressed store, hash-verified

5925
5926 // Create a marker, wire it up to the right lines, and
5927 function markText(doc, from, to, options, type) {
5928 // Shared markers (across linked documents) are handled separately
5929 // (markTextShared will call out to this again, once per
5930 // document).
5931 if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
5932 // Ensure we are in an operation.
5933 if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
5934
5935 var marker = new TextMarker(doc, type), diff = cmp(from, to);
5936 if (options) { copyObj(options, marker, false); }
5937 // Don't connect empty markers unless clearWhenEmpty is false
5938 if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
5939 { return marker }
5940 if (marker.replacedWith) {
5941 // Showing up as a widget implies collapsed (widget replaces text)
5942 marker.collapsed = true;
5943 marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget");
5944 if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true"); }
5945 if (options.insertLeft) { marker.widgetNode.insertLeft = true; }
5946 }
5947 if (marker.collapsed) {
5948 if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
5949 from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
5950 { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
5951 seeCollapsedSpans();
5952 }
5953
5954 if (marker.addToHistory)
5955 { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); }
5956
5957 var curLine = from.line, cm = doc.cm, updateMaxLine;
5958 doc.iter(curLine, to.line + 1, function (line) {
5959 if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
5960 { updateMaxLine = true; }
5961 if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0); }
5962 addMarkedSpan(line, new MarkedSpan(marker,
5963 curLine == from.line ? from.ch : null,
5964 curLine == to.line ? to.ch : null));
5965 ++curLine;
5966 });
5967 // lineIsHidden depends on the presence of the spans, so needs a second pass
5968 if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
5969 if (lineIsHidden(doc, line)) { updateLineHeight(line, 0); }
5970 }); }
5971
5972 if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }); }
5973
5974 if (marker.readOnly) {
5975 seeReadOnlySpans();
5976 if (doc.history.done.length || doc.history.undone.length)
5977 { doc.clearHistory(); }
5978 }
5979 if (marker.collapsed) {
5980 marker.id = ++nextMarkerId;
5981 marker.atomic = true;
5982 }
5983 if (cm) {
5984 // Sync editor state

Callers 3

markTextSharedFunction · 0.85
copySharedMarkersFunction · 0.85
codemirror.jsFile · 0.85

Calls 15

markTextSharedFunction · 0.85
operationFunction · 0.85
cmpFunction · 0.85
copyObjFunction · 0.85
eltPFunction · 0.85
seeCollapsedSpansFunction · 0.85
addChangeToHistoryFunction · 0.85
visualLineFunction · 0.85
updateLineHeightFunction · 0.85
addMarkedSpanFunction · 0.85
lineIsHiddenFunction · 0.85

Tested by

no test coverage detected