Rework the Search popup and highlight what matched

- The search field is a single-line field, so Enter no longer adds a
  line break that made every search come up empty.
- The field, button and list use real font sizes from the theme instead
  of being drawn at half size and scaled up, so the text is sharp, and
  everything fits inside the panel.
- Results have alternating row backgrounds like the other lists, a count
  ("3 of 1045 soundtracks") and a message when nothing matches.
- The letters that matched are highlighted.
- Searches shorter than Settings.LETTERS_FOR_LOOSE_SEARCH (3) only find
  names that contain the text, instead of names with the letters far
  apart, which matched most of the library. The Statistics tab uses the
  same search.
This commit is contained in:
Sansan committed 2026-10-07 14:53:51 +02:00
1 parent 13fdb3f68c
commit 845d08c260
12 files changed
+2063 -808

No files matched your search

+25 -11
View File
@@ -63,16 +63,30 @@ func test_clean_term() -> void:
assert_str(SoundtrackSearch.clean_term("Ys I & II")).is_equal("ysiandii")
func test_search_popup_searches_with_soundtrack_search() -> void:
var popup: SearchPopup = auto_free(load("res://popups/SearchPopup.tscn").instantiate())
add_child(popup)
popup.set_soundtracks(["Chrono Trigger", "Super Mario 64"])
popup.show_all_soundtracks()
func test_short_search_only_finds_names_containing_it() -> void:
# "sm" is in order in "Super Mario 64" but not next to each other
assert_int(Settings.LETTERS_FOR_LOOSE_SEARCH).is_equal(3)
assert_array(_search.find_matches("sm")).is_empty()
assert_array(_search.find_matches("smr")).contains_exactly(["Super Mario 64"])
popup.perform_search("smr")
var shown: Array[String] = []
for label: Label in popup.search_list.get_children():
if label.visible:
shown.append(label.text)
assert_array(shown).contains_exactly(["Super Mario 64"])
func test_matched_letters_of_plain_match() -> void:
assert_array(SoundtrackSearch.matched_letters("Chrono Trigger", "trig")) \
.contains_exactly([7, 8, 9, 10])
func test_matched_letters_ignoring_spaces_and_special_characters() -> void:
# "mario and luigi" matches "Mario & Luigi" with & read as "and"
var letters: Array[int] = SoundtrackSearch.matched_letters(
"Mario & Luigi: Superstar Saga", "mario and luigi")
assert_array(letters).contains_exactly([0, 1, 2, 3, 4, 6, 8, 9, 10, 11, 12])
func test_matched_letters_in_order() -> void:
assert_array(SoundtrackSearch.matched_letters("Super Mario 64", "smr")) \
.contains_exactly([0, 6, 8])
func test_matched_letters_of_no_match() -> void:
assert_array(SoundtrackSearch.matched_letters("Chrono Trigger", "metroid")).is_empty()
assert_array(SoundtrackSearch.matched_letters("Super Mario 64", "sm")).is_empty()