Skip to content

Commit

Permalink
revert of 5027.2 и 5028.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Sep 13, 2017
1 parent 7cba823 commit 6ba37ba
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 67 deletions.
4 changes: 4 additions & 0 deletions far/changelog
@@ -1,3 +1,7 @@
drkns 13.09.2017 20:19:28 +0100 - build 5029

1. Откат 5027.2 и 5028.1.

drkns 12.09.2017 21:04:02 +0100 - build 5028

1. Продолжение 0003481.
Expand Down
135 changes: 69 additions & 66 deletions far/help.cpp
Expand Up @@ -149,6 +149,8 @@ Help::Help(private_tag):
MsY(-1),
CurColor(colors::PaletteColorToFarColor(COL_HELPTEXT)),
CtrlTabSize(0),
LastStartPos(0),
StartPos(0),
MouseDown(false),
IsNewTopic(true),
m_TopicFound(false),
Expand Down Expand Up @@ -337,38 +339,25 @@ bool Help::ReadHelp(const string& Mask)
wchar_t PrevSymbol=0;
bool drawline = false;
wchar_t DrawLineChar = 0;
const size_t MaxLength = CanvasWidth();

size_t StartPos = 0;
const int MaxLength = CanvasWidth();

StartPos = 0;
LastStartPos = 0;
bool MacroProcess=false;
int MI=0;
string strMacroArea;

GetFileString GetStr(HelpFile, nCodePage);
const size_t StartSizeKeyName = 20;
size_t SizeKeyName = StartSizeKeyName;

// (Line, its StartPos)
// Keeping them together to prevent overwriting paragraph-specific StartPos
// with the one from the next paragraph, if any.
std::pair<string, size_t> SplitLine;
bool SplitLineBegin = false;

const auto& AddSplitLine = [this](const std::pair<string, size_t>& Line)
{
AddLine(Line.first, Line.second);
};

const auto& SplitLineLength = [this](const std::pair<string, size_t>& Line)
{
return StringLen(Line.first) + Line.second;
};
string strSplitLine;

bool InHeader = true;

for (;;)
{
const int RealMaxLength = MaxLength - StartPos;

if (!MacroProcess && !RepeatLastLine && !BreakProcess)
{
if (GetStr.GetString(strReadStr))
Expand All @@ -383,10 +372,10 @@ bool Help::ReadHelp(const string& Mask)
}
else
{
if (SplitLineLength(SplitLine) < MaxLength)
if (StringLen(strSplitLine)<MaxLength)
{
if (!SplitLine.first.empty())
AddSplitLine(SplitLine);
if (!strSplitLine.empty())
AddLine(strSplitLine);
}
else
{
Expand Down Expand Up @@ -483,7 +472,7 @@ bool Help::ReadHelp(const string& Mask)
size_t p1 = strReadStr.rfind(L'\n') + 1;
if (p1 > pos)
p1 = 0;
StartPos = StringLen(strReadStr.substr(p1, pos-p1));
LastStartPos = StringLen(strReadStr.substr(p1, pos-p1));
strReadStr.erase(pos, strCtrlStartPosChar.size());
}
}
Expand Down Expand Up @@ -522,7 +511,7 @@ bool Help::ReadHelp(const string& Mask)
goto m1;
}

if (!SplitLine.first.empty())
if (!strSplitLine.empty())
{
BreakProcess = true;
strReadStr.clear();
Expand Down Expand Up @@ -551,7 +540,7 @@ bool Help::ReadHelp(const string& Mask)
else
{
m1:
if (strReadStr.empty() && BreakProcess && SplitLine.first.empty())
if (strReadStr.empty() && BreakProcess && strSplitLine.empty())
break;

if (m_TopicFound)
Expand Down Expand Up @@ -586,11 +575,12 @@ bool Help::ReadHelp(const string& Mask)
if (NearTopicFound)
{
StartPos = 0;
LastStartPos = 0;
}

if ((!strReadStr.empty() && strReadStr[0]==L'$') && NearTopicFound && (PrevSymbol == L'$' || PrevSymbol == L'@'))
{
AddLine(strReadStr.data()+1, StartPos);
AddLine(strReadStr.data()+1);
FixCount++;
}
else
Expand All @@ -599,16 +589,17 @@ bool Help::ReadHelp(const string& Mask)

if (strReadStr.empty() || !Formatting)
{
if (!SplitLine.first.empty())
if (!strSplitLine.empty())
{
if (SplitLineLength(SplitLine) < MaxLength)
if (StringLen(strSplitLine)<RealMaxLength)
{
AddSplitLine(SplitLine);
SplitLine.first.clear();
AddLine(strSplitLine);
strSplitLine.clear();

if (StringLen(strReadStr) + StartPos < MaxLength)
if (StringLen(strReadStr)<RealMaxLength)
{
AddLine(strReadStr, StartPos);
AddLine(strReadStr);
LastStartPos = 0;
StartPos = 0;
continue;
}
Expand All @@ -618,13 +609,13 @@ bool Help::ReadHelp(const string& Mask)
}
else if (!strReadStr.empty())
{
if (StringLen(strReadStr) + StartPos < MaxLength)
if (StringLen(strReadStr)<RealMaxLength)
{
AddLine(strReadStr, StartPos);
AddLine(strReadStr);
continue;
}
}
else if (strReadStr.empty() && SplitLine.first.empty())
else if (strReadStr.empty() && strSplitLine.empty())
{
AddLine(L"");
continue;
Expand All @@ -633,23 +624,22 @@ bool Help::ReadHelp(const string& Mask)

if (!strReadStr.empty() && IsSpace(strReadStr[0]) && Formatting)
{
if (SplitLineLength(SplitLine) < MaxLength)
if (StringLen(strSplitLine)<RealMaxLength)
{
if (!SplitLine.first.empty())
if (!strSplitLine.empty())
{
AddSplitLine(SplitLine);
AddLine(strSplitLine);
StartPos = 0;
}

for (size_t nl = strReadStr.find(L'\n'); nl != string::npos; )
{
AddLine(strReadStr.substr(0, nl), StartPos);
AddLine(strReadStr.substr(0, nl));
strReadStr.erase(0, nl+1);
nl = strReadStr.find(L'\n');
}

SplitLine = { strReadStr, StartPos };
SplitLineBegin = true;

strSplitLine = strReadStr;
strReadStr.clear();
continue;
}
Expand All @@ -660,27 +650,28 @@ bool Help::ReadHelp(const string& Mask)
if (drawline)
{
drawline = false;
if (!SplitLine.first.empty())
if (!strSplitLine.empty())
{
AddSplitLine(SplitLine);
AddLine(strSplitLine);
StartPos = 0;
}
wchar_t userSeparator[4] = { L' ', (DrawLineChar ? DrawLineChar : BoxSymbols[BS_H1]), L' ', 0 }; // left-center-right
int Mul = (DrawLineChar == L'@' || DrawLineChar == L'~' || DrawLineChar == L'#' ? 2 : 1); // Double. See Help::OutString
AddLine(MakeSeparator(CanvasWidth() * Mul - (Mul>>1), 12, userSeparator)); // 12 -> UserSep horiz
strReadStr.clear();
SplitLine.first.clear();
strSplitLine.clear();
continue;
}

if (!RepeatLastLine)
{
if (!SplitLine.first.empty())
SplitLine.first += L' ';
if (!strSplitLine.empty())
strSplitLine += L' ';

SplitLine.first += strReadStr;
strSplitLine += strReadStr;
}

if (SplitLineLength(SplitLine) < MaxLength)
if (StringLen(strSplitLine)<RealMaxLength)
{
if (strReadStr.empty() && BreakProcess)
goto m1;
Expand All @@ -690,26 +681,34 @@ bool Help::ReadHelp(const string& Mask)

int Splitted=0;

for (int I=(int)SplitLine.first.size()-1; I > 0; I--)
for (int I=(int)strSplitLine.size()-1; I > 0; I--)
{
if (I > 0 && SplitLine.first[I] == L'~')
if (I > 0 && strSplitLine[I]==L'~' && strSplitLine[I - 1] == L'~')
{
I--;
continue;
}

if (I > 0 && strSplitLine[I] == L'~' && strSplitLine[I - 1] != L'~')
{
do
{
I--;
while (I > 0 && SplitLine.first[I] != L'~');
}
while (I > 0 && strSplitLine[I] != L'~');

continue;
}

if (SplitLine.first[I] == L' ')
if (strSplitLine[I] == L' ')
{
string FirstPart = SplitLine.first.substr(0, I);
if (StringLen(FirstPart) + SplitLine.second < MaxLength)
string FirstPart = strSplitLine.substr(0, I);
if (StringLen(FirstPart) < RealMaxLength)
{
AddLine(FirstPart, SplitLineBegin? 0 : SplitLine.second);
SplitLineBegin = false;
SplitLine.first.erase(1, I);
SplitLine.first[0] = L' ';
HighlightsCorrection(SplitLine.first);
AddLine(FirstPart);
strSplitLine.erase(1, I);
strSplitLine[0] = L' ';
HighlightsCorrection(strSplitLine);
Splitted=TRUE;
break;
}
Expand All @@ -718,15 +717,19 @@ bool Help::ReadHelp(const string& Mask)

if (!Splitted)
{
AddSplitLine(SplitLine);
SplitLine.first.clear();
AddLine(strSplitLine);
strSplitLine.clear();
}
else
{
StartPos = LastStartPos;
}
}
}

if (BreakProcess)
{
if (!SplitLine.first.empty())
if (!strSplitLine.empty())
goto m1;

break;
Expand All @@ -748,9 +751,9 @@ bool Help::ReadHelp(const string& Mask)
return m_TopicFound;
}

void Help::AddLine(const string& Line, size_t Offset)
void Help::AddLine(const string& Line)
{
const auto Width = Offset && !Line.empty() && Line[0] == L' '? Offset - 1 : Offset;
const auto Width = StartPos && !Line.empty() && Line[0] == L' '? StartPos - 1 : StartPos;
HelpList.emplace_back(string(Width, L' ') + Line);
}

Expand Down Expand Up @@ -1070,7 +1073,7 @@ void Help::OutString(string_view Str)
while (OutPos<(int)(std::size(OutStr)-10))
{
if (!Str.empty() && (
(Str[0]==L'~' && Str[1]==L'~') ||
(Str[0]==L'~' && Str[1]==L'~') ||
(Str[0]==L'#' && Str[1]==L'#') ||
(Str[0]==L'@' && Str[1]==L'@') ||
(cColor && Str[0]==cColor && Str[1]==cColor)
Expand Down
5 changes: 4 additions & 1 deletion far/help.hpp
Expand Up @@ -69,7 +69,7 @@ class Help:public Modal
virtual string GetTitle() const override { return {}; }
void init(const string& Topic, const wchar_t *Mask, unsigned long long Flags);
bool ReadHelp(const string& Mask);
void AddLine(const string& Line, size_t Offset = 0);
void AddLine(const string& Line);
void AddTitle(const string& Title);
static void HighlightsCorrection(string &strStr);
void FastShow();
Expand Down Expand Up @@ -107,6 +107,9 @@ class Help:public Modal
FarColor CurColor; // CurColor - текущий цвет отрисовки
int CtrlTabSize; // CtrlTabSize - опция! размер табуляции

DWORD LastStartPos;
DWORD StartPos;

bool MouseDown;
bool IsNewTopic;
bool m_TopicFound;
Expand Down

0 comments on commit 6ba37ba

Please sign in to comment.