Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d0196a4

Browse files
authoredNov 5, 2019
Merge pull request #6 from l0llygag/cursorimp
Add cursor blink
2 parents 5d83575 + ca7cd0c commit d0196a4

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
 

‎css/caret.css

+9
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@
66

77
transition: 0.07s;
88
z-index: 3;
9+
}
10+
11+
.blink-caret {
12+
animation: blink 1s 1s infinite;
13+
}
14+
15+
@keyframes blink{
16+
0%{opacity: 0;}
17+
50%{opacity: 100%;}
918
}

‎css/custom.css

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#code_editor {
22
background-color: rgb(39, 39, 39);
33
overflow-y: auto;
4+
cursor: text;
45
/* overflow-x: hidden; */
56
}
67
.caret {

‎js/caret.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ Caret.prototype = {
1616
},
1717

1818
setPos : function(row, col) {
19+
this.resetBlink();
20+
1921
this.row = row;
2022
this.col = col;
2123

2224
let el = this.getCharacterElementBefore();
23-
let caretElement = $(`#caret_${this.page.getId()}_${this.id}`);
25+
let caretElement = this.getCarretElement();
2426
let lineEl, linenumEl, linecodeEl;
2527

2628
let top, left;
@@ -265,5 +267,19 @@ Caret.prototype = {
265267
let line_ref = _this.page.getLineRef(line_num);
266268
_this.setPos(line_num, line_ref.getCharCount()+1);
267269
}
270+
},
271+
272+
getCarretElement: function() {
273+
return $(`#caret_${this.page.getId()}_${this.id}`);
274+
},
275+
276+
resetBlink: function() {
277+
let carret = this.getCarretElement();
278+
carret.removeClass("blink-caret");
279+
280+
// Timeout avoids continuation of blink animation
281+
window.setTimeout(() => {
282+
carret.addClass("blink-caret");
283+
}, 500);;
268284
}
269285
}

0 commit comments

Comments
 (0)
Please sign in to comment.