MCPcopy Create free account
hub / github.com/breck7/scroll / markText

Function markText

external/.scrollLibs.js:7999–8098  ·  view source on GitHub ↗
(doc, from, to, options, type)

Source from the content-addressed store, hash-verified

7997
7998 // Create a marker, wire it up to the right lines, and
7999 function markText(doc, from, to, options, type) {
8000 // Shared markers (across linked documents) are handled separately
8001 // (markTextShared will call out to this again, once per
8002 // document).
8003 if (options && options.shared) {
8004 return markTextShared(doc, from, to, options, type)
8005 }
8006 // Ensure we are in an operation.
8007 if (doc.cm && !doc.cm.curOp) {
8008 return operation(doc.cm, markText)(doc, from, to, options, type)
8009 }
8010
8011 var marker = new TextMarker(doc, type),
8012 diff = cmp(from, to)
8013 if (options) {
8014 copyObj(options, marker, false)
8015 }
8016 // Don't connect empty markers unless clearWhenEmpty is false
8017 if (diff > 0 || (diff == 0 && marker.clearWhenEmpty !== false)) {
8018 return marker
8019 }
8020 if (marker.replacedWith) {
8021 // Showing up as a widget implies collapsed (widget replaces text)
8022 marker.collapsed = true
8023 marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget")
8024 if (!options.handleMouseEvents) {
8025 marker.widgetNode.setAttribute("cm-ignore-events", "true")
8026 }
8027 if (options.insertLeft) {
8028 marker.widgetNode.insertLeft = true
8029 }
8030 }
8031 if (marker.collapsed) {
8032 if (conflictingCollapsedRange(doc, from.line, from, to, marker) || (from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))) {
8033 throw new Error("Inserting collapsed marker partially overlapping an existing one")
8034 }
8035 seeCollapsedSpans()
8036 }
8037
8038 if (marker.addToHistory) {
8039 addChangeToHistory(doc, { from: from, to: to, origin: "markText" }, doc.sel, NaN)
8040 }
8041
8042 var curLine = from.line,
8043 cm = doc.cm,
8044 updateMaxLine
8045 doc.iter(curLine, to.line + 1, function (line) {
8046 if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine) {
8047 updateMaxLine = true
8048 }
8049 if (marker.collapsed && curLine != from.line) {
8050 updateLineHeight(line, 0)
8051 }
8052 addMarkedSpan(line, new MarkedSpan(marker, curLine == from.line ? from.ch : null, curLine == to.line ? to.ch : null))
8053 ++curLine
8054 })
8055 // lineIsHidden depends on the presence of the spans, so needs a second pass
8056 if (marker.collapsed) {

Callers 3

markTextSharedFunction · 0.85
copySharedMarkersFunction · 0.85
.scrollLibs.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