MCPcopy Create free account
hub / github.com/sql-js/sql.js / markText

Function markText

GUI/codemirror/lib/codemirror.js:5002–5069  ·  view source on GitHub ↗
(doc, from, to, options, type)

Source from the content-addressed store, hash-verified

5000
5001 // Create a marker, wire it up to the right lines, and
5002 function markText(doc, from, to, options, type) {
5003 // Shared markers (across linked documents) are handled separately
5004 // (markTextShared will call out to this again, once per
5005 // document).
5006 if (options && options.shared) return markTextShared(doc, from, to, options, type);
5007 // Ensure we are in an operation.
5008 if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type);
5009
5010 var marker = new TextMarker(doc, type), diff = cmp(from, to);
5011 if (options) copyObj(options, marker, false);
5012 // Don't connect empty markers unless clearWhenEmpty is false
5013 if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
5014 return marker;
5015 if (marker.replacedWith) {
5016 // Showing up as a widget implies collapsed (widget replaces text)
5017 marker.collapsed = true;
5018 marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget");
5019 if (!options.handleMouseEvents) marker.widgetNode.ignoreEvents = true;
5020 if (options.insertLeft) marker.widgetNode.insertLeft = true;
5021 }
5022 if (marker.collapsed) {
5023 if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
5024 from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
5025 throw new Error("Inserting collapsed marker partially overlapping an existing one");
5026 sawCollapsedSpans = true;
5027 }
5028
5029 if (marker.addToHistory)
5030 addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN);
5031
5032 var curLine = from.line, cm = doc.cm, updateMaxLine;
5033 doc.iter(curLine, to.line + 1, function(line) {
5034 if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
5035 updateMaxLine = true;
5036 if (marker.collapsed && curLine != from.line) updateLineHeight(line, 0);
5037 addMarkedSpan(line, new MarkedSpan(marker,
5038 curLine == from.line ? from.ch : null,
5039 curLine == to.line ? to.ch : null));
5040 ++curLine;
5041 });
5042 // lineIsHidden depends on the presence of the spans, so needs a second pass
5043 if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
5044 if (lineIsHidden(doc, line)) updateLineHeight(line, 0);
5045 });
5046
5047 if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); });
5048
5049 if (marker.readOnly) {
5050 sawReadOnlySpans = true;
5051 if (doc.history.done.length || doc.history.undone.length)
5052 doc.clearHistory();
5053 }
5054 if (marker.collapsed) {
5055 marker.id = ++nextMarkerId;
5056 marker.atomic = true;
5057 }
5058 if (cm) {
5059 // Sync editor state

Callers 3

markTextSharedFunction · 0.85
copySharedMarkersFunction · 0.85
codemirror.jsFile · 0.85

Calls 15

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…