aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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`",