Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
MKadaner committed Jan 24, 2024
1 parent 8dde8e2 commit 4073298
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions far/vmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<int, Shifts.size()> 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 };
Expand Down

0 comments on commit 4073298

Please sign in to comment.