Skip to content

Commit d662f18

Browse files
binnymightyguava
authored andcommitted
[vim] Added CSS3 animated fat cursor
1 parent 8726ab6 commit d662f18

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

keymap/vim.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,8 @@
604604
// executed in between.
605605
lastMotion: null,
606606
marks: {},
607+
// fake cursor for visual mode
608+
fakeCursor: null,
607609
insertMode: false,
608610
// Repeat count for changes made in insert mode, triggered by key
609611
// sequences like 3,i. Only exists when insertMode is true.
@@ -2467,6 +2469,9 @@
24672469
cm.setCursor(clipCursorToContent(cm, selectionEnd));
24682470
}
24692471
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
2472+
if (vim.fakeCursor) {
2473+
vim.fakeCursor.clear();
2474+
}
24702475
}
24712476

24722477
// Remove any trailing newlines from the selection. For
@@ -4332,6 +4337,20 @@
43324337
} else if (cm.doc.history.lastSelOrigin == '*mouse') {
43334338
// Reset lastHPos if mouse click was done in normal mode.
43344339
vim.lastHPos = cm.doc.getCursor().ch;
4340+
} else if (vim.visualMode) {
4341+
var from, head;
4342+
from = head = cm.getCursor('head');
4343+
var anchor = cm.getCursor('anchor');
4344+
var to = Pos(head.line, from.ch + (cursorIsBefore(anchor, head) ? -1 : 1));
4345+
if (cursorIsBefore(to, from)) {
4346+
var temp = from;
4347+
from = to;
4348+
to = temp;
4349+
}
4350+
if (vim.fakeCursor) {
4351+
vim.fakeCursor.clear();
4352+
}
4353+
vim.fakeCursor = cm.markText(from, to, {className: 'fake-fat-cursor'});
43354354
}
43364355
}
43374356

lib/codemirror.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,45 @@ div.CodeMirror-overwrite div.CodeMirror-cursor {}
6363
border-left: 1px solid #ccc;
6464
position: absolute;
6565
}
66+
.fake-fat-cursor {
67+
width: auto;
68+
border: 0;
69+
background: #7e7;
70+
71+
-webkit-animation: blink 1s infinite;
72+
-moz-animation: blink 1s infinite;
73+
animation: blink 1s infinite;
74+
}
6675

76+
@-moz-keyframes blink {
77+
0% {
78+
visibility: visible;
79+
}
80+
100% {
81+
visibility: hidden;
82+
background: white;
83+
}
84+
}
85+
86+
@-webkit-keyframes blink {
87+
0% {
88+
visibility: visible;
89+
}
90+
100% {
91+
visibility: hidden;
92+
background: white;
93+
}
94+
}
95+
96+
@keyframes blink {
97+
0% {
98+
visibility: visible;
99+
}
100+
100% {
101+
visibility: hidden;
102+
background: white;
103+
}
104+
}
67105
/* DEFAULT THEME */
68106

69107
.cm-s-default .cm-keyword {color: #708;}

0 commit comments

Comments
 (0)