Merge pull request #304 from RaiKoHoff/Bugfix_Join

Fix: Join Lines , New: Fuse Lines
This commit is contained in:
Derick Payne 2018-01-15 15:29:50 +02:00 committed by GitHub
commit 0da2f3c736
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 63 deletions

View File

@ -3576,7 +3576,14 @@ void EditWrapToColumn(HWND hwnd,int nColumn/*,int nTabWidth*/)
//
// EditJoinLinesEx()
//
void EditJoinLinesEx(HWND hwnd)
// Customized version of SCI_LINESJOIN (w/o using TARGET transaction)
//
// ~EditEnterTargetTransaction();
// ~SciCall_TargetFromSelection();
// ~SendMessage(g_hwndEdit, SCI_LINESJOIN, 0, 0);
// ~EditLeaveTargetTransaction();
//
void EditJoinLinesEx(HWND hwnd, BOOL bPreserveParagraphs, BOOL bCRLF2Space)
{
BOOL bModified = FALSE;
@ -3590,84 +3597,85 @@ void EditJoinLinesEx(HWND hwnd)
int iCurPos = SciCall_GetCurrentPos();
int iAnchorPos = SciCall_GetAnchor();
int iSelStart = SciCall_GetSelectionStart();
int iLine = SciCall_LineFromPosition(iSelStart);
iSelStart = SciCall_PositionFromLine(iLine);
int iSelEnd = SciCall_GetSelectionEnd();
int iSelEnd = SciCall_GetSelectionEnd();
int iSelCount = iSelEnd - iSelStart;
char* pszText = LocalAlloc(LPTR,iSelCount+2);
if (pszText == NULL)
return;
char* pszText = (char*)SciCall_GetRangePointer(iSelStart, iSelCount);
char* pszJoin = LocalAlloc(LPTR,LocalSize(pszText));
char* pszJoin = LocalAlloc(LPTR, iSelCount+1);
if (pszJoin == NULL) {
LocalFree(pszText);
return;
}
struct Sci_TextRange tr = { { 0, 0 }, NULL };
tr.chrg.cpMin = iSelStart;
tr.chrg.cpMax = iSelEnd;
tr.lpstrText = pszText;
SendMessage(hwnd,SCI_GETTEXTRANGE,0,(LPARAM)&tr);
int cchEOL = 2;
char szEOL[] = "\r\n";
int cEOLMode = (int)SendMessage(hwnd,SCI_GETEOLMODE,0,0);
if (cEOLMode == SC_EOL_CR)
cchEOL = 1;
else if (cEOLMode == SC_EOL_LF) {
cchEOL = 1;
szEOL[0] = '\n';
int cchEOL = 2;
switch ((int)SendMessage(hwnd, SCI_GETEOLMODE, 0, 0))
{
case SC_EOL_LF:
szEOL[0] = '\n';
szEOL[1] = '\0';
cchEOL = 1;
break;
case SC_EOL_CR:
szEOL[1] = '\0';
cchEOL = 1;
break;
case SC_EOL_CRLF:
default:
break;
}
int cchJoin = 0;
for (int i = 0; i < iSelCount; i++)
int cchJoin = -1;
for (int i = 0; i < iSelCount; ++i)
{
if (pszText[i] == '\r' || pszText[i] == '\n') {
if (pszText[i] == '\r' && pszText[i+1] == '\n')
i++;
if (!StrChrA("\r\n",pszText[i+1]) && pszText[i+1] != 0) {
pszJoin[cchJoin++] = ' ';
if (pszText[i] == '\r' || pszText[i] == '\n')
{
if (pszText[i] == '\r' && pszText[i + 1] == '\n') { ++i; }
if (!StrChrA("\r\n",pszText[i+1]) && pszText[i+1])
{
// next char is non line-break
if (bCRLF2Space) { pszJoin[++cchJoin] = ' '; }
bModified = TRUE;
}
else {
else { // we are between paragraphs
// swallow all line-breaks
while (StrChrA("\r\n",pszText[i+1])) {
i++;
++i;
bModified = TRUE;
}
if (pszText[i+1] != 0) {
pszJoin[cchJoin++] = szEOL[0];
if (cchEOL > 1)
pszJoin[cchJoin++] = szEOL[1];
if (cchJoin > cchEOL) {
pszJoin[cchJoin++] = szEOL[0];
if (cchEOL > 1)
pszJoin[cchJoin++] = szEOL[1];
if (bPreserveParagraphs) {
if (pszText[i + 1] != 0) {
for (int k = 0; k < cchEOL; ++k) { pszJoin[++cchJoin] = szEOL[k]; }
if (cchJoin > cchEOL) {
for (int k = 0; k < cchEOL; ++k) { pszJoin[++cchJoin] = szEOL[k]; }
}
bModified = TRUE;
}
}
}
}
else {
pszJoin[cchJoin++] = pszText[i];
pszJoin[++cchJoin] = pszText[i]; // copy char
}
}
LocalFree(pszText);
if (bModified) {
if (iAnchorPos > iCurPos) {
//iCurPos = iSelStart;
iAnchorPos = iSelStart + cchJoin;
iCurPos = iSelStart;
iAnchorPos = iSelStart + cchJoin + 1;
}
else {
//iAnchorPos = iSelStart;
iCurPos = iSelStart + cchJoin;
iAnchorPos = iSelStart;
iCurPos = iSelStart + cchJoin + 1;
}
SendMessage(hwnd,SCI_BEGINUNDOACTION,0,0);
SciCall_SetSel(iSelStart, iCurPos);
SciCall_SetSel(iSelStart, iSelEnd);
SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)pszJoin);
SciCall_SetSel(iAnchorPos, iCurPos);
SendMessage(hwnd,SCI_ENDUNDOACTION,0,0);

View File

@ -96,7 +96,7 @@ void EditStripTrailingBlanks(HWND,BOOL);
void EditCompressSpaces(HWND);
void EditRemoveBlankLines(HWND,BOOL);
void EditWrapToColumn(HWND,int);
void EditJoinLinesEx(HWND);
void EditJoinLinesEx(HWND,BOOL,BOOL);
void EditSortLines(HWND,int);
void EditJumpTo(HWND,int,int);

View File

@ -2327,7 +2327,8 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam)
EnableCmd(hmenu,IDM_EDIT_COLUMNWRAP,i /*&& IsWindowsNT()*/);
EnableCmd(hmenu,IDM_EDIT_SPLITLINES,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_JOINLINES,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_JOINLINESEX,i /*&& !bReadOnly*/);
EnableCmd(hmenu, IDM_EDIT_JOINLN_NOSP,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_JOINLINES_PARA,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_CONVERTUPPERCASE,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_CONVERTLOWERCASE,i /*&& !bReadOnly*/);
@ -3450,22 +3451,27 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
BeginWaitCursor(NULL);
int token = BeginSelUndoAction();
EditEnterTargetTransaction();
SciCall_TargetFromSelection();
SendMessage(g_hwndEdit,SCI_LINESJOIN,0,0);
EditLeaveTargetTransaction();
EditJoinLinesEx(g_hwndEdit); // needed to join paragraphs ???
EditJoinLinesEx(g_hwndEdit, FALSE, TRUE);
EndSelUndoAction(token);
EndWaitCursor();
}
break;
case IDM_EDIT_JOINLINESEX:
case IDM_EDIT_JOINLN_NOSP:
{
BeginWaitCursor(NULL);
int token = BeginSelUndoAction();
EditJoinLinesEx(g_hwndEdit);
EditJoinLinesEx(g_hwndEdit, FALSE, FALSE);
EndSelUndoAction(token);
EndWaitCursor();
}
break;
case IDM_EDIT_JOINLINES_PARA:
{
BeginWaitCursor(NULL);
int token = BeginSelUndoAction();
EditJoinLinesEx(g_hwndEdit, TRUE, TRUE);
EndSelUndoAction(token);
EndWaitCursor();
}
@ -7266,6 +7272,7 @@ void UpdateStatusbar()
}
else {
tchSel[0] = L'-'; tchSel[1] = L'-'; tchSel[2] = L'\0';
tchSelB[0] = L'0'; tchSelB[1] = L'\0';
}
// Print number of occurrence marks found

View File

@ -174,9 +174,10 @@ BEGIN
MENUITEM "Delete Line Right\tCtrl+Shift+Del", IDM_EDIT_DELETELINERIGHT
MENUITEM SEPARATOR
MENUITEM "Column &Wrap...\tCtrl+Shift+W", IDM_EDIT_COLUMNWRAP
MENUITEM "&Split Lines\tCtrl+I", IDM_EDIT_SPLITLINES
MENUITEM "&Join Lines\tCtrl+J", IDM_EDIT_JOINLINES
MENUITEM "Join &Paragraphs\tCtrl+Shift+J", IDM_EDIT_JOINLINESEX
MENUITEM "&Split Lines\tCtrl+I", IDM_EDIT_SPLITLINES
MENUITEM "&Join Lines\tCtrl+J", IDM_EDIT_JOINLINES
MENUITEM "&Fuse Lines\tCtrl+Alt+J", IDM_EDIT_JOINLN_NOSP
MENUITEM "&Preserve Paragraphs\tCtrl+Shift+J", IDM_EDIT_JOINLINES_PARA
END
POPUP "&Block"
BEGIN
@ -460,8 +461,9 @@ BEGIN
"I", IDM_EDIT_TITLECASE, VIRTKEY, CONTROL, ALT, NOINVERT
"I", IDM_VIEW_HILITECURRENTLINE, VIRTKEY, SHIFT, CONTROL, NOINVERT
"J", IDM_EDIT_JOINLINES, VIRTKEY, CONTROL, NOINVERT
"J", IDM_EDIT_ALIGN, VIRTKEY, ALT, NOINVERT
"J", IDM_EDIT_JOINLINESEX, VIRTKEY, SHIFT, CONTROL, NOINVERT
"J", IDM_EDIT_JOINLN_NOSP, VIRTKEY, CONTROL, ALT, NOINVERT
"J", IDM_EDIT_JOINLINES_PARA,VIRTKEY, SHIFT, CONTROL, NOINVERT
"J", IDM_EDIT_ALIGN, VIRTKEY, ALT, NOINVERT
"K", IDM_EDIT_SWAP, VIRTKEY, CONTROL, NOINVERT
"K", IDM_FILE_ADDTOFAV, VIRTKEY, ALT, NOINVERT
"K", CMD_COPYWINPOS, VIRTKEY, SHIFT, CONTROL, NOINVERT

View File

@ -289,7 +289,7 @@
#define IDM_EDIT_COLUMNWRAP 40321
#define IDM_EDIT_SPLITLINES 40322
#define IDM_EDIT_JOINLINES 40323
#define IDM_EDIT_JOINLINESEX 40324
#define IDM_EDIT_JOINLINES_PARA 40324
#define IDM_EDIT_INDENT 40325
#define IDM_EDIT_UNINDENT 40326
#define IDM_EDIT_ENCLOSESELECTION 40327
@ -339,6 +339,7 @@
#define IDM_EDIT_SELTONEXT 40371
#define IDM_EDIT_SELTOPREV 40372
#define IDM_EDIT_COMPLETEWORD 40373
#define IDM_EDIT_JOINLN_NOSP 40374
#define IDM_VIEW_SCHEME 40400
#define IDM_VIEW_USE2NDDEFAULT 40401
#define IDM_VIEW_SCHEMECONFIG 40402