Skip to content

Commit cf7bb1d

Browse files
committed
修复一个算法结果不稳定得bug
1 parent 86183f7 commit cf7bb1d

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

CodeService/src/FormatElement/KeepLineElement.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ FormatElementType KeepLineElement::GetType()
1414

1515
void KeepLineElement::Serialize(FormatContext& ctx, int position, FormatElement& parent)
1616
{
17+
int lastElementLine = getLastValidLine(ctx, position, parent);
18+
int nextElementLine = getNextValidLine(ctx, position, parent);
19+
20+
if (nextElementLine == -1)
21+
{
22+
return;
23+
}
24+
1725
int line = _line;
1826
if (line == -1)
1927
{
20-
int lastElementLine = getLastValidLine(ctx, position, parent);
21-
int nextElementLine = getNextValidLine(ctx, position, parent);
22-
23-
if (nextElementLine == -1)
24-
{
25-
return;
26-
}
27-
2828
line = nextElementLine - lastElementLine - 1;
2929
if (line < 0)
3030
{
@@ -37,16 +37,18 @@ void KeepLineElement::Serialize(FormatContext& ctx, int position, FormatElement&
3737

3838
void KeepLineElement::Diagnosis(DiagnosisContext& ctx, int position, FormatElement& parent)
3939
{
40-
if (_line != -1)
41-
{
42-
int lastElementOffset = getLastValidOffset(position, parent);
43-
int nextElementOffset = getNextValidOffset(position, parent);
40+
ctx.SetCharacterCount(0);
4441

45-
if (nextElementOffset == -1)
46-
{
47-
return;
48-
}
42+
int lastElementOffset = getLastValidOffset(position, parent);
43+
int nextElementOffset = getNextValidOffset(position, parent);
44+
45+
if (nextElementOffset == -1)
46+
{
47+
return;
48+
}
4949

50+
if (_line != -1)
51+
{
5052
int lastElementLine = ctx.GetLine(lastElementOffset);
5153
int nextElementLine = ctx.GetLine(nextElementOffset);
5254

@@ -56,6 +58,4 @@ void KeepLineElement::Diagnosis(DiagnosisContext& ctx, int position, FormatEleme
5658
TextRange(lastElementOffset, nextElementOffset));
5759
}
5860
}
59-
ctx.SetCharacterCount(0);
60-
6161
}

0 commit comments

Comments
 (0)