Add smoothBlinking option to cursor
This commit is contained in:
parent
aa9962aafd
commit
1557004dfa
2 changed files with 34 additions and 3 deletions
|
|
@ -152,6 +152,18 @@
|
||||||
opacity: 0.2;
|
opacity: 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ace_smooth-blinking .ace_cursor {
|
||||||
|
-moz-transition: opacity 0.18s;
|
||||||
|
-webkit-transition: opacity 0.18s;
|
||||||
|
-o-transition: opacity 0.18s;
|
||||||
|
-ms-transition: opacity 0.18s;
|
||||||
|
transition: opacity 0.18s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ace_cursor[style*="opacity: 0"]{
|
||||||
|
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
|
||||||
|
}
|
||||||
|
|
||||||
.ace_editor.ace_multiselect .ace_cursor {
|
.ace_editor.ace_multiselect .ace_cursor {
|
||||||
border-left-width: 1px;
|
border-left-width: 1px;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ var Cursor = function(parentEl) {
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
this.isBlinking = true;
|
this.isBlinking = true;
|
||||||
this.blinkInterval = 1000;
|
this.blinkInterval = 1000;
|
||||||
|
this.smoothBlinking = false;
|
||||||
|
|
||||||
this.cursors = [];
|
this.cursors = [];
|
||||||
this.cursor = this.addCursor();
|
this.cursor = this.addCursor();
|
||||||
|
|
@ -71,6 +72,17 @@ var Cursor = function(parentEl) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.setSmoothBlinking = function(smoothBlinking) {
|
||||||
|
if (smoothBlinking != this.smoothBlinking) {
|
||||||
|
this.smoothBlinking = smoothBlinking;
|
||||||
|
if (smoothBlinking)
|
||||||
|
dom.addCssClass(this.element, "ace_smooth-blinking");
|
||||||
|
else
|
||||||
|
dom.removeCssClass(this.element, "ace_smooth-blinking");
|
||||||
|
this.resetTimer();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.addCursor = function() {
|
this.addCursor = function() {
|
||||||
var el = dom.createElement("div");
|
var el = dom.createElement("div");
|
||||||
var className = "ace_cursor";
|
var className = "ace_cursor";
|
||||||
|
|
@ -110,23 +122,30 @@ var Cursor = function(parentEl) {
|
||||||
this.resetTimer = function() {
|
this.resetTimer = function() {
|
||||||
clearInterval(this.intervalId);
|
clearInterval(this.intervalId);
|
||||||
clearTimeout(this.timeoutId);
|
clearTimeout(this.timeoutId);
|
||||||
|
if (this.smoothBlinking)
|
||||||
|
dom.removeCssClass(this.element, "ace_smooth-blinking");
|
||||||
for (var i = this.cursors.length; i--; )
|
for (var i = this.cursors.length; i--; )
|
||||||
this.cursors[i].style.visibility = "";
|
this.cursors[i].style.opacity = "";
|
||||||
|
|
||||||
if (!this.isBlinking || !this.blinkInterval || !this.isVisible)
|
if (!this.isBlinking || !this.blinkInterval || !this.isVisible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (this.smoothBlinking)
|
||||||
|
setTimeout(function(){
|
||||||
|
dom.addCssClass(this.element, "ace_smooth-blinking");
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
var blink = function(){
|
var blink = function(){
|
||||||
this.timeoutId = setTimeout(function() {
|
this.timeoutId = setTimeout(function() {
|
||||||
for (var i = this.cursors.length; i--; ) {
|
for (var i = this.cursors.length; i--; ) {
|
||||||
this.cursors[i].style.visibility = "hidden";
|
this.cursors[i].style.opacity = 0;
|
||||||
}
|
}
|
||||||
}.bind(this), 0.6 * this.blinkInterval);
|
}.bind(this), 0.6 * this.blinkInterval);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
this.intervalId = setInterval(function() {
|
this.intervalId = setInterval(function() {
|
||||||
for (var i = this.cursors.length; i--; ) {
|
for (var i = this.cursors.length; i--; ) {
|
||||||
this.cursors[i].style.visibility = "";
|
this.cursors[i].style.opacity = "";
|
||||||
}
|
}
|
||||||
blink();
|
blink();
|
||||||
}.bind(this), this.blinkInterval);
|
}.bind(this), this.blinkInterval);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue