From fa96054acf612619d66ae3c01d9e4c5a3712728c Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Thu, 23 Apr 2020 17:51:23 +1000 Subject: [PATCH] PERF: stop firing superfluous onSelectionChange onSelectionChanged fires a debounced event that calls window.getSelection() window.getSelection() is reasonably expensive. There is no reason to do any of this work if we have an input field focused, that is not how quote works --- .../javascripts/discourse/components/quote-button.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/components/quote-button.js b/app/assets/javascripts/discourse/components/quote-button.js index 8f7d464543b..180654099fa 100644 --- a/app/assets/javascripts/discourse/components/quote-button.js +++ b/app/assets/javascripts/discourse/components/quote-button.js @@ -188,10 +188,16 @@ export default Component.extend({ .on("mouseup.quote-button", () => { this._prevSelection = null; this._isMouseDown = false; - onSelectionChanged(); + if (document.activeElement === document.body) { + onSelectionChanged(); + } }) .on("selectionchange.quote-button", () => { - if (!this._isMouseDown && !this._reselected) { + if ( + !this._isMouseDown && + !this._reselected && + document.activeElement === document.body + ) { onSelectionChanged(); } });