From 3522a53ad445073a5d2d3a803982655fb25be1f1 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 11 Apr 2022 14:04:50 +0300 Subject: [PATCH] limit section's height to viewport --- edit/sections-editor-section.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/edit/sections-editor-section.js b/edit/sections-editor-section.js index 9909e087..187bf625 100644 --- a/edit/sections-editor-section.js +++ b/edit/sections-editor-section.js @@ -241,6 +241,7 @@ function createSection(originalSection, genId, si) { if (appliesTo.length > 1 && appliesTo[0].all) { removeApply(appliesTo[0]); } + if (base) requestAnimationFrame(shrinkSectionBy1); emitSectionChange('apply'); return apply; } @@ -349,6 +350,15 @@ function createSection(originalSection, genId, si) { dirty.add(`${dirtyPrefix}.value`, value); } } + + function shrinkSectionBy1() { + const cmEl = cm.display.wrapper; + const cmH = cmEl.offsetHeight; + const viewH = el.parentElement.offsetHeight; + if (el.offsetHeight > viewH && cmH > Math.min(viewH / 2, cm.display.sizer.offsetHeight + 30)) { + cmEl.style.height = (cmH - appliesToContainer.offsetHeight / (appliesTo.length || 1) | 0) + 'px'; + } + } } function createResizeGrip(cm) {