Skip to content

Commit

Permalink
split visibility method and sort instead
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thot-experiment committed May 19, 2023
1 parent e373fd0 commit 7b61acb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion javascript/dragdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 7 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 7b61acb

Please sign in to comment.