1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

CharacterMap: Limit the number of results from the GUI character search

Past a few hundred matches, the search is no longer useful, and takes an
excessive amount of time to recalculate the column widths by measuring
thousands of pieces of text. 250 seems like a reasonable arbitrary
limit, and keeps things nice and snappy. :^)
This commit is contained in:
Sam Atkins 2023-03-05 15:30:36 +00:00 committed by Andreas Kling
parent bb8bd48dc0
commit 1f0f96e6d7
5 changed files with 39 additions and 18 deletions

View file

@ -84,6 +84,7 @@ void CharacterSearchWidget::search()
// TODO: Sort the results nicely. They're sorted by code-point for now, which is easy, but not the most useful.
// Sorting intelligently in a style similar to Assistant would be nicer.
// Note that this will mean limiting the number of results some other way.
auto& model = static_cast<CharacterSearchModel&>(*m_results_table->model());
model.clear();
auto query = m_search_input->text();
@ -94,5 +95,11 @@ void CharacterSearchWidget::search()
builder.append_code_point(code_point);
model.add_result({ code_point, builder.to_deprecated_string(), move(display_name) });
// Stop when we reach 250 results.
// This is already too many for the search to be useful, and means we don't spend forever recalculating the column size.
if (model.row_count({}) >= 250)
return IterationDecision::Break;
return IterationDecision::Continue;
});
}