Skip to content

Commit

Permalink
WIP: Viewer::HorizontalScroll should be two different functions depen…
Browse files Browse the repository at this point in the history
…ding on (m_DisplayMode == VMT_TEXT)
  • Loading branch information
MKadaner committed Feb 4, 2024
1 parent f86db3b commit eddd5e1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions far/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,56 @@ void Viewer::AdjustBytesPerLine(int const Amount)
Show();
}

void Viewer::HorizontalScroll(const int Shift, const bool LeftKeyPressed)
{
if (!ViewFile || Shift <= 0) return;

const auto ShiftContentLeft{ LeftKeyPressed == Global->Opt->VMenu.SwapHScrollDirection };
if (ShiftContentLeft)
{
if (m_DisplayMode == VMT_TEXT)
{
if (!m_Wrap)
{
LeftPos = std::min(LeftPos + Shift, static_cast<long long>(MaxViewLineSize()));
Show();
}
return;
}

if (Shift > 1)
{
const auto CharSize = GetModeDependentCharSize();
FilePos -= FilePos % CharSize;
FilePos = FilePos < FileSize - CharSize? FilePos + CharSize : FileSize - 1;
FilePos -= FilePos % CharSize;
Show();
return;
}
}
else // Shift Content Right
{
if (m_DisplayMode == VMT_TEXT)
{
if (!m_Wrap)
{
LeftPos = std::max(LeftPos - Shift, 0LL);
Show();
}
return;
}

if (Shift > 1)
{
const auto CharSize = GetModeDependentCharSize();
FilePos = FilePos > CharSize? FilePos - CharSize : 0;
FilePos -= FilePos % CharSize;
Show();
return;
}
}
}

struct Viewer::ViewerUndoData
{
ViewerUndoData(long long UndoAddr, long long UndoLeft):
Expand Down
2 changes: 2 additions & 0 deletions far/viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class Viewer:public SimpleScreenObject
int CalculateMaxBytesPerLineByScreenWidth() const;
void AdjustBytesPerLine(int Amount);

void HorizontalScroll(int Shift, bool LeftKeyPressed);

friend class FileViewer;

Options::ViewerOptions ViOpt;
Expand Down

0 comments on commit eddd5e1

Please sign in to comment.