Fix: calculate cm height correctly

This commit is contained in:
eight 2019-06-18 01:12:40 +08:00
parent f0ab852a14
commit 1cdb2e7e92

View File

@ -9,7 +9,11 @@ function createResizeGrip(cm) {
const resizeGrip = template.resizeGrip.cloneNode(true); const resizeGrip = template.resizeGrip.cloneNode(true);
wrapper.appendChild(resizeGrip); wrapper.appendChild(resizeGrip);
let lastClickTime = 0; let lastClickTime = 0;
let initHeight;
let initY;
resizeGrip.onmousedown = event => { resizeGrip.onmousedown = event => {
initHeight = wrapper.offsetHeight;
initY = event.pageY;
if (event.button !== 0) { if (event.button !== 0) {
return; return;
} }
@ -31,9 +35,8 @@ function createResizeGrip(cm) {
document.addEventListener('mouseup', resizeStop); document.addEventListener('mouseup', resizeStop);
function resize(e) { function resize(e) {
const cmPageY = wrapper.getBoundingClientRect().top + window.scrollY; const height = Math.max(minHeight, initHeight + e.pageY - initY);
const height = Math.max(minHeight, e.pageY - cmPageY); if (height !== wrapper.offsetHeight) {
if (height !== wrapper.clientHeight) {
cm.setSize(null, height); cm.setSize(null, height);
} }
} }