Skip to content

Conversation

@srujanyadav-hyp
Copy link

Fixes a crash that occurs when clearing search results in streams or topics view when the underlying list is empty. The application would raise 'IndexError: Can't set focus, ListBox is empty' when attempting to restore focus position after clearing a search. Added checks before calling set_focus() in 4 locations:

  • StreamsView.keypress() CLEAR_SEARCH handler
  • TopicsView.keypress() CLEAR_SEARCH handler
  • TopicsView.update_topics_list() (2 locations) The fix verifies the list is not empty before attempting to set focus, preventing the crash while maintaining expected behavior when lists contain items.

What does this PR do, and why?

Outstanding aspect(s)

  • [ ]

External discussion & connections

  • Discussed in #zulip-terminal in topic
  • Fully fixes #
  • Partially fixes issue #
  • Builds upon previous unmerged work in PR #
  • Is a follow-up to work in PR #
  • Requires merge of PR #
  • Merge will enable work on #

How did you test this?

  • Manually - Behavioral changes
  • Manually - Visual changes
  • Adapting existing automated tests
  • Adding automated tests for new behavior (or missing tests)
  • Existing automated tests should already cover this (only a refactor of tested code)

Self-review checklist for each commit

  • It is a minimal coherent idea
  • It has a commit summary following the documented style (title & body)
  • It has a commit summary describing the motivation and reasoning for the change
  • It individually passes linting and tests
  • It contains test additions for any new behavior
  • It flows clearly from a previous branch commit, and/or prepares for the next commit

Visual changes

Fixes a crash that occurs when clearing search results in streams or
topics view when the underlying list is empty. The application would
raise 'IndexError: Can't set focus, ListBox is empty' when attempting
to restore focus position after clearing a search.
Added checks before calling set_focus() in 4 locations:
- StreamsView.keypress() CLEAR_SEARCH handler
- TopicsView.keypress() CLEAR_SEARCH handler
- TopicsView.update_topics_list() (2 locations)
The fix verifies the list is not empty before attempting to set focus,
preventing the crash while maintaining expected behavior when lists
contain items.
@zulipbot zulipbot added the size: S [Automatic label added by zulipbot] label Nov 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S [Automatic label added by zulipbot]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants