Skip to content

Commit

Permalink
Merge pull request #241 from getmaxun/cap-list-select
Browse files Browse the repository at this point in the history
fix: include visual containment for capture list selection
  • Loading branch information
amhsirak authored Dec 10, 2024
2 parents 14c9626 + 668a670 commit 1383193
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions server/src/workflow-management/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,16 +847,24 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
if (!originalEl) return null;

let element = originalEl;

const containerTags = ['DIV', 'SECTION', 'ARTICLE', 'MAIN', 'HEADER', 'FOOTER', 'NAV', 'ASIDE',
'ADDRESS', 'BLOCKQUOTE', 'DETAILS', 'DIALOG', 'FIGURE', 'FIGCAPTION', 'MAIN', 'MARK', 'SUMMARY', 'TIME',
'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TR', 'TH', 'TD', 'CAPTION', 'COLGROUP', 'COL', 'FORM', 'FIELDSET',
'LEGEND', 'LABEL', 'INPUT', 'BUTTON', 'SELECT', 'DATALIST', 'OPTGROUP', 'OPTION', 'TEXTAREA', 'OUTPUT',
'PROGRESS', 'METER', 'DETAILS', 'SUMMARY', 'MENU', 'MENUITEM', 'MENUITEM', 'APPLET', 'EMBED', 'OBJECT',
'PARAM', 'VIDEO', 'AUDIO', 'SOURCE', 'TRACK', 'CANVAS', 'MAP', 'AREA', 'SVG', 'IFRAME', 'FRAME', 'FRAMESET',
'LI', 'UL', 'OL', 'DL', 'DT', 'DD', 'HR', 'P', 'PRE', 'LISTING', 'PLAINTEXT', 'A'
];

if (originalEl.tagName === 'A') {
element = originalEl;
} else if (originalEl.parentElement?.tagName === 'A') {
element = originalEl.parentElement;
} else {
while (element.parentElement) {
const parentRect = element.parentElement.getBoundingClientRect();
const childRect = element.getBoundingClientRect();

if (!containerTags.includes(element.parentElement.tagName)) {
break;
}

const fullyContained =
parentRect.left <= childRect.left &&
parentRect.right >= childRect.right &&
Expand All @@ -871,7 +879,6 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
element = element.parentElement;
} else {
break;
}
}
}

Expand Down

0 comments on commit 1383193

Please sign in to comment.