From 02a9e409fbc8e68e815c1d6c500d32b1f6ed1b1a Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 10 Oct 2020 07:44:59 +0300 Subject: [PATCH] scroll the window to show a manually added section entirely --- edit/sections-editor.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/edit/sections-editor.js b/edit/sections-editor.js index b6ef594b..302d7d03 100644 --- a/edit/sections-editor.js +++ b/edit/sections-editor.js @@ -558,20 +558,18 @@ function createSectionsEditor({style, onTitleChanged}) { prevEditor, nextEditor }); - if (base) { - const index = sections.indexOf(base); - sections.splice(index + 1, 0, section); - container.insertBefore(section.el, base.el.nextSibling); - section.cm.focus(); - } else { - sections.push(section); - container.appendChild(section.el); - } - section.cm[forceRefresh ? 'refresh' : 'refreshOnView'](); + const {cm} = section; + sections.splice(base ? sections.indexOf(base) + 1 : sections.length, 0, section); + container.insertBefore(section.el, base ? base.el.nextSibling : null); + cm[forceRefresh ? 'refresh' : 'refreshOnView'](); if (!base || init.code) { // Fit a) during startup or b) when the clone button is clicked on a section with some code fitToContent(section); } + if (base) { + cm.focus(); + setTimeout(scrollToEditor, 0, cm); + } updateSectionOrder(); section.onChange(updateLivePreview); updateLivePreview();