Menu

#2372 SCI_LINESJOIN sometimes works incorrect

Bug
closed-fixed
nobody
scintilla (610)
5
2023-02-07
2023-01-03
No

SCI_LINESJOIN sometimes unnecessary change CRLF to CR when we have some spaces before CRFL.
Check attached picture. Second case seems wrong.

1 Attachments

Discussion

  • Neil Hodgson

    Neil Hodgson - 2023-01-03
    • labels: --> scintilla
    • status: open --> open-accepted
     
  • Neil Hodgson

    Neil Hodgson - 2023-01-03

    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.

     
    • Zufu Liu

      Zufu Liu - 2023-01-04

      The patch is missing.

       
  • Neil Hodgson

    Neil Hodgson - 2023-01-04

    Patch

     
  • Zufu Liu

    Zufu Liu - 2023-01-05

    The code can be more efficient (to avoid testing space and line ending on each byte) as following:

    for (Sci::Position pos = pdoc->LineEndPosition(targetRange.start.Position()); pos < targetRange.end.Position();) {
        const char chPrev = pdoc->CharAt(pos - 1);
        targetRange.end.Add(-pdoc->LenChar(pos));
        pdoc->DelChar(pos);
        if (chPrev != ' ') {
            // Ensure at least one space separating previous lines
            const Sci::Position lengthInserted = 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().

     
  • Zufu Liu

    Zufu Liu - 2023-01-06

    Updated the code to call LenChar() once:

    for (Sci::Position pos = pdoc->LineEndPosition(targetRange.start.Position()); pos < targetRange.end.Position();) {
        const char chPrev = pdoc->CharAt(pos - 1);
        const Sci::Position widthChar = pdoc->LenChar(pos);
        targetRange.end.Add(-widthChar);
        pdoc->DeleteChars(pos, widthChar);
        if (chPrev != ' ') {
            // Ensure at least one space separating previous lines
            const Sci::Position lengthInserted = pdoc->InsertString(pos, " ", 1);
            targetRange.end.Add(lengthInserted);
        }
        pos = pdoc->LineEndPosition(pos);
    }
    
     
  • Neil Hodgson

    Neil Hodgson - 2023-01-10
    • status: open-accepted --> open-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2023-01-10

    Committed fix as [e81c4c].

     

    Related

    Commit: [e81c4c]

  • Zufu Liu

    Zufu Liu - 2023-01-11

    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:

    const Sci::Line line = pdoc->SciLineFromPosition(targetRange.start.Position());
    for (Sci::Position pos = pdoc->LineEnd(line); pos < targetRange.end.Position(); pos = pdoc->LineEnd(line)) {
        const char chPrev = pdoc->CharAt(pos - 1);
        const Sci::Position widthChar = pdoc->LenChar(pos);
        targetRange.end.Add(-widthChar);
        pdoc->DeleteChars(pos, widthChar);
        if (chPrev != ' ') {
            // Ensure at least one space separating previous lines
            const Sci::Position lengthInserted = pdoc->InsertString(pos, " ", 1);
            targetRange.end.Add(lengthInserted);
        }
    }
    
     
    • Neil Hodgson

      Neil Hodgson - 2023-01-11
       

      Related

      Commit: [21a1a4]

  • Neil Hodgson

    Neil Hodgson - 2023-02-07
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB