From 116b40f28c76482b1830a6194356dd11bdb25e93 Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Fri, 16 Sep 2022 11:20:15 -0700 Subject: [PATCH] [bottom_status] fix out-of-bounds when with word-wrap Related to #1058 --- src/bottom_status_source.cc | 25 ++++++++++--------------- src/listview_curses.hh | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/bottom_status_source.cc b/src/bottom_status_source.cc index 81b441f9..05bc88ed 100644 --- a/src/bottom_status_source.cc +++ b/src/bottom_status_source.cc @@ -69,21 +69,16 @@ bottom_status_source::update_line_number(listview_curses* lc) sf.set_value(" L%'d", (int) lc->get_top()); } - if (lc->get_inner_height() > 0) { - std::vector rows(1); - - lc->get_data_source()->listview_value_for_rows( - *lc, lc->get_top(), rows); - const auto& sa = rows[0].get_attrs(); - auto error_wrapper = get_string_attr(sa, SA_ERROR); - if (error_wrapper) { - this->bss_line_error.set_value(error_wrapper.value().get()); - } else { - this->bss_line_error.clear(); - } - } else { - this->bss_line_error.clear(); - } + this->bss_line_error.set_value( + lc->map_top_row([](const attr_line_t& top_row) + -> nonstd::optional { + const auto& sa = top_row.get_attrs(); + auto error_wrapper = get_string_attr(sa, SA_ERROR); + if (error_wrapper) { + return error_wrapper.value().get(); + } + return nonstd::nullopt; + }).value_or("")); } void diff --git a/src/listview_curses.hh b/src/listview_curses.hh index 9e8f301f..1797bb78 100644 --- a/src/listview_curses.hh +++ b/src/listview_curses.hh @@ -244,7 +244,7 @@ public: auto map_top_row(F func) -> typename std::result_of::type { - if (this->get_inner_height() == 0) { + if (this->lv_top >= this->get_inner_height()) { return nonstd::nullopt; }