caret: Don't turn on animation repeatedly

This commit is contained in:
Florian Bruhin 2018-09-24 19:23:11 +02:00
parent 3c1ab71fce
commit 119a60d498

View File

@ -768,6 +768,13 @@ window._qutebrowser.caret = (function() {
*/
CaretBrowsing.needsFilterPrefix = null;
/**
* The id returned by window.setInterval for our stopAnimation function, so
* we can cancel it when we call stopAnimation again.
* @type {number?}
*/
CaretBrowsing.animationFunctionId = null;
/**
* Check if a node is a control that normally allows the user to interact
* with it using arrow keys. We won't override the arrow keys when such a
@ -1252,7 +1259,9 @@ window._qutebrowser.caret = (function() {
CaretBrowsing.stopAnimation = function() {
if (CaretBrowsing.caretElement) {
CaretBrowsing.caretElement.style.animationIterationCount = 0;
window.setTimeout(() => {
window.clearTimeout(CaretBrowsing.animationFunctionId);
CaretBrowsing.animationFunctionId = window.setTimeout(() => {
CaretBrowsing.startAnimation();
}, 1000);
}