Unverified Commit fe7bcbe3 authored by AUTOMATIC1111's avatar AUTOMATIC1111 Committed by GitHub
Browse files

Merge pull request #10534 from thot-experiment/dev

rewrite uiElementIsVisible
parents 8c1148b9 7b61acbd
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -81,7 +81,10 @@ window.addEventListener('paste', e => {
    }

    const visibleImageFields = [...gradioApp().querySelectorAll('[data-testid="image"]')]
        .filter(el => uiElementIsVisible(el));
        .filter(el => uiElementIsVisible(el))
        .sort((a,b) => uiElementInSight(b) - uiElementInSight(a));


    if (!visibleImageFields.length) {
        return;
    }
+15 −13
Original line number Diff line number Diff line
@@ -92,19 +92,21 @@ document.addEventListener('keydown', function(e) {
 * checks that a UI element is not in another hidden element or tab content
 */
function uiElementIsVisible(el) {
    let isVisible = !el.closest('.\\!hidden');
    if (!isVisible) {
        return false;
    if (el === document) {
        return true;
    }

    while ((isVisible = el.closest('.tabitem')?.style.display) !== 'none') {
        if (!isVisible) {
            return false;
        } else if (el.parentElement) {
            el = el.parentElement;
        } else {
            break;
        }
    const computedStyle = getComputedStyle(el);
    const isVisible = computedStyle.display !== 'none';

    if (!isVisible) return false;
    return uiElementIsVisible(el.parentNode);
}
    return isVisible;

function uiElementInSight(el) {
    const clRect = el.getBoundingClientRect();
    const windowHeight = window.innerHeight;
    const isOnScreen = clRect.bottom > 0 && clRect.top < windowHeight;

    return isOnScreen;
}