Prioritize selected rectangle in pattern editor hit test

When multiple rectangles overlap, the currently selected one is now
tested first for both click and hover, keeping its edges and body
interactive even when another rectangle sits on top.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-19 11:42:08 +03:00
parent df52a197d9
commit 747cdfabd6

View File

@@ -675,8 +675,15 @@ function _patternCanvasMouseDown(e) {
}
}
// Test all rects in reverse order (top-most first).
// Test all rects; selected rect takes priority so it stays interactive
// even when overlapping with others.
const selIdx = patternEditorSelectedIdx;
const testOrder = [];
if (selIdx >= 0 && selIdx < patternEditorRects.length) testOrder.push(selIdx);
for (let i = patternEditorRects.length - 1; i >= 0; i--) {
if (i !== selIdx) testOrder.push(i);
}
for (const i of testOrder) {
const r = patternEditorRects[i];
const hit = _hitTestRect(mx, my, r, w, h);
if (!hit) continue;
@@ -733,7 +740,14 @@ function _patternCanvasMouseMove(e) {
let cursor = 'default';
let newHoverIdx = -1;
let newHoverHit = null;
// Selected rect takes priority for hover so edges stay reachable under overlaps
const selIdx = patternEditorSelectedIdx;
const hoverOrder = [];
if (selIdx >= 0 && selIdx < patternEditorRects.length) hoverOrder.push(selIdx);
for (let i = patternEditorRects.length - 1; i >= 0; i--) {
if (i !== selIdx) hoverOrder.push(i);
}
for (const i of hoverOrder) {
const hit = _hitTestRect(mx, my, patternEditorRects[i], w, h);
if (hit) {
cursor = _DIR_CURSORS[hit] || 'default';