From fcad0ee523087cc931f77d70ee2e48dfd99561a0 Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 12 Feb 2022 21:31:35 +0300 Subject: [PATCH] avoid double handling of keyboard event in rerouter ...and thus fix the bug with restoring keyboard focus to codemirror when closing color picker --- edit/codemirror-factory.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/edit/codemirror-factory.js b/edit/codemirror-factory.js index 6e18789e..92b4b9c3 100644 --- a/edit/codemirror-factory.js +++ b/edit/codemirror-factory.js @@ -48,8 +48,10 @@ cm.lastActive = Date.now(); }; const onCmBlur = cm => { - rerouteHotkeys.toggle(true); setTimeout(() => { + /* Delaying to next tick to avoid double-processing of the currently processed keyboard event + * when it bubbles up from CodeMirror to `document` where the rerouter listens */ + rerouteHotkeys.toggle(true); const {wrapper} = cm.display; wrapper.classList.toggle('CodeMirror-active', wrapper.contains(document.activeElement)); });