From 0766dd7f0aedd056283c25fa7c00328f89ae7282 Mon Sep 17 00:00:00 2001 From: narcolepticinsomniac Date: Fri, 12 Oct 2018 17:47:08 -0400 Subject: [PATCH] Reincorporate tophf's update --- popup/popup.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/popup/popup.js b/popup/popup.js index 90d8e91a..ad6fdd81 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -356,7 +356,14 @@ function createStyleElement({ if (check) detectSloppyRegexps([style]); const oldElement = $(ENTRY_ID_PREFIX + style.id); - if (oldElement) { + if (oldElement && oldElement.contains(document.activeElement)) { + // preserve the focused element inside + const {className} = document.activeElement; + oldElement.parentNode.replaceChild(entry, oldElement); + // we're not using $() since className may contain multiple tokens + const el = entry.getElementsByClassName(className)[0]; + if (el) el.focus(); + } else if (oldElement) { oldElement.parentNode.replaceChild(entry, oldElement); } else { container.appendChild(entry);