mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03: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:
parent
bb8bd48dc0
commit
1f0f96e6d7
Notes:
sideshowbarker
2024-07-16 23:23:43 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/1f0f96e6d7 Pull-request: https://github.com/SerenityOS/serenity/pull/17723 Reviewed-by: https://github.com/trflynn89
@ -10,6 +10,7 @@ compile_gml(CharacterSearchWindow.gml CharacterSearchWindowGML.h character_searc
|
||||
set(SOURCES
|
||||
CharacterMapWidget.cpp
|
||||
CharacterSearchWidget.cpp
|
||||
SearchCharacters.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
25
Userland/Applications/CharacterMap/SearchCharacters.cpp
Normal file
25
Userland/Applications/CharacterMap/SearchCharacters.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "SearchCharacters.h"
|
||||
#include <LibUnicode/CharacterTypes.h>
|
||||
|
||||
void for_each_character_containing(StringView query, Function<IterationDecision(u32 code_point, DeprecatedString const& display_name)> callback)
|
||||
{
|
||||
DeprecatedString uppercase_query = query.to_uppercase_string();
|
||||
StringView uppercase_query_view = uppercase_query.view();
|
||||
constexpr u32 maximum_code_point = 0x10FFFF;
|
||||
// FIXME: There's probably a better way to do this than just looping, but it still only takes ~150ms to run for me!
|
||||
for (u32 code_point = 1; code_point <= maximum_code_point; ++code_point) {
|
||||
if (auto maybe_display_name = Unicode::code_point_display_name(code_point); maybe_display_name.has_value()) {
|
||||
auto display_name = maybe_display_name.release_value();
|
||||
if (display_name.contains(uppercase_query_view, AK::CaseSensitivity::CaseSensitive)) {
|
||||
if (callback(code_point, move(display_name)) == IterationDecision::Break)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
@ -7,20 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <LibUnicode/CharacterTypes.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/IterationDecision.h>
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_character_containing(StringView query, Callback callback)
|
||||
{
|
||||
DeprecatedString uppercase_query = query.to_uppercase_string();
|
||||
StringView uppercase_query_view = uppercase_query.view();
|
||||
constexpr u32 maximum_code_point = 0x10FFFF;
|
||||
// FIXME: There's probably a better way to do this than just looping, but it still only takes ~150ms to run for me!
|
||||
for (u32 code_point = 1; code_point <= maximum_code_point; ++code_point) {
|
||||
if (auto maybe_display_name = Unicode::code_point_display_name(code_point); maybe_display_name.has_value()) {
|
||||
auto display_name = maybe_display_name.release_value();
|
||||
if (display_name.contains(uppercase_query_view, AK::CaseSensitivity::CaseSensitive))
|
||||
callback(code_point, move(display_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
void for_each_character_containing(StringView query, Function<IterationDecision(u32 code_point, DeprecatedString const& display_name)> callback);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
@ -28,6 +28,7 @@ static void search_and_print_results(DeprecatedString const& query)
|
||||
builder.append(display_name);
|
||||
outln(builder.string_view());
|
||||
result_count++;
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
if (result_count == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user