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
This commit is contained in:
Thottyottyotty 2023-05-18 23:43:01 -07:00
parent e373fd0c00
commit 7b61acbd35
2 changed files with 13 additions and 6 deletions

View File

@ -81,7 +81,10 @@ window.addEventListener('paste', e => {
} }
const visibleImageFields = [...gradioApp().querySelectorAll('[data-testid="image"]')] 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) { if (!visibleImageFields.length) {
return; return;
} }

View File

@ -99,10 +99,14 @@ function uiElementIsVisible(el) {
const computedStyle = getComputedStyle(el); const computedStyle = getComputedStyle(el);
const isVisible = computedStyle.display !== 'none'; const isVisible = computedStyle.display !== 'none';
const clRect = el.getBoundingClientRect(); if (!isVisible) return false;
const windowHeight = window.innerHeight;
const onScreen = clRect.bottom > 0 && clRect.top < windowHeight;
if (!isVisible || !onScreen) return false;
return uiElementIsVisible(el.parentNode); return uiElementIsVisible(el.parentNode);
} }
function uiElementInSight(el) {
const clRect = el.getBoundingClientRect();
const windowHeight = window.innerHeight;
const isOnScreen = clRect.bottom > 0 && clRect.top < windowHeight;
return isOnScreen;
}