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