From 81fa6b1e7994a8136104e07305f420ed354024ea Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 25 Feb 2021 10:04:25 +0300 Subject: [PATCH] avoid a scrollbar due to rounding errors --- edit/sections-editor.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/edit/sections-editor.js b/edit/sections-editor.js index 2102cad4..0f2f7db4 100644 --- a/edit/sections-editor.js +++ b/edit/sections-editor.js @@ -21,6 +21,7 @@ function SectionsEditor() { let INC_ID = 0; // an increment id that is used by various object to track the order let sectionOrder = ''; let headerOffset; // in compact mode the header is at the top so it reduces the available height + let cmExtrasHeight; // resize grip + borders updateHeader(); rerouteHotkeys.toggle(true); // enabled initially because we don't always focus a CodeMirror @@ -138,13 +139,17 @@ function SectionsEditor() { return; } if (headerOffset == null) { - headerOffset = container.getBoundingClientRect().top + scrollY | 0; + headerOffset = Math.ceil(container.getBoundingClientRect().top + scrollY); } - contentHeight += 9; // border & resize grip + if (cmExtrasHeight == null) { + cmExtrasHeight = $('.resize-grip', wrapper).offsetHeight + // grip + wrapper.offsetHeight - wrapper.clientHeight; // borders + } + contentHeight += cmExtrasHeight; cm.off('update', resize); const cmHeight = wrapper.offsetHeight; const appliesToHeight = Math.min(section.el.offsetHeight - cmHeight, window.innerHeight / 2); - const maxHeight = (window.innerHeight - headerOffset) - appliesToHeight; + const maxHeight = Math.floor(window.innerHeight - headerOffset - appliesToHeight); const fit = Math.min(contentHeight, maxHeight); if (Math.abs(fit - cmHeight) > 1) { cm.setSize(null, fit);