From 40732985f87942d10d470e840d8f01339cca8677 Mon Sep 17 00:00:00 2001 From: "Michael Z. Kadaner" Date: Tue, 23 Jan 2024 20:26:34 -0800 Subject: [PATCH] WIP --- far/vmenu.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/far/vmenu.cpp b/far/vmenu.cpp index 36be448925..3368fdfcb9 100644 --- a/far/vmenu.cpp +++ b/far/vmenu.cpp @@ -401,6 +401,19 @@ namespace return true; } + int adjust_hpos_shift(const int Shift, const int Left, const int Right, const int TextAreaWidth) + { + if (Right <= 0) + return Shift <= 0 ? 0 : Shift - Right; + if (Left >= TextAreaWidth) + return Shift >= 0 ? 0 : Shift - (Left - TextAreaWidth); + if (Shift <= 0) + return std::max(Shift, 1 - Right); + if (Shift >= 0) + return std::min(Shift, TextAreaWidth - Left - 1); + return Shift; + } + int adjust_en_bloc_shift(const int Shift, const int EnBlocHScrollDiscriminator, const int TextAreaWidth) { assert(TextAreaWidth > 0); @@ -3664,6 +3677,36 @@ TEST_CASE("list.hpos.classifier") } } +TEST_CASE("adjust.hpos.shift") +{ + static constexpr int TextAreaWidth{ 10 }; + static constexpr std::array Shifts{ -10 }; + static const struct test_data + { + int Left; + int Right; + std::array Expected; + } TestDataPoints[] = + { + { -5, { { 0, 0 }, { -7, 0 }, { -5, 0 }, { -1, 0 }, { 1, 6 }, { 3, 8 }, { 10, 15 }, { 15, 20 }, } }, + { 0, { { 0, 0 }, { -7, 0 }, { -5, 0 }, { -1, 0 }, { 1, 1 }, { 3, 3 }, { 10, 10 }, { 15, 15 }, } }, + { 1, { { 0, 0 }, { -7, -7 }, { -5, -5 }, { -1, -1 }, { 1, 1 }, { 3, 3 }, { 10, 10 }, { 15, 15 }, } }, + { 5, { { 0, 0 }, { -7, -7 }, { -5, -5 }, { -1, -1 }, { 1, 1 }, { 3, 3 }, { 10, 10 }, { 15, 15 }, } }, + { 10, { { 0, 0 }, { -7, -7 }, { -5, -5 }, { -1, -1 }, { 1, 0 }, { 3, 0 }, { 10, 0 }, { 15, 0 }, } }, + { 15, { { 0, 0 }, { -7, -12 }, { -5, -10 }, { -1, -6 }, { 1, 0 }, { 3, 0 }, { 10, 0 }, { 15, 0 }, } }, + }; + + for (const auto& TestDataPoint : TestDataPoints) + { + for (const auto& ShiftAndExpected : TestDataPoint.ShiftAndExpectedList) + { + REQUIRE(ShiftAndExpected.second == adjust_en_bloc_shift(ShiftAndExpected.first, TestDataPoint.EnBlocHScrollDiscriminator, TextAreaWidth)); + } + } + + // adjust_hpos_shift +} + TEST_CASE("adjust.en.bloc.shift") { static constexpr int TextAreaWidth{ 10 };