fix more rect selection bugs

This commit is contained in:
2025-09-04 21:03:19 +02:00
parent afcbadee8b
commit 13e91fdfbf
5 changed files with 30 additions and 35 deletions

View File

@@ -8,6 +8,10 @@ const width = computed(() => Math.abs(rect.a.x - rect.b.x));
const height = computed(() => Math.abs(rect.a.y - rect.b.y));
function onDocumentPointerDown(e: MouseEvent) {
if (e.button !== 0) {
return;
}
const point = { x: e.x, y: e.y };
rect.set(
point,
@@ -17,12 +21,16 @@ function onDocumentPointerDown(e: MouseEvent) {
}
function onDocumentPointerMove(e: MouseEvent) {
if (!rect.enabled) {
return;
}
rect.updateB(e.x, e.y);
if (
rect.mode !== 'set' ||
!rect.enabled ||
warrenStore.selection.size === 0
warrenStore.selection.size === 0 ||
!rect.isMinSize()
) {
return;
}
@@ -30,22 +38,24 @@ function onDocumentPointerMove(e: MouseEvent) {
warrenStore.clearSelection();
}
function onDocumentPointerUp() {
function onDocumentPointerUp(e: MouseEvent) {
if (e.button !== 0 || !rect.enabled) {
return;
}
rect.disable();
if (warrenStore.current == null || warrenStore.current.dir == null) {
return;
}
const start = rect.a;
const end = rect.b;
const left = Math.min(start.x, end.x);
const top = Math.min(start.y, end.y);
const width = Math.abs(start.x - end.x);
const height = Math.abs(start.y - end.y);
const left = Math.min(rect.a.x, rect.b.x);
const top = Math.min(rect.a.y, rect.b.y);
const width = Math.abs(rect.a.x - rect.b.x);
const height = Math.abs(rect.a.y - rect.b.y);
if (!rect.isMinSize()) {
warrenStore.clearSelection();
return;
}
@@ -72,8 +82,6 @@ function onDocumentPointerUp() {
}
}
rect.dirty = true;
if (rect.mode === 'set') {
warrenStore.setSelection(targetEntries);
} else if (rect.mode === 'add') {