From 0cffb564eabd0cc9d59c7b4d2bcecb7a407a8fc1 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 13 Sep 2018 08:36:19 +0300 Subject: [PATCH 1/2] don't re-toggle the style back on pressing Spacebar fixes #501 --- popup/popup.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/popup/popup.js b/popup/popup.js index 30a3d4a1..0ab1ccf1 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -328,6 +328,8 @@ Object.assign(handleEvent, { }, toggle(event) { + // when fired on checkbox, prevent the parent label from seeing the event, see #501 + event.stopPropagation(); API.saveStyle({ id: handleEvent.getClickedStyleId(event), enabled: this.matches('.enable') || this.checked, From 2a52139b6a1212be2daeadae4eb56e9bab2ed0b4 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 13 Sep 2018 08:36:53 +0300 Subject: [PATCH 2/2] preserve the focused element when replacing entry in-place --- popup/popup.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/popup/popup.js b/popup/popup.js index 0ab1ccf1..bea9498d 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -304,7 +304,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);