1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:07:35 +00:00

Browser: Add option to filter entries in Storage Inspector

This commit is contained in:
Rafał Babiarz 2022-05-06 20:30:39 +02:00 committed by Linus Groh
parent d1e6dcfbc2
commit 6463bc7eb3
7 changed files with 87 additions and 11 deletions

View file

@ -6,6 +6,8 @@
#include "LocalStorageModel.h"
#include <AK/FuzzyMatch.h>
namespace Browser {
void LocalStorageModel::set_items(OrderedHashMap<String, String> map)
@ -26,6 +28,13 @@ void LocalStorageModel::clear_items()
did_update(DontInvalidateIndices);
}
int LocalStorageModel::row_count(GUI::ModelIndex const& index) const
{
if (!index.is_valid())
return m_local_storage_entries.size();
return 0;
}
String LocalStorageModel::column_name(int column) const
{
switch (column) {
@ -66,4 +75,20 @@ GUI::Variant LocalStorageModel::data(GUI::ModelIndex const& index, GUI::ModelRol
VERIFY_NOT_REACHED();
}
TriState LocalStorageModel::data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const
{
auto needle = term.as_string();
if (needle.is_empty())
return TriState::True;
auto const& keys = m_local_storage_entries.keys();
auto const& local_storage_key = keys[index.row()];
auto const& local_storage_value = m_local_storage_entries.get(local_storage_key).value_or({});
auto haystack = String::formatted("{} {}", local_storage_key, local_storage_value);
if (fuzzy_match(needle, haystack).score > 0)
return TriState::True;
return TriState::False;
}
}