Skip to content

SearchableList: re-rank while typing, and make Enter confirm the best match - #579

Merged
matt-edmondson merged 3 commits into
mainfrom
copilot/fix-searchablelist-popup-issue
Oct 3, 2026
Merged

matt-edmondson merged 3 commits into
mainfrom
copilot/fix-searchablelist-popup-issue

Conversation

Copilot AI commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

SearchableList<TItem> drew its search box with ImGuiInputTextFlags.EnterReturnsTrue. With that flag, ImGui only writes the edited text back on Enter or when the box loses focus, so searchTerm stayed "" while the user typed and the list never re-ranked. Enter then confirmed cachedValue ?? selectedItem before the list was ranked against the new term. That was the first unranked row, or the default item if one was passed. Typing Cherry and pressing Enter confirmed Apple.

Changes (ImGui.Popups/SearchableList.cs)

  • Search term updates live: the search box no longer uses EnterReturnsTrue, so searchTerm changes on every keystroke and the ranking follows it.
  • Enter is detected separately: it counts when Enter/KeypadEnter is pressed while the box is active or was just deactivated. Single-line Enter deactivates the box in that same frame, so checking only for active would miss it.
  • Enter is handled after ranking: it runs after the list box has ended, using the ranked list.
    • With text typed, it confirms the top-ranked match, even if a different item was the current choice.
    • With nothing typed, behaviour is unchanged: it confirms the current choice, or the first item if there is none.
  • The ranked result is now held in a list, because it is read twice: once to draw the rows and once for Enter.
ImGui.InputText("##Search", ref searchTerm, 255);
bool enterPressed = (ImGui.IsItemActive() || ImGui.IsItemDeactivated())
	&& (ImGui.IsKeyPressed(ImGuiKey.Enter) || ImGui.IsKeyPressed(ImGuiKey.KeypadEnter));
// ...rank, draw list...
if (enterPressed)
{
	if (!string.IsNullOrEmpty(searchTerm) && sortedStrings.Count > 0)
	{
		cachedValue = itemLookup[sortedStrings[0]];
	}

	ConfirmSelectedItem();
}

Tests (tests/ImGui.Popups.Tests/SearchableListTests.cs)

New cases:

  • Typing Cherry moves the Cherry row above Apple.
  • Typing Cherry then pressing Enter confirms Cherry, with no current choice and with Apple as the current choice.
  • Enter with nothing typed confirms the current choice, or the first item when there is none.

The first three fail against the previous implementation.

Copilot AI and others added 2 commits October 1, 2026 10:06
…n Enter

Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com>
Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SearchableList popup to update ranking on search input SearchableList: re-rank while typing, and make Enter confirm the best match Oct 1, 2026
Copilot AI requested a review from matt-edmondson October 1, 2026 10:10
@matt-edmondson
matt-edmondson marked this pull request as ready for review October 2, 2026 13:01
@sonarqubecloud

sonarqubecloud Bot commented Oct 2, 2026

Copy link
Copy Markdown

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.

SearchableList popup: typing in the search box doesn't re-rank the list, and Enter confirms the first item instead of the best match

2 participants