From b8dc05a08e179f7e4dddcd03e3160a25e90f9bc7 Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Sun, 18 Dec 2022 21:11:29 +0800 Subject: [PATCH] PDFViewer: Fix indexing error in ErrorsView I confused myself when implementing this, plus I tested using pages that had errors in pages 1 and 2, so the index and the number of the page (internally represented as 0-indexed) was always the same. When opening files with errors on higher pages it became evident that there was an issue with how I was reading the errors per page from the corresponding ModelIndex object. --- Userland/Applications/PDFViewer/PDFViewerWidget.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index c779a3604f..4747b277ee 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -49,8 +49,7 @@ public: return static_cast(m_paged_errors.size()); } if (!index.parent().is_valid()) { - auto errors_in_page = m_paged_errors.get(index.row()).release_value().size(); - return static_cast(errors_in_page); + return static_cast(error_count_in_page(index)); } return 0; } @@ -103,7 +102,7 @@ public: case Columns::Page: return m_pages_with_errors[index.row()] + 1; case Columns::Message: - return DeprecatedString::formatted("{} errors", m_paged_errors.get(index.row()).release_value().size()); + return DeprecatedString::formatted("{} errors", error_count_in_page(index)); default: VERIFY_NOT_REACHED(); } @@ -149,6 +148,13 @@ private: return count; } + size_t error_count_in_page(GUI::ModelIndex const& index) const + { + VERIFY(!index.parent().is_valid()); + auto page = m_pages_with_errors[index.row()]; + return m_paged_errors.get(page).release_value().size(); + } + Vector m_pages_with_errors; PagedErrors m_paged_errors; };