Auto-expand single section editor to utilize available space

This commit is contained in:
narcolepticinsomniac 2019-05-26 15:17:23 -04:00 committed by GitHub
parent eb6888e44c
commit 4f1d7a4052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,13 +60,32 @@ function createResizeGrip(cm) {
const sectionEl = wrapper.parentNode; const sectionEl = wrapper.parentNode;
const sectionExtrasHeight = sectionEl.clientHeight - wrapper.offsetHeight; const sectionExtrasHeight = sectionEl.clientHeight - wrapper.offsetHeight;
cm.state.toggleHeightSaved = wrapper.clientHeight; cm.state.toggleHeightSaved = wrapper.clientHeight;
cm.setSize(null, window.innerHeight - sectionExtrasHeight - pageExtrasHeight); cm.setSize(null, window.innerHeight - sectionExtrasHeight - pageExtrasHeight - 2);
const bounds = sectionEl.getBoundingClientRect(); const bounds = sectionEl.getBoundingClientRect();
if (bounds.top < 0 || bounds.bottom > window.innerHeight) { if (bounds.top < 0 || bounds.bottom > window.innerHeight) {
window.scrollBy(0, bounds.top); window.scrollBy(0, bounds.top);
} }
} }
} }
document.onreadystatechange = () => {
if (document.readyState !== 'loading') {
new MutationObserver((_, observer) => {
const sections = document.getElementsByClassName('section');
if (sections) {
if (sections.length === 1) {
setTimeout(() => {
toggleSectionHeight(cm);
sections[0].classList.add('height-calculated');
});
observer.disconnect();
} else {
observer.disconnect();
}
}
}).observe(document, {childList: true, subtree: true});
}
}
} }
function createSection({ function createSection({