Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #1774, when the autoselect is small try to add the next sibling (…
Browse files Browse the repository at this point in the history
…or uncle) element.
  • Loading branch information
ianb committed Oct 18, 2016
1 parent e0ffcbd commit a3b8604
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions addon/data/shooter-interactive-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ class Selection {
}
}

union(other) {
return new Selection(
Math.min(this.left, other.left),
Math.min(this.top, other.top),
Math.max(this.right, other.right),
Math.max(this.bottom, other.bottom)
);
}

clone() {
return new Selection(this.x1, this.y1, this.x2, this.y2);
}
Expand Down Expand Up @@ -392,7 +401,9 @@ stateHandlers.crosshairs = {
);
document.body.classList.remove("pageshot-no-pointer-event");
let lastRect;
let lastNode;
let rect;
let attemptExtend = false;
let node = el;
while (node) {
rect = Selection.getBoundingClientRect(node);
Expand All @@ -403,6 +414,7 @@ stateHandlers.crosshairs = {
if (rect.width > MAX_DETECT_WIDTH || rect.height > MAX_DETECT_HEIGHT) {
// Then the last rectangle is better
rect = lastRect;
attemptExtend = true;
break;
}
if (rect.width >= MIN_DETECT_WIDTH && rect.height >= MIN_DETECT_HEIGHT) {
Expand All @@ -411,8 +423,33 @@ stateHandlers.crosshairs = {
}
}
lastRect = rect;
lastNode = node;
node = node.parentNode;
}
if (rect && attemptExtend) {
let extendNode = lastNode.nextSibling;
while (extendNode) {
if (extendNode.nodeType === document.ELEMENT_NODE) {
break;
}
extendNode = extendNode.nextSibling;
if (! extendNode) {
let parent = lastNode.parentNode;
for (let i=0; i<parent.childNodes.length; i++) {
if (parent.childNodes[i] === lastNode) {
extendNode = parent.childNodes[i+1];
}
}
}
}
if (extendNode) {
let extendSelection = Selection.getBoundingClientRect(extendNode);
let extendRect = rect.union(extendSelection);
if (extendRect.width <= MAX_DETECT_WIDTH && extendRect.height <= MAX_DETECT_HEIGHT) {
rect = extendRect;
}
}
}
if (! rect) {
ui.HoverBox.hide();
} else {
Expand Down

0 comments on commit a3b8604

Please sign in to comment.