Skip to content
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

fix(selection list): update indexes after option removed #4464

Conversation

TomJGooding
Copy link
Contributor

@TomJGooding TomJGooding commented Apr 29, 2024

Fixes #4462.

I've added a basic test that the index is updated, but I'm not sure if you need a regression test that actually replicates the issue above?

Please review the following checklist.

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

@TomJGooding TomJGooding marked this pull request as ready for review April 29, 2024 22:08
Copy link

@jvllmr jvllmr left a comment

Choose a reason for hiding this comment

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

I tested your change with the example code from my issue and it works wonderfully. Thanks a lot! 💯

@@ -646,6 +646,11 @@ def _remove_option(self, index: int) -> None:
option = self.get_option_at_index(index)
self._deselect(option.value)
del self._values[option.value]
# Decrement index of options after the one we just removed.
Copy link
Member

@darrenburns darrenburns May 2, 2024

Choose a reason for hiding this comment

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

Maybe a separate issue (or not an issue at all if I'm missing something), but this makes me wonder why the highlighted index wouldn't be decremented if it appears below the removed option.

Copy link
Member

Choose a reason for hiding this comment

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

Actually from a skim, I'm guessing it might be that the highlight is applied based on the ID of the option rather than the index. It's just converted to an ID via a validator.

Copy link
Member

@darrenburns darrenburns left a comment

Choose a reason for hiding this comment

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

Thanks!

@darrenburns darrenburns merged commit 17e975d into Textualize:main May 2, 2024
20 checks passed
@TomJGooding TomJGooding deleted the fix-selection-list-update-indexes-after-option-removed branch May 5, 2024 08:02
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.

SelectionList weird behavior when removing options in its own event handler until freeze
3 participants