scroll the window to show a manually added section entirely

This commit is contained in:
tophf 2020-10-10 07:44:59 +03:00
parent 858fa874ae
commit 02a9e409fb

View File

@ -558,20 +558,18 @@ function createSectionsEditor({style, onTitleChanged}) {
prevEditor, prevEditor,
nextEditor nextEditor
}); });
if (base) { const {cm} = section;
const index = sections.indexOf(base); sections.splice(base ? sections.indexOf(base) + 1 : sections.length, 0, section);
sections.splice(index + 1, 0, section); container.insertBefore(section.el, base ? base.el.nextSibling : null);
container.insertBefore(section.el, base.el.nextSibling); cm[forceRefresh ? 'refresh' : 'refreshOnView']();
section.cm.focus();
} else {
sections.push(section);
container.appendChild(section.el);
}
section.cm[forceRefresh ? 'refresh' : 'refreshOnView']();
if (!base || init.code) { if (!base || init.code) {
// Fit a) during startup or b) when the clone button is clicked on a section with some code // Fit a) during startup or b) when the clone button is clicked on a section with some code
fitToContent(section); fitToContent(section);
} }
if (base) {
cm.focus();
setTimeout(scrollToEditor, 0, cm);
}
updateSectionOrder(); updateSectionOrder();
section.onChange(updateLivePreview); section.onChange(updateLivePreview);
updateLivePreview(); updateLivePreview();