From 119a60d498a9e92c3936b7834712e4d19a5353d8 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 24 Sep 2018 19:23:11 +0200 Subject: [PATCH] caret: Don't turn on animation repeatedly --- qutebrowser/javascript/caret.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qutebrowser/javascript/caret.js b/qutebrowser/javascript/caret.js index cd226dc1c..8f3ec8d72 100644 --- a/qutebrowser/javascript/caret.js +++ b/qutebrowser/javascript/caret.js @@ -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); }