()
| 250 | var Pos = CodeMirror.Pos; |
| 251 | |
| 252 | var Vim = function() { |
| 253 | function enterVimMode(cm) { |
| 254 | cm.setOption('disableInput', true); |
| 255 | cm.setOption('showCursorWhenSelecting', false); |
| 256 | CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"}); |
| 257 | cm.on('cursorActivity', onCursorActivity); |
| 258 | maybeInitVimState(cm); |
| 259 | CodeMirror.on(cm.getInputField(), 'paste', getOnPasteFn(cm)); |
| 260 | } |
| 261 | |
| 262 | function leaveVimMode(cm) { |
| 263 | cm.setOption('disableInput', false); |
| 264 | cm.off('cursorActivity', onCursorActivity); |
| 265 | CodeMirror.off(cm.getInputField(), 'paste', getOnPasteFn(cm)); |
| 266 | cm.state.vim = null; |
| 267 | } |
| 268 | |
| 269 | function detachVimMap(cm, next) { |
| 270 | if (this == CodeMirror.keyMap.vim) { |
| 271 | CodeMirror.rmClass(cm.getWrapperElement(), "cm-fat-cursor"); |
| 272 | if (cm.getOption("inputStyle") == "contenteditable" && document.body.style.caretColor != null) { |
| 273 | disableFatCursorMark(cm); |
| 274 | cm.getInputField().style.caretColor = ""; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | if (!next || next.attach != attachVimMap) |
| 279 | leaveVimMode(cm); |
| 280 | } |
| 281 | function attachVimMap(cm, prev) { |
| 282 | if (this == CodeMirror.keyMap.vim) { |
| 283 | CodeMirror.addClass(cm.getWrapperElement(), "cm-fat-cursor"); |
| 284 | if (cm.getOption("inputStyle") == "contenteditable" && document.body.style.caretColor != null) { |
| 285 | enableFatCursorMark(cm); |
| 286 | cm.getInputField().style.caretColor = "transparent"; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | if (!prev || prev.attach != attachVimMap) |
| 291 | enterVimMode(cm); |
| 292 | } |
| 293 | |
| 294 | function updateFatCursorMark(cm) { |
| 295 | if (!cm.state.fatCursorMarks) return; |
| 296 | clearFatCursorMark(cm); |
| 297 | var ranges = cm.listSelections(), result = [] |
| 298 | for (var i = 0; i < ranges.length; i++) { |
| 299 | var range = ranges[i]; |
| 300 | if (range.empty()) { |
| 301 | var lineLength = cm.getLine(range.anchor.line).length; |
| 302 | if (range.anchor.ch < lineLength) { |
| 303 | result.push(cm.markText(range.anchor, Pos(range.anchor.line, range.anchor.ch + 1), |
| 304 | {className: "cm-fat-cursor-mark"})); |
| 305 | } else { |
| 306 | result.push(cm.markText(Pos(range.anchor.line, lineLength - 1), |
| 307 | Pos(range.anchor.line, lineLength), |
| 308 | {className: "cm-fat-cursor-mark"})); |
| 309 | } |
no test coverage detected