From 1cdb2e7e922911f4b7eac475be063aceb1c43689 Mon Sep 17 00:00:00 2001 From: eight Date: Tue, 18 Jun 2019 01:12:40 +0800 Subject: [PATCH] Fix: calculate cm height correctly --- edit/sections-editor-section.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/edit/sections-editor-section.js b/edit/sections-editor-section.js index 74540e79..67880a35 100644 --- a/edit/sections-editor-section.js +++ b/edit/sections-editor-section.js @@ -9,7 +9,11 @@ function createResizeGrip(cm) { const resizeGrip = template.resizeGrip.cloneNode(true); wrapper.appendChild(resizeGrip); let lastClickTime = 0; + let initHeight; + let initY; resizeGrip.onmousedown = event => { + initHeight = wrapper.offsetHeight; + initY = event.pageY; if (event.button !== 0) { return; } @@ -31,9 +35,8 @@ function createResizeGrip(cm) { document.addEventListener('mouseup', resizeStop); function resize(e) { - const cmPageY = wrapper.getBoundingClientRect().top + window.scrollY; - const height = Math.max(minHeight, e.pageY - cmPageY); - if (height !== wrapper.clientHeight) { + const height = Math.max(minHeight, initHeight + e.pageY - initY); + if (height !== wrapper.offsetHeight) { cm.setSize(null, height); } }