diff options
author | 2024-09-09 21:28:12 +0300 | |
---|---|---|
committer | 2024-09-09 21:28:12 +0300 | |
commit | 86f84e5fe42cc80458e220f141a604ceed03b4a1 (patch) | |
tree | dc7af288895d4294cd11f31694bfc604aaca5b4d | |
parent | 285e2490204a94355f924ad2f2dcc747ebb7b1a8 (diff) | |
parent | 359c06347e3512d59a8534cfa13ea60de027f932 (diff) | |
download | newsboat-86f84e5fe42cc80458e220f141a604ceed03b4a1.tar.gz newsboat-86f84e5fe42cc80458e220f141a604ceed03b4a1.tar.zst newsboat-86f84e5fe42cc80458e220f141a604ceed03b4a1.zip |
Merge pull request #2846 from dennisschagt/fix-resize-near-end-of-list
Fixup scroll_offset when list is changed/resized
-rw-r--r-- | include/listmovementcontrol.h | 3 | ||||
-rw-r--r-- | test/listmovementcontrol.cpp | 17 |
2 files changed, 19 insertions, 1 deletions
diff --git a/include/listmovementcontrol.h b/include/listmovementcontrol.h index ddcb7947..c29113b9 100644 --- a/include/listmovementcontrol.h +++ b/include/listmovementcontrol.h @@ -190,6 +190,9 @@ private: } else { set_position(0); } + } else { + // Make sure position and scroll_offset are both correct after list changes/resizes + set_position(current_position); } } diff --git a/test/listmovementcontrol.cpp b/test/listmovementcontrol.cpp index 85e40d64..e35a5f27 100644 --- a/test/listmovementcontrol.cpp +++ b/test/listmovementcontrol.cpp @@ -71,7 +71,7 @@ TEST_CASE("get_position() returns position of selected item in list", } } -TEST_CASE("on_lines_changed() makes sure `position < num_lines`", "[ListMovementControl]") +TEST_CASE("on_list_changed() makes sure `position < num_lines`", "[ListMovementControl]") { auto list_movement = ListMovementControl<ListStub>(dummyFormName, dummyForm, 0); ListStub& list = list_movement; @@ -100,6 +100,21 @@ TEST_CASE("on_lines_changed() makes sure `position < num_lines`", "[ListMovement } } } + + GIVEN("a list of 10 items, where the 10th itemn is selected") { + list.num_lines = 10; + list_movement.set_position(9); + + WHEN("the height of the viewport is reduced to 7") { + list.height = 7; + list.on_list_changed(); + + THEN("the scroll_offset is updated to keep the same item in view") { + REQUIRE(list.position == 9); + REQUIRE(list.scroll_offset == 3); + } + } + } } TEST_CASE("move_up() moves up by 1 line, and respects `wrap_scroll`", |