From 37eb9cfa369cadbb1d2259db94aaf3a3ff6115e4 Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Sun, 3 Sep 2023 07:43:19 -0700 Subject: [PATCH] [listview] fix a couple of glitches with the selection --- src/db_sub_source.cc | 4 ++-- src/hotkeys.cc | 14 ++++++++------ src/listview_curses.cc | 5 ++++- src/listview_curses.hh | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/db_sub_source.cc b/src/db_sub_source.cc index 1c105073..ed817431 100644 --- a/src/db_sub_source.cc +++ b/src/db_sub_source.cc @@ -52,7 +52,7 @@ db_label_source::text_value_for_line(textview_curses& tc, */ label_out.clear(); - if (row >= (int) this->dls_rows.size()) { + if (row < 0_vl || row >= (int) this->dls_rows.size()) { return; } for (int lpc = 0; lpc < (int) this->dls_rows[row].size(); lpc++) { @@ -85,7 +85,7 @@ db_label_source::text_attrs_for_line(textview_curses& tc, struct line_range lr(0, 0); const struct line_range lr2(0, -1); - if (row >= (int) this->dls_rows.size()) { + if (row < 0_vl || row >= (int) this->dls_rows.size()) { return; } auto alt_row_index = row % 4; diff --git a/src/hotkeys.cc b/src/hotkeys.cc index a27c20ac..0a56c1c8 100644 --- a/src/hotkeys.cc +++ b/src/hotkeys.cc @@ -380,12 +380,14 @@ handle_paging_key(int ch) case 'J': if (tc->is_selectable()) { - tc->toggle_user_mark(&textview_curses::BM_USER, - tc->get_selection()); - lnav_data.ld_select_start[tc] = tc->get_selection(); - lnav_data.ld_last_user_mark[tc] = tc->get_selection(); - if (tc->get_selection() + 1_vl < tc->get_inner_height()) { - tc->set_selection(tc->get_selection() + 1_vl); + if (tc->get_selection() >= 0_vl) { + tc->toggle_user_mark(&textview_curses::BM_USER, + tc->get_selection()); + lnav_data.ld_select_start[tc] = tc->get_selection(); + lnav_data.ld_last_user_mark[tc] = tc->get_selection(); + if (tc->get_selection() + 1_vl < tc->get_inner_height()) { + tc->set_selection(tc->get_selection() + 1_vl); + } } } else { if (lnav_data.ld_last_user_mark.find(tc) diff --git a/src/listview_curses.cc b/src/listview_curses.cc index c4648d6c..55aedf57 100644 --- a/src/listview_curses.cc +++ b/src/listview_curses.cc @@ -114,8 +114,11 @@ listview_curses::reload_data() } else if (this->lv_selection >= this->get_inner_height()) { this->set_selection(this->get_inner_height() - 1_vl); } else { - auto curr_sel = this->lv_selection; + auto curr_sel = this->get_selection(); + if (curr_sel == -1_vl) { + curr_sel = 0_vl; + } this->lv_selection = -1_vl; this->set_selection(curr_sel); } diff --git a/src/listview_curses.hh b/src/listview_curses.hh index 2ba69cd3..65b363c7 100644 --- a/src/listview_curses.hh +++ b/src/listview_curses.hh @@ -236,7 +236,7 @@ public: vis_line_t get_selection() const { - if (this->lv_selectable) { + if (this->lv_selectable && this->lv_selection != -1_vl) { return this->lv_selection; } return this->lv_top;