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);
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);
}
}