(doc, from, to, options, type)
| 6190 | |
| 6191 | // Create a marker, wire it up to the right lines, and |
| 6192 | function markText(doc, from, to, options, type) { |
| 6193 | // Shared markers (across linked documents) are handled separately |
| 6194 | // (markTextShared will call out to this again, once per |
| 6195 | // document). |
| 6196 | if (options && options.shared) return markTextShared(doc, from, to, options, type); |
| 6197 | // Ensure we are in an operation. |
| 6198 | if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type); |
| 6199 | |
| 6200 | var marker = new TextMarker(doc, type), diff = cmp(from, to); |
| 6201 | if (options) copyObj(options, marker, false); |
| 6202 | // Don't connect empty markers unless clearWhenEmpty is false |
| 6203 | if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false) |
| 6204 | return marker; |
| 6205 | if (marker.replacedWith) { |
| 6206 | // Showing up as a widget implies collapsed (widget replaces text) |
| 6207 | marker.collapsed = true; |
| 6208 | marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget"); |
| 6209 | if (!options.handleMouseEvents) marker.widgetNode.setAttribute("cm-ignore-events", "true"); |
| 6210 | if (options.insertLeft) marker.widgetNode.insertLeft = true; |
| 6211 | } |
| 6212 | if (marker.collapsed) { |
| 6213 | if (conflictingCollapsedRange(doc, from.line, from, to, marker) || |
| 6214 | from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker)) |
| 6215 | throw new Error("Inserting collapsed marker partially overlapping an existing one"); |
| 6216 | sawCollapsedSpans = true; |
| 6217 | } |
| 6218 | |
| 6219 | if (marker.addToHistory) |
| 6220 | addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); |
| 6221 | |
| 6222 | var curLine = from.line, cm = doc.cm, updateMaxLine; |
| 6223 | doc.iter(curLine, to.line + 1, function(line) { |
| 6224 | if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine) |
| 6225 | updateMaxLine = true; |
| 6226 | if (marker.collapsed && curLine != from.line) updateLineHeight(line, 0); |
| 6227 | addMarkedSpan(line, new MarkedSpan(marker, |
| 6228 | curLine == from.line ? from.ch : null, |
| 6229 | curLine == to.line ? to.ch : null)); |
| 6230 | ++curLine; |
| 6231 | }); |
| 6232 | // lineIsHidden depends on the presence of the spans, so needs a second pass |
| 6233 | if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) { |
| 6234 | if (lineIsHidden(doc, line)) updateLineHeight(line, 0); |
| 6235 | }); |
| 6236 | |
| 6237 | if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); }); |
| 6238 | |
| 6239 | if (marker.readOnly) { |
| 6240 | sawReadOnlySpans = true; |
| 6241 | if (doc.history.done.length || doc.history.undone.length) |
| 6242 | doc.clearHistory(); |
| 6243 | } |
| 6244 | if (marker.collapsed) { |
| 6245 | marker.id = ++nextMarkerId; |
| 6246 | marker.atomic = true; |
| 6247 | } |
| 6248 | if (cm) { |
| 6249 | // Sync editor state |
no test coverage detected