(cm, vim)
| 5554 | } |
| 5555 | } |
| 5556 | function handleExternalSelection(cm, vim) { |
| 5557 | var anchor = cm.getCursor('anchor'); |
| 5558 | var head = cm.getCursor('head'); |
| 5559 | // Enter or exit visual mode to match mouse selection. |
| 5560 | if (vim.visualMode && !cm.somethingSelected()) { |
| 5561 | exitVisualMode(cm, false); |
| 5562 | } else if (!vim.visualMode && !vim.insertMode && cm.somethingSelected()) { |
| 5563 | vim.visualMode = true; |
| 5564 | vim.visualLine = false; |
| 5565 | CodeMirror.signal(cm, "vim-mode-change", {mode: "visual"}); |
| 5566 | } |
| 5567 | if (vim.visualMode) { |
| 5568 | // Bind CodeMirror selection model to vim selection model. |
| 5569 | // Mouse selections are considered visual characterwise. |
| 5570 | var headOffset = !cursorIsBefore(head, anchor) ? -1 : 0; |
| 5571 | var anchorOffset = cursorIsBefore(head, anchor) ? -1 : 0; |
| 5572 | head = offsetCursor(head, 0, headOffset); |
| 5573 | anchor = offsetCursor(anchor, 0, anchorOffset); |
| 5574 | vim.sel = { |
| 5575 | anchor: anchor, |
| 5576 | head: head |
| 5577 | }; |
| 5578 | updateMark(cm, vim, '<', cursorMin(head, anchor)); |
| 5579 | updateMark(cm, vim, '>', cursorMax(head, anchor)); |
| 5580 | } else if (!vim.insertMode) { |
| 5581 | // Reset lastHPos if selection was modified by something outside of vim mode e.g. by mouse. |
| 5582 | vim.lastHPos = cm.getCursor().ch; |
| 5583 | } |
| 5584 | } |
| 5585 | |
| 5586 | /** Wrapper for special keys pressed in insert mode */ |
| 5587 | function InsertModeKey(keyName) { |
no test coverage detected