From b9f6095db562ece6354fb107ad3b0ae27cc7397b Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 15 Nov 2017 04:53:37 +0300 Subject: [PATCH] focus code on opening standard editor immediately --- edit/edit.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/edit/edit.js b/edit/edit.js index 74db15dd..4fda7cff 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -1384,12 +1384,14 @@ function addSections(sections, onAdded = () => {}) { const t0 = performance.now(); const divs = []; let index = 0; + return new Promise(function run(resolve) { while (index < sections.length) { const div = addSection(null, sections[index]); maximizeCodeHeight(div, index === sections.length - 1); onAdded(div, index); divs.push(div); + maybeFocusFirstCM(); index++; const elapsed = performance.now() - t0; if (elapsed > 500) { @@ -1401,15 +1403,19 @@ function addSections(sections, onAdded = () => {}) { return; } } - if (divs[0]) { - makeSectionVisible(divs[0].CodeMirror); - divs[0].CodeMirror.focus(); - } editors.last.state.renderLintReportNow = true; addSections.running = false; setGlobalProgress(); resolve(divs); }); + + function maybeFocusFirstCM() { + const isPageLocked = document.documentElement.style.pointerEvents; + if (divs[0] && (isPageLocked ? index === sections.length : index === 0)) { + makeSectionVisible(divs[0].CodeMirror); + divs[0].CodeMirror.focus(); + } + } } function setupOptionsExpand() {