Procházet zdrojové kódy

Help: Include page names in the search

This fixes the problem before, where searching "Shell" would list
"Shell-vars" in the results, but searching "Shell-vars" would make it
disappear.

Also removed some now-unnecessary includes.
Sam Atkins před 3 roky
rodič
revize
85a54261b3

+ 15 - 3
Userland/Applications/Help/ManualModel.cpp

@@ -8,10 +8,7 @@
 #include "ManualNode.h"
 #include "ManualPageNode.h"
 #include "ManualSectionNode.h"
-#include <AK/ByteBuffer.h>
 #include <AK/Try.h>
-#include <LibCore/File.h>
-#include <LibGUI/FilteringProxyModel.h>
 
 static ManualSectionNode s_sections[] = {
     { "1", "User programs" },
@@ -49,6 +46,17 @@ Optional<GUI::ModelIndex> ManualModel::index_from_path(StringView path) const
     return {};
 }
 
+String ManualModel::page_name(const GUI::ModelIndex& index) const
+{
+    if (!index.is_valid())
+        return {};
+    auto* node = static_cast<const ManualNode*>(index.internal_data());
+    if (!node->is_page())
+        return {};
+    auto* page = static_cast<const ManualPageNode*>(node);
+    return page->name();
+}
+
 String ManualModel::page_path(const GUI::ModelIndex& index) const
 {
     if (!index.is_valid())
@@ -165,6 +173,10 @@ void ManualModel::update_section_node_on_toggle(const GUI::ModelIndex& index, co
 
 TriState ManualModel::data_matches(const GUI::ModelIndex& index, const GUI::Variant& term) const
 {
+    auto name = page_name(index);
+    if (name.contains(term.as_string()))
+        return TriState::True;
+
     auto view_result = page_view(page_path(index));
     if (view_result.is_error() || view_result.value().is_empty())
         return TriState::False;

+ 1 - 0
Userland/Applications/Help/ManualModel.h

@@ -23,6 +23,7 @@ public:
 
     Optional<GUI::ModelIndex> index_from_path(StringView) const;
 
+    String page_name(const GUI::ModelIndex&) const;
     String page_path(const GUI::ModelIndex&) const;
     String page_and_section(const GUI::ModelIndex&) const;
     ErrorOr<StringView> page_view(String const& path) const;