When there is a space at the end of a line and then empty lines, it doesn't reset prevNonWS and moves past the '\r' without deleting it. Attached a patch that may fix this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The code can be more efficient (to avoid testing space and line ending on each byte) as following:
for(Sci::Positionpos=pdoc->LineEndPosition(targetRange.start.Position());pos<targetRange.end.Position();){constcharchPrev=pdoc->CharAt(pos-1);targetRange.end.Add(-pdoc->LenChar(pos));pdoc->DelChar(pos);if(chPrev!=' '){// Ensure at least one space separating previous linesconstSci::PositionlengthInserted=pdoc->InsertString(pos," ",1);targetRange.end.Add(lengthInserted);}pos=pdoc->LineEndPosition(pos);}
The condition chPrev != ' ' can be changed to chPrev != ' ' && pdoc->CharAt(pos) != ' ', or changed to use IsSpaceOrTab().
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
for(Sci::Positionpos=pdoc->LineEndPosition(targetRange.start.Position());pos<targetRange.end.Position();){constcharchPrev=pdoc->CharAt(pos-1);constSci::PositionwidthChar=pdoc->LenChar(pos);targetRange.end.Add(-widthChar);pdoc->DeleteChars(pos,widthChar);if(chPrev!=' '){// Ensure at least one space separating previous linesconstSci::PositionlengthInserted=pdoc->InsertString(pos," ",1);targetRange.end.Add(lengthInserted);}pos=pdoc->LineEndPosition(pos);}
Just found the code be optimized further: the function is join multiply lines to a single line with space delimiter, thus the line number is not changed, the loop can be written as:
constSci::Lineline=pdoc->SciLineFromPosition(targetRange.start.Position());for(Sci::Positionpos=pdoc->LineEnd(line);pos<targetRange.end.Position();pos=pdoc->LineEnd(line)){constcharchPrev=pdoc->CharAt(pos-1);constSci::PositionwidthChar=pdoc->LenChar(pos);targetRange.end.Add(-widthChar);pdoc->DeleteChars(pos,widthChar);if(chPrev!=' '){// Ensure at least one space separating previous linesconstSci::PositionlengthInserted=pdoc->InsertString(pos," ",1);targetRange.end.Add(lengthInserted);}}
When there is a space at the end of a line and then empty lines, it doesn't reset
prevNonWSand moves past the '\r' without deleting it. Attached a patch that may fix this.The patch is missing.
Patch
The code can be more efficient (to avoid testing space and line ending on each byte) as following:
The condition
chPrev != ' 'can be changed tochPrev != ' ' && pdoc->CharAt(pos) != ' ', or changed to useIsSpaceOrTab().Updated the code to call
LenChar()once:Committed fix as [e81c4c].
Related
Commit: [e81c4c]
Just found the code be optimized further: the function is join multiply lines to a single line with space delimiter, thus the line number is not changed, the loop can be written as:
OK, [21a1a4].
Related
Commit: [21a1a4]