Skip to content

Outline currently selected image #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

CreativeAlloy
Copy link

This new logic adds an outline to the currently selected image, whether from the image history or the current image batch.

More specifically, I have modified three files with the following code:

  • genpage.css, which now contains style code for .image-block-selected, the outline using var --emphasis' color code to ensure that it's consistent with the current loaded theme.
  • currentimagehandler.js, which now contains logic within function clickImageInBatch(div) that, upon clicking any image, removes the outline from any previously selected image, and adds the latest clicked image to the classList instead. Furthermore, some additional logic uses the existing "curImg.dataset.batch_id = 'history';" code to make an if(){} check, where if the batchId is NOT history, the selector will be removed from the image history as well.
  • imagehistory.js, with similar logic to remove and add images into the classList.

There's also a few line breaks removed before some "else"s, which I left as they were. I can easily go back and reinsert the line breaks if desired.

Attached example images to showcase what this looks like with the default dark theme.

image
image

This new logic adds an outline to the currently selected image, whether from the image history or the current image batch.
@@ -237,6 +237,13 @@ function toggleShowLoadSpinners() {
}

function clickImageInBatch(div) {
// Remove 'image-block-selected' from all image-blocks in the batch
document.querySelectorAll('#current_image_batch .image-block-selected').forEach(function (block) {
Copy link
Member

Choose a reason for hiding this comment

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

Please use standard foreach not functional forEach.
ie, foreach (let block of document.queryetc)

Copy link
Member

Choose a reason for hiding this comment

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

Also this should probably be current_image_batch querySelectorAll, not document query that then only matches within current_image_batch

@@ -237,6 +237,13 @@ function toggleShowLoadSpinners() {
}

function clickImageInBatch(div) {
// Remove 'image-block-selected' from all image-blocks in the batch
Copy link
Member

Choose a reason for hiding this comment

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

these comments are redundant

@@ -245,6 +252,7 @@ function clickImageInBatch(div) {
setCurrentImage(div.dataset.src, div.dataset.metadata, div.dataset.batch_id ?? '', imgElem && imgElem.dataset.previewGrow == 'true', false, true, div.dataset.is_placeholder == 'true');
}


Copy link
Member

Choose a reason for hiding this comment

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

minor stray edit

@@ -369,8 +377,7 @@ function shiftToNextImagePreview(next = true, expand = false) {
let newIndex = index + (next ? 1 : -1);
if (newIndex < 0) {
newIndex = divs.length - 1;
}
else if (newIndex >= divs.length) {
} else if (newIndex >= divs.length) {
Copy link
Member

Choose a reason for hiding this comment

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

no put those back

@@ -802,6 +816,26 @@ function setCurrentImage(src, metadata = '', batchId = '', previewGrow = false,
curImg.appendChild(img);
curImg.appendChild(extrasWrapper);
}

// Only remove selection from image history if we're not selecting a history image
if (batchId !== 'history') {
Copy link
Member

Choose a reason for hiding this comment

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

!=

outline-offset: -2px;
z-index: 2;
}
.image-block-selected {
Copy link
Member

Choose a reason for hiding this comment

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

why is this here twice

newIndex = 0;
}
let newImg = imgs[newIndex];
let block = findParentOfClass(newImg, 'image-block');
for (let block of getRequiredElementById('current_image_batch').querySelectorAll('.image-block-selected')) {
Copy link
Member

Choose a reason for hiding this comment

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

I think setting the selection here is redundant if setCurrentImage is going to replace it right after anyway?

@@ -139,6 +139,10 @@ function describeImage(image) {
function selectImageInHistory(image, div) {
lastHistoryImage = image.data.src;
lastHistoryImageDiv = div;
for (let selected of document.querySelectorAll('.browser-list-entry.image-block-selected, .browser-details-list-entry.image-block-selected, .image-block.image-block-selected, .model-block.image-block-selected')) {
Copy link
Member

@mcmonkey4eva mcmonkey4eva May 14, 2025

Choose a reason for hiding this comment

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

Same as other comment, this will be overwritten by setCurrentImage?

EDIT: Oh, it's... skipped if batchId == history. But then... if you arrow key through history, it'll just be selected wrongly I think?
Having it centrally maintained in setCurrentImage is probably ideal

Copy link
Author

Choose a reason for hiding this comment

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

I didn't know you could arrow key through history. Perhaps this needed more time in the oven (and fewer merge conflicts). Will try to edit asap. Thanks for the detailed feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants