mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
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:
parent
f9d8e42636
commit
10700ca4c1
3 changed files with 34 additions and 32 deletions
|
@ -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; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue