From 60a5fb96be3efcafd3ced302424ab2bc7d5f117f Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 11 Dec 2017 08:32:11 +0300 Subject: [PATCH] don't steal focus from the find input on page open --- edit/sections.js | 6 +++++- edit/source-editor.js | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/edit/sections.js b/edit/sections.js index 15be1684..a36960dc 100644 --- a/edit/sections.js +++ b/edit/sections.js @@ -65,7 +65,11 @@ function addSections(sections, onAdded = () => {}) { const isPageLocked = document.documentElement.style.pointerEvents; if (divs[0] && (isPageLocked ? divs.length === sections.length : index === 0)) { makeSectionVisible(divs[0].CodeMirror); - divs[0].CodeMirror.focus(); + setTimeout(() => { + if ((document.activeElement || {}).localName !== 'input') { + divs[0].CodeMirror.focus(); + } + }); } } } diff --git a/edit/source-editor.js b/edit/source-editor.js index 231901c9..f9139be1 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -43,8 +43,11 @@ function createSourceEditor(style) { initHooks(); initAppliesToLineWidget(); - // focus must be the last action, otherwise the style is duplicated on saving - cm.focus(); + setTimeout(() => { + if ((document.activeElement || {}).localName !== 'input') { + cm.focus(); + } + }); }); function initAppliesToLineWidget() {