|
255 | 255 | } |
256 | 256 |
|
257 | 257 | function detachVimMap(cm, next) { |
258 | | - if (this == CodeMirror.keyMap.vim) |
| 258 | + if (this == CodeMirror.keyMap.vim) { |
259 | 259 | CodeMirror.rmClass(cm.getWrapperElement(), "cm-fat-cursor"); |
| 260 | + if (cm.getOption("inputStyle") == "contenteditable" && document.body.style.caretColor != null) { |
| 261 | + disableFatCursorMark(cm); |
| 262 | + cm.getInputField().style.caretColor = ""; |
| 263 | + } |
| 264 | + } |
260 | 265 |
|
261 | 266 | if (!next || next.attach != attachVimMap) |
262 | 267 | leaveVimMode(cm); |
263 | 268 | } |
264 | 269 | function attachVimMap(cm, prev) { |
265 | | - if (this == CodeMirror.keyMap.vim) |
| 270 | + if (this == CodeMirror.keyMap.vim) { |
266 | 271 | CodeMirror.addClass(cm.getWrapperElement(), "cm-fat-cursor"); |
| 272 | + if (cm.getOption("inputStyle") == "contenteditable" && document.body.style.caretColor != null) { |
| 273 | + enableFatCursorMark(cm); |
| 274 | + cm.getInputField().style.caretColor = "transparent"; |
| 275 | + } |
| 276 | + } |
267 | 277 |
|
268 | 278 | if (!prev || prev.attach != attachVimMap) |
269 | 279 | enterVimMode(cm); |
270 | 280 | } |
271 | 281 |
|
| 282 | + function fatCursorMarks(cm) { |
| 283 | + var ranges = cm.listSelections(), result = [] |
| 284 | + for (var i = 0; i < ranges.length; i++) { |
| 285 | + var range = ranges[i] |
| 286 | + if (range.empty()) { |
| 287 | + if (range.anchor.ch < cm.getLine(range.anchor.line).length) { |
| 288 | + result.push(cm.markText(range.anchor, Pos(range.anchor.line, range.anchor.ch + 1), |
| 289 | + {className: "cm-fat-cursor-mark"})) |
| 290 | + } else { |
| 291 | + var widget = document.createElement("span") |
| 292 | + widget.textContent = "\u00a0" |
| 293 | + widget.className = "cm-fat-cursor-mark" |
| 294 | + result.push(cm.setBookmark(range.anchor, {widget: widget})) |
| 295 | + } |
| 296 | + } |
| 297 | + } |
| 298 | + return result |
| 299 | + } |
| 300 | + |
| 301 | + function updateFatCursorMark(cm) { |
| 302 | + var marks = cm.state.fatCursorMarks |
| 303 | + if (marks) for (var i = 0; i < marks.length; i++) marks[i].clear() |
| 304 | + cm.state.fatCursorMarks = fatCursorMarks(cm) |
| 305 | + } |
| 306 | + |
| 307 | + function enableFatCursorMark(cm) { |
| 308 | + cm.state.fatCursorMarks = fatCursorMarks(cm) |
| 309 | + cm.on("cursorActivity", updateFatCursorMark) |
| 310 | + } |
| 311 | + |
| 312 | + function disableFatCursorMark(cm) { |
| 313 | + var marks = cm.state.fatCursorMarks |
| 314 | + if (marks) for (var i = 0; i < marks.length; i++) marks[i].clear() |
| 315 | + cm.state.fatCursorMarks = null |
| 316 | + cm.off("cursorActivity", updateFatCursorMark) |
| 317 | + } |
| 318 | + |
272 | 319 | // Deprecated, simply setting the keymap works again. |
273 | 320 | CodeMirror.defineOption('vimMode', false, function(cm, val, prev) { |
274 | 321 | if (val && cm.getOption("keyMap") != "vim") |
|
0 commit comments