mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +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
Notes:
sideshowbarker
2024-07-17 04:10:16 +09:00
Author: https://github.com/tcl3
Commit: 10700ca4c1
Pull-request: https://github.com/SerenityOS/serenity/pull/18244
Reviewed-by: https://github.com/ADKaster ✅
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