[notes] avoid jiggling on _commit() by accounting for border widths

This commit is contained in:
Shish 2024-06-05 13:39:51 +01:00 committed by Shish
parent 15aaedb951
commit b6088f95c3

View file

@ -88,7 +88,7 @@ function renderEditor(noteDiv, note) {
dragStart = { dragStart = {
x: e.pageX, x: e.pageX,
y: e.pageY, y: e.pageY,
mode: getArea(e.offsetX, e.offsetY, noteDiv.offsetWidth, noteDiv.offsetHeight), mode: getArea(e.offsetX, e.offsetY, noteDiv.clientWidth, noteDiv.clientHeight),
}; };
noteDiv.classList.add("dragging"); noteDiv.classList.add("dragging");
}); });
@ -113,7 +113,7 @@ function renderEditor(noteDiv, note) {
noteDiv.style.width = (note.width * scale) + (e.pageX - dragStart.x) + 'px'; noteDiv.style.width = (note.width * scale) + (e.pageX - dragStart.x) + 'px';
} }
} else { } else {
let area = getArea(e.offsetX, e.offsetY, noteDiv.offsetWidth, noteDiv.offsetHeight); let area = getArea(e.offsetX, e.offsetY, noteDiv.clientWidth, noteDiv.clientHeight);
if(area == "c") { if(area == "c") {
noteDiv.style.cursor = 'move'; noteDiv.style.cursor = 'move';
} else { } else {
@ -126,8 +126,8 @@ function renderEditor(noteDiv, note) {
dragStart = null; dragStart = null;
note.x1 = Math.round(noteDiv.offsetLeft / scale); note.x1 = Math.round(noteDiv.offsetLeft / scale);
note.y1 = Math.round(noteDiv.offsetTop / scale); note.y1 = Math.round(noteDiv.offsetTop / scale);
note.width = Math.round(noteDiv.offsetWidth / scale); note.width = Math.round(noteDiv.clientWidth / scale);
note.height = Math.round(noteDiv.offsetHeight / scale); note.height = Math.round(noteDiv.clientHeight / scale);
renderNotes(); renderNotes();
} }
noteDiv.addEventListener('mouseup', _commit); noteDiv.addEventListener('mouseup', _commit);