Skip to content

Conversation

csehatt741
Copy link
Contributor

@csehatt741 csehatt741 commented Aug 17, 2025

Summary

A new feature was implemented to locate any images in the gallery via the image context menu.

  • NavigationApi was extended by two new functions, expandLeftPanel and expandRightPanel, to expand the right panel on which the image gallery located
  • two functions, collapse and expand, were extended in useCollapsibleGridviewPanel to check the status of the panel and only collapse/expand when it is required in order to avoid unnecessary resizing of the panel
  • useGalleryPanel custom hook was created to encapsulate gallery related configuration of useCollapsibleGridviewPanel
  • GalleryPanel was refactored to use useGalleryPanel custom hook
  • ImageMenuItemLocateInGalery image context menu item was created to locate any images in the gallery
  • SingleSelectionMenuItems was extended by the new ImageMenuItemLocateInGalery menu item
  • new tanslations, sentToCanvas and sentToUpscale, was added to en.json

Related Issues / Discussions

Closes #7867

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

@github-actions github-actions bot added the frontend PRs that change frontend files label Aug 17, 2025
@csehatt741
Copy link
Contributor Author

This is a simple and naive implementation, as isCollapsed and lastExpandedSize states are strictly local to any components using the useCollapsibleGridviewPanel hook. Currently, different components can only manipulate the same panel via NavigationApi without any information about that state.

To provide better user experience, state could be shared via Redux, but I'm not sure it is within the scope of this change.

Attila Cseh and others added 7 commits August 18, 2025 19:17
Three changes needed to make scrollIntoView and "Locate in Gallery" work
reliably.

1. Use setTimeout to work around race condition with scrollIntoView in
gallery.

It was possible to call scrollIntoView before react-virtuoso was ready.
I think react-virtuoso was initialized but hadn't rendered/measured its
items yet, so when we scroll to e.g. index 742, the items have a zero
height, so it doesn't actually scroll down. Then the items render.

Setting a timeout here defers the scroll until after the next event loop
cycle, by which time we expect react-virutoso to be ready.

2. Ensure the scollIntoView effect in gallery triggers any time the
selection is touched by making its dependency the array of selected
images, not just the last selected image name.

The "locate in gallery" functionality works by selecting an image.
There's a reactive effect in the gallery that runs when the last
selected image changes and scrolls it into view.

But if you already have an image selected, selecting it again will not
change the image name bc it is a string primitive. The useEffect ignores
the selection.

So, if you clicked "locate in gallery" on an image that was already
selected, it wouldn't be scrolled into view - even if you had already
scrolled away from it.

To work around this, the effect now uses the whole selection array as
its dependency. Whenever the selection changes, we get a new array,
which triggers the effect.

3. Gallery slice had some checks to avoid creating a new array of
selected image names in state when the selected images didn't change.

For example, if image "abc" was selected, and we selected "abc" again,
instead of creating a new array with the same "abc" image, we bailed
early. IIRC this optimization addressed a rerender issue long ago.

This optimization needs to be removed in order for fix invoke-ai#2 above to work.
We now _want_ a new array whenever selection is set - even if it didn't
actually change.
… locate

e.g. when on a tab that doesn't have a gallery, or the image is
intermediate
Copy link
Collaborator

@psychedelicious psychedelicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I made a number of changes to ensure the panels activate and the image gets scrolled-to reliably. See commits for more detail. Had to fight react a bit to make it work.

@psychedelicious psychedelicious merged commit f4aba52 into invoke-ai:main Aug 18, 2025
12 checks passed
@csehatt741 csehatt741 deleted the feat/locate-in-gallery branch August 19, 2025 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend PRs that change frontend files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[enhancement]: Add "Locate in Gallery"
2 participants