aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dennis van der Schagt <dennisschagt@gmail.com> 2024-09-08 19:25:09 +0200
committerGravatar Dennis van der Schagt <dennisschagt@gmail.com> 2024-09-08 19:48:18 +0200
commit359c06347e3512d59a8534cfa13ea60de027f932 (patch)
treeb6a26c5e87b7d87aec0bd854db2b732ca31976b2
parentbe8cca9934b0e1438175f482dcce4373bf4d13d2 (diff)
downloadnewsboat-359c06347e3512d59a8534cfa13ea60de027f932.tar.gz
newsboat-359c06347e3512d59a8534cfa13ea60de027f932.tar.zst
newsboat-359c06347e3512d59a8534cfa13ea60de027f932.zip
Fixup scroll_offset when list is changed/resized
-rw-r--r--include/listmovementcontrol.h3
-rw-r--r--test/listmovementcontrol.cpp17
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`",