LibManual: Associate SubsectionNode with similarly named markdown file

For a subsection named `Foo` with a markdown file `Foo.md` in the same
directory, the document `Foo.md` will be returned when the subsection is
selected.

This prevents PageNodes and SubsectionNodes from sharing the same
name, which fixes an issue in Help where subsections could not be
navigated.
This commit is contained in:
Tim Ledbetter 2023-04-16 10:28:45 +01:00 committed by Andrew Kaster
commit 10700ca4c1
Notes: sideshowbarker 2024-07-17 04:10:16 +09:00
3 changed files with 34 additions and 32 deletions

View file

@ -10,31 +10,16 @@
namespace Manual {
SubsectionNode::SubsectionNode(NonnullRefPtr<SectionNode const> parent, StringView name)
SubsectionNode::SubsectionNode(NonnullRefPtr<SectionNode const> parent, StringView name, RefPtr<PageNode> page)
: SectionNode(name, name)
, m_parent(move(parent))
, m_page(move(page))
{
}
Node const* SubsectionNode::parent() const { return m_parent; }
PageNode const* SubsectionNode::document() const
{
auto maybe_siblings = parent()->children();
if (maybe_siblings.is_error())
return nullptr;
auto siblings = maybe_siblings.release_value();
for (auto const& sibling : siblings) {
if (&*sibling == this)
continue;
auto sibling_name = sibling->name();
if (sibling_name.is_error())
continue;
if (sibling_name.value() == m_name && is<PageNode>(*sibling))
return static_cast<PageNode const*>(&*sibling);
}
return nullptr;
}
PageNode const* SubsectionNode::document() const { return m_page; }
ErrorOr<String> SubsectionNode::name() const { return m_name; }