src/Edit.c
void EditJoinLinesEx(bool bPreserveParagraphs, bool bCRLF2Space)
{
  bool bModified = false;

  if (SciCall_IsSelectionEmpty()) { return; }

  if (Sci_IsMultiOrRectangleSelection()) {
    InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_SELRECTORMULTI);
    return;
  }

  DocPos const iSelStart = SciCall_GetSelectionStart();
  DocPos const iSelEnd = SciCall_GetSelectionEnd();
  DocPos const iSelLength = (iSelEnd - iSelStart);
  DocPos iCurPos = SciCall_GetCurrentPos();
  DocPos iAnchorPos = SciCall_GetAnchor();

  DocPos cchJoin = (DocPos)-1;

  char* pszText = SciCall_GetRangePointer(iSelStart, iSelLength);

  char* pszJoin = AllocMem(iSelLength + 1, HEAP_ZERO_MEMORY);
  if (pszJoin == NULL) {
    return;
  }

  char szEOL[3] = { '\0' };
  int const cchEOL = Sci_GetCurrentEOL_A(szEOL);

  for (int i = 0; i < iSelLength; ++i)
  {
    int j = i;
    // try to swallow next line-breaks
    while (StrChrA("\r\n", pszText[j])) { ++j; }

    if (i < j) {
      // swallowed!
      if (((j - i) >= 2*cchEOL) && bPreserveParagraphs) {
        for (int k = 0; k < 2*cchEOL; ++k) { pszJoin[++cchJoin] = szEOL[k % cchEOL]; }
      }
      else if (bCRLF2Space) {
        pszJoin[++cchJoin] = ' ';
      }
      i = j;
      bModified = true;
    }
    if (i < iSelLength) {
      pszJoin[++cchJoin] = pszText[i]; // copy char
    }
  }
  ++cchJoin; // start at -1 

  if (bModified) {
    if (iAnchorPos > iCurPos) {
      iCurPos = iSelStart;
      iAnchorPos = iSelStart + cchJoin;
    }
    else {
      iAnchorPos = iSelStart;
      iCurPos = iSelStart + cchJoin;
    }

    _BEGIN_UNDO_ACTION_;
    DocPos const saveTargetBeg = SciCall_GetTargetStart();
    DocPos const saveTargetEnd = SciCall_GetTargetEnd();
    SciCall_SetTargetRange(iSelStart, iSelEnd);
    SciCall_ReplaceTarget(cchJoin, pszJoin);
    SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
    EditSetSelectionEx(iAnchorPos, iCurPos, -1, -1);
    _END_UNDO_ACTION_;
  }
  FreeMem(pszJoin);
}
//=============================================================================
//
//  EditJoinLinesEx()
//
//  Customized version of  SCI_LINESJOIN  (w/o using TARGET transaction)
//

EditJoinLinesEx()
Customized version of  SCI_LINESJOIN  (w/o using TARGET transaction)
EditJoinLinesEx () Customized version of SCI_LINESJOIN ( w / o using TARGET transaction )
void EditJoinLinesEx(bool bPreserveParagraphs, bool bCRLF2Space)
{
  bool bModified = false;
  if (SciCall_IsSelectionEmpty()) { return; }
  if (Sci_IsMultiOrRectangleSelection()) {
    InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_SELRECTORMULTI);
    return;
  }
  DocPos const iSelStart = SciCall_GetSelectionStart();
  DocPos const iSelEnd = SciCall_GetSelectionEnd();
  DocPos const iSelLength = (iSelEnd - iSelStart);
  DocPos iCurPos = SciCall_GetCurrentPos();
  DocPos iAnchorPos = SciCall_GetAnchor();
  DocPos cchJoin = (DocPos)-1;
  char* pszText = SciCall_GetRangePointer(iSelStart, iSelLength);
  char* pszJoin = AllocMem(iSelLength + 1, HEAP_ZERO_MEMORY);
  if (pszJoin == NULL) {
    return;
  }
  char szEOL[3] = { '\0' };
  int const cchEOL = Sci_GetCurrentEOL_A(szEOL);
  for (int i = 0; i < iSelLength; ++i)
  {
    int j = i;
    while (StrChrA("\r\n", pszText[j])) { ++j; }
    if (i < j) {
      if (((j - i) >= 2*cchEOL) && bPreserveParagraphs) {
        for (int k = 0; k < 2*cchEOL; ++k) { pszJoin[++cchJoin] = szEOL[k % cchEOL]; }
      }
      else if (bCRLF2Space) {
        pszJoin[++cchJoin] = ' ';
      }
      i = j;
      bModified = true;
    }
    if (i < iSelLength) {
      pszJoin[++cchJoin] = pszText[i]; 
    }
  }
  ++cchJoin; 
  if (bModified) {
    if (iAnchorPos > iCurPos) {
      iCurPos = iSelStart;
      iAnchorPos = iSelStart + cchJoin;
    }
    else {
      iAnchorPos = iSelStart;
      iCurPos = iSelStart + cchJoin;
    }
    _BEGIN_UNDO_ACTION_;
    DocPos const saveTargetBeg = SciCall_GetTargetStart();
    DocPos const saveTargetEnd = SciCall_GetTargetEnd();
    SciCall_SetTargetRange(iSelStart, iSelEnd);
    SciCall_ReplaceTarget(cchJoin, pszJoin);
    SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); 
    EditSetSelectionEx(iAnchorPos, iCurPos, -1, -1);
    _END_UNDO_ACTION_;
  }
  FreeMem(pszJoin);
}
void EditJoinLinesEx ( bool bPreserveParagraphs , bool bCRLF2Space ) { bool bModified = false ; if ( SciCall_IsSelectionEmpty ( ) ) { return ; } if ( Sci_IsMultiOrRectangleSelection ( ) ) { InfoBoxLng ( MB_ICONWARNING , NULL , IDS_MUI_SELRECTORMULTI ) ; return ; } DocPos const iSelStart = SciCall_GetSelectionStart ( ) ; DocPos const iSelEnd = SciCall_GetSelectionEnd ( ) ; DocPos const iSelLength = ( iSelEnd - iSelStart ) ; DocPos iCurPos = SciCall_GetCurrentPos ( ) ; DocPos iAnchorPos = SciCall_GetAnchor ( ) ; DocPos cchJoin = ( DocPos ) - 1 ; char * pszText = SciCall_GetRangePointer ( iSelStart , iSelLength ) ; char * pszJoin = AllocMem ( iSelLength + 1 , HEAP_ZERO_MEMORY ) ; if ( pszJoin == NULL ) { return ; } char szEOL [ 3 ] = { ' \0 ' } ; int const cchEOL = Sci_GetCurrentEOL_A ( szEOL ) ; for ( int i = 0 ; i < iSelLength ; ++ i ) { int j = i ; while ( StrChrA ( " \r \n " , pszText [ j ] ) ) { ++ j ; } if ( i < j ) { if ( ( ( j - i ) >= 2 * cchEOL ) && bPreserveParagraphs ) { for ( int k = 0 ; k < 2 * cchEOL ; ++ k ) { pszJoin [ ++ cchJoin ] = szEOL [ k % cchEOL ] ; } } else if ( bCRLF2Space ) { pszJoin [ ++ cchJoin ] = ' ' ; } i = j ; bModified = true ; } if ( i < iSelLength ) { pszJoin [ ++ cchJoin ] = pszText [ i ] ; } } ++ cchJoin ; if ( bModified ) { if ( iAnchorPos > iCurPos ) { iCurPos = iSelStart ; iAnchorPos = iSelStart + cchJoin ; } else { iAnchorPos = iSelStart ; iCurPos = iSelStart + cchJoin ; } _BEGIN_UNDO_ACTION_ ; DocPos const saveTargetBeg = SciCall_GetTargetStart ( ) ; DocPos const saveTargetEnd = SciCall_GetTargetEnd ( ) ; SciCall_SetTargetRange ( iSelStart , iSelEnd ) ; SciCall_ReplaceTarget ( cchJoin , pszJoin ) ; SciCall_SetTargetRange ( saveTargetBeg , saveTargetEnd ) ; EditSetSelectionEx ( iAnchorPos , iCurPos , -1 , -1 ) ; _END_UNDO_ACTION_ ; } FreeMem ( pszJoin ) ; }
EditJoinLinesEx()
Customized version of  SCI_LINESJOIN  (w/o using TARGET transaction)
EditJoinLinesEx () Customized version of SCI_LINESJOIN ( w / o using TARGET transaction )
// try to swallow next line-breaks
 // swallowed!
 // copy char
 // start at -1 
 //restore
