Commit 7b61acbd authored by Thottyottyotty's avatar Thottyottyotty
Browse files

split visibility method and sort instead

split out the visibility method for pasting and use a sort inside the paste handler to prioritize on-screen fields rather than targeting ONLY on screen fields
parent e373fd0c
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;
    }
+7 −3
Original line number Diff line number Diff line
@@ -99,10 +99,14 @@ function uiElementIsVisible(el) {
    const computedStyle = getComputedStyle(el);
    const isVisible = computedStyle.display !== 'none';

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

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

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