(doc, from, to, options, type)
| 3959 | var nextMarkerId = 0; |
| 3960 | |
| 3961 | function markText(doc, from, to, options, type) { |
| 3962 | if (options && options.shared) return markTextShared(doc, from, to, options, type); |
| 3963 | if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type); |
| 3964 | |
| 3965 | var marker = new TextMarker(doc, type); |
| 3966 | if (options) copyObj(options, marker); |
| 3967 | if (posLess(to, from) || posEq(from, to) && marker.clearWhenEmpty !== false) |
| 3968 | return marker; |
| 3969 | if (marker.replacedWith) { |
| 3970 | marker.collapsed = true; |
| 3971 | marker.replacedWith = elt("span", [marker.replacedWith], "CodeMirror-widget"); |
| 3972 | if (!options.handleMouseEvents) marker.replacedWith.ignoreEvents = true; |
| 3973 | } |
| 3974 | if (marker.collapsed) { |
| 3975 | if (conflictingCollapsedRange(doc, from.line, from, to, marker) || |
| 3976 | from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker)) |
| 3977 | throw new Error("Inserting collapsed marker partially overlapping an existing one"); |
| 3978 | sawCollapsedSpans = true; |
| 3979 | } |
| 3980 | |
| 3981 | if (marker.addToHistory) |
| 3982 | addToHistory(doc, {from: from, to: to, origin: "markText"}, |
| 3983 | {head: doc.sel.head, anchor: doc.sel.anchor}, NaN); |
| 3984 | |
| 3985 | var curLine = from.line, cm = doc.cm, updateMaxLine; |
| 3986 | doc.iter(curLine, to.line + 1, function(line) { |
| 3987 | if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(doc, line) == cm.display.maxLine) |
| 3988 | updateMaxLine = true; |
| 3989 | var span = {from: null, to: null, marker: marker}; |
| 3990 | if (curLine == from.line) span.from = from.ch; |
| 3991 | if (curLine == to.line) span.to = to.ch; |
| 3992 | if (marker.collapsed && curLine != from.line) updateLineHeight(line, 0); |
| 3993 | addMarkedSpan(line, span); |
| 3994 | ++curLine; |
| 3995 | }); |
| 3996 | if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) { |
| 3997 | if (lineIsHidden(doc, line)) updateLineHeight(line, 0); |
| 3998 | }); |
| 3999 | |
| 4000 | if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); }); |
| 4001 | |
| 4002 | if (marker.readOnly) { |
| 4003 | sawReadOnlySpans = true; |
| 4004 | if (doc.history.done.length || doc.history.undone.length) |
| 4005 | doc.clearHistory(); |
| 4006 | } |
| 4007 | if (marker.collapsed) { |
| 4008 | marker.id = ++nextMarkerId; |
| 4009 | marker.atomic = true; |
| 4010 | } |
| 4011 | if (cm) { |
| 4012 | if (updateMaxLine) cm.curOp.updateMaxLine = true; |
| 4013 | if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.collapsed) |
| 4014 | regChange(cm, from.line, to.line + 1); |
| 4015 | if (marker.atomic) reCheckSelection(cm); |
| 4016 | } |
| 4017 | return marker; |
| 4018 | } |
no test coverage detected