mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-03 21:10:30 +00:00
PDFViewer: Fix parent_index() implementation in OutlineModel
The previous implementation had some repeated code, and wasn't really working (because the OutlineItem.parent member was never populated). In fact, when navigating with the up/down arrows in the associted TreeView one could experience some funky behavior. Now that we store OutlineItem's parents, we are fixing the implementation for parent_index(), which was comparing the parent siblings against the item's outline item instead of to its parent.
This commit is contained in:
parent
6df9aa8f2c
commit
c76564b533
Notes:
sideshowbarker
2024-07-17 09:47:09 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/c76564b533 Pull-request: https://github.com/SerenityOS/serenity/pull/16550
1 changed files with 6 additions and 13 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include "OutlineModel.h"
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <LibGfx/Font/FontDatabase.h>
|
||||
|
||||
ErrorOr<NonnullRefPtr<OutlineModel>> OutlineModel::create(NonnullRefPtr<PDF::OutlineDict> const& outline)
|
||||
|
@ -73,19 +74,11 @@ GUI::ModelIndex OutlineModel::parent_index(const GUI::ModelIndex& index) const
|
|||
if (!parent)
|
||||
return {};
|
||||
|
||||
if (parent->parent) {
|
||||
auto& grandparent = parent->parent;
|
||||
for (size_t i = 0; i < grandparent->children.size(); i++) {
|
||||
auto* sibling = &grandparent->children[i];
|
||||
if (sibling == index.internal_data())
|
||||
return create_index(static_cast<int>(i), 0, sibling);
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < m_outline->children.size(); i++) {
|
||||
auto* sibling = &m_outline->children[i];
|
||||
if (sibling == index.internal_data())
|
||||
return create_index(static_cast<int>(i), 0, sibling);
|
||||
}
|
||||
NonnullRefPtrVector<PDF::OutlineItem> parent_siblings = (parent->parent ? parent->parent->children : m_outline->children);
|
||||
for (size_t i = 0; i < parent_siblings.size(); i++) {
|
||||
auto* parent_sibling = &parent_siblings[i];
|
||||
if (parent_sibling == parent.ptr())
|
||||
return create_index(static_cast<int>(i), index.column(), parent.ptr());
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
|
|
Loading…
Reference in a new issue