diff --git a/src/Edit.c b/src/Edit.c index 90637c950..edabea922 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -261,6 +261,7 @@ void EditInitWordDelimiter(HWND hwnd) extern BOOL bFreezeAppTitle; extern FILEVARS fvCurFile; + void EditSetNewText(HWND hwnd,char* lpstrText,DWORD cbText) { bFreezeAppTitle = TRUE; @@ -720,7 +721,7 @@ BOOL EditPasteClipboard(HWND hwnd, BOOL bSwapClipBoard, BOOL bSkipUnicodeCheck) SciCall_Paste(); if (bSwapClipBoard) { EditClearClipboard(hwnd); - EditSelectEx(hwnd, iAnchorPos, SciCall_GetCurrentPos()); + EditSelectEx(hwnd, iAnchorPos, SciCall_GetCurrentPos(), -1, -1); } } else { @@ -730,13 +731,13 @@ BOOL EditPasteClipboard(HWND hwnd, BOOL bSwapClipBoard, BOOL bSkipUnicodeCheck) if (bSwapClipBoard) { EditSetClipboardText(hwnd, pszText); if (iCurPos < iAnchorPos) - EditSelectEx(hwnd, SciCall_GetCurrentPos(), iCurPos); + EditSelectEx(hwnd, SciCall_GetCurrentPos(), iCurPos, -1, -1); else - EditSelectEx(hwnd, iAnchorPos, SciCall_GetCurrentPos()); + EditSelectEx(hwnd, iAnchorPos, SciCall_GetCurrentPos(), -1, -1); } else { if (iCurPos < iAnchorPos) - EditSelectEx(hwnd, iCurPos, iCurPos); + EditSelectEx(hwnd, iCurPos, iCurPos, -1, -1); } LocalFree(pszText); } @@ -756,14 +757,14 @@ BOOL EditPasteClipboard(HWND hwnd, BOOL bSwapClipBoard, BOOL bSkipUnicodeCheck) SciCall_Copy(); SciCall_ReplaceSel(pClip); if (iCurPos < iAnchorPos) - EditSelectEx(hwnd, iCurPos + clipLen, iCurPos); + EditSelectEx(hwnd, iCurPos + clipLen, iCurPos, -1, -1); else - EditSelectEx(hwnd, iAnchorPos, iAnchorPos + clipLen); + EditSelectEx(hwnd, iAnchorPos, iAnchorPos + clipLen, -1, -1); } else { SciCall_ReplaceSel(pClip); if (iCurPos < iAnchorPos) - EditSelectEx(hwnd, iCurPos, iCurPos); + EditSelectEx(hwnd, iCurPos, iCurPos, -1, -1); } ObserveNotifyChangeEvent(); } @@ -796,7 +797,7 @@ BOOL EditCopyAppend(HWND hwnd, BOOL bAppend) else { DocPos cchText = SciCall_GetTextLength(); pszText = LocalAlloc(LPTR,cchText + 1); - SciCall_GetTextFromBegin((DocPos)LocalSize(pszText), pszText); + SciCall_GetText((DocPos)LocalSize(pszText), pszText); } WCHAR* pszTextW = NULL; int cchTextW = MultiByteToWideChar(Encoding_SciCP,0,pszText,-1,NULL,0); @@ -1617,9 +1618,9 @@ void EditURLEncode(HWND hwnd) if (iCurPos < iAnchorPos) - EditSelectEx(hwnd, iCurPos + cchEscaped, iCurPos); + EditSelectEx(hwnd, iCurPos + cchEscaped, iCurPos, -1, -1); else - EditSelectEx(hwnd, iAnchorPos, iAnchorPos + cchEscaped); + EditSelectEx(hwnd, iAnchorPos, iAnchorPos + cchEscaped, -1, -1); LocalFree(pszTextW); LocalFree(pszEscaped); @@ -1682,9 +1683,9 @@ void EditURLDecode(HWND hwnd) EditLeaveTargetTransaction(); if (iCurPos < iAnchorPos) - EditSelectEx(hwnd, iCurPos + cchUnescaped, iCurPos); + EditSelectEx(hwnd, iCurPos + cchUnescaped, iCurPos, -1, -1); else - EditSelectEx(hwnd, iAnchorPos, iAnchorPos + cchUnescaped); + EditSelectEx(hwnd, iAnchorPos, iAnchorPos + cchUnescaped, -1, -1); LocalFree(pszTextW); LocalFree(pszUnescaped); @@ -1780,7 +1781,7 @@ void EditChar2Hex(HWND hwnd) { char ch[32] = { '\0' }; WCHAR wch[32] = { L'\0' }; - EditSelectEx(hwnd, iSelStart, iSelEnd); + EditSelectEx(hwnd, iSelStart, iSelEnd, -1, -1); //TODO: iterate over complete selection? if (SciCall_GetSelText(NULL) <= COUNTOF(ch)) { @@ -1802,13 +1803,13 @@ void EditChar2Hex(HWND hwnd) { const DocPos iReplLen = StringCchLenA(ch, COUNTOF(ch)); if (iCurPos < iAnchorPos) { - EditSelectEx(hwnd, iCurPos + iReplLen, iCurPos); + EditSelectEx(hwnd, iCurPos + iReplLen, iCurPos, -1, -1); } else if (iCurPos > iAnchorPos) { - EditSelectEx(hwnd, iAnchorPos, iAnchorPos + iReplLen); + EditSelectEx(hwnd, iAnchorPos, iAnchorPos + iReplLen, -1, -1); } else { // empty selection - EditSelectEx(hwnd, iCurPos + iReplLen, iCurPos + iReplLen); + EditSelectEx(hwnd, iCurPos + iReplLen, iCurPos + iReplLen, -1, -1); } } @@ -1870,13 +1871,13 @@ void EditHex2Char(HWND hwnd) if (iCurPos < iAnchorPos) { --iCurPos; } else { --iAnchorPos; } } } - EditSelectEx(hwnd, iSelStart, iSelEnd); + EditSelectEx(hwnd, iSelStart, iSelEnd, -1, -1); SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)ch); if (iCurPos < iAnchorPos) - EditSelectEx(hwnd, iCurPos + cch, iCurPos); + EditSelectEx(hwnd, iCurPos + cch, iCurPos, -1, -1); else - EditSelectEx(hwnd, iAnchorPos, iAnchorPos + cch); + EditSelectEx(hwnd, iAnchorPos, iAnchorPos + cch, -1, -1); } } @@ -1906,7 +1907,7 @@ void EditFindMatchingBrace(HWND hwnd) } if (iMatchingBracePos != (DocPos)-1) { iMatchingBracePos = bIsAfter ? iMatchingBracePos : SciCall_PositionAfter(iMatchingBracePos); - EditSelectEx(hwnd, iMatchingBracePos, iMatchingBracePos); + EditSelectEx(hwnd, iMatchingBracePos, iMatchingBracePos, -1, -1); } } @@ -1934,9 +1935,9 @@ void EditSelectToMatchingBrace(HWND hwnd) } if (iMatchingBracePos != (DocPos)-1) { if (bIsAfter) - EditSelectEx(hwnd, iCurPos, iMatchingBracePos); + EditSelectEx(hwnd, iCurPos, iMatchingBracePos, -1, -1); else - EditSelectEx(hwnd, iCurPos, SciCall_PositionAfter(iMatchingBracePos)); + EditSelectEx(hwnd, iCurPos, SciCall_PositionAfter(iMatchingBracePos), -1, -1); } } @@ -2098,7 +2099,7 @@ void EditTabsToSpaces(HWND hwnd,int nTabWidth,BOOL bOnlyIndentingWS) SendMessage(hwnd, SCI_REPLACETARGET, (WPARAM)cchConvM, (LPARAM)pszText2); EditLeaveTargetTransaction(); - EditSelectEx(hwnd, iAnchorPos, iCurPos); + EditSelectEx(hwnd, iAnchorPos, iCurPos, -1, -1); FreeMem(pszText2); } @@ -2211,7 +2212,7 @@ void EditSpacesToTabs(HWND hwnd,int nTabWidth,BOOL bOnlyIndentingWS) SendMessage(hwnd, SCI_REPLACETARGET, (WPARAM)cchConvM, (LPARAM)pszText2); EditLeaveTargetTransaction(); - EditSelectEx(hwnd, iAnchorPos, iCurPos); + EditSelectEx(hwnd, iAnchorPos, iCurPos, -1, -1); FreeMem(pszText2); } @@ -2495,7 +2496,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend) iAnchorPos = SciCall_PositionFromLine(iLineStart); iCurPos = SciCall_PositionFromLine(iLineEnd + 1); } - EditSelectEx(hwnd, iAnchorPos, iCurPos); + EditSelectEx(hwnd, iAnchorPos, iCurPos, -1, -1); } } else @@ -2532,7 +2533,7 @@ void EditIndentBlock(HWND hwnd, int cmd, BOOL bFormatIndentation) // better idea: EditPaste2RectSel(hwnd, pPadStr, pText); pText==NULL => copy single sel //TODO: workaround for rectangular selection: make stream selection - EditSelectEx(hwnd, SciCall_GetAnchor(), SciCall_GetCurrentPos()); + EditSelectEx(hwnd, SciCall_GetAnchor(), SciCall_GetCurrentPos(), -1, -1); } const DocPos iCurPos = SciCall_GetCurrentPos(); @@ -2586,7 +2587,7 @@ void EditIndentBlock(HWND hwnd, int cmd, BOOL bFormatIndentation) if (bSingleLine) { if (bFormatIndentation) - EditSelectEx(hwnd, SciCall_GetCurrentPos() + iDiffCurrent + (iAnchorPos - iCurPos), SciCall_GetCurrentPos() + iDiffCurrent); + EditSelectEx(hwnd, SciCall_GetCurrentPos() + iDiffCurrent + (iAnchorPos - iCurPos), SciCall_GetCurrentPos() + iDiffCurrent, -1, -1); } else { // on multiline indentation, anchor and current positions are moved to line begin resp. end if (bFixStart) { @@ -2595,7 +2596,7 @@ void EditIndentBlock(HWND hwnd, int cmd, BOOL bFormatIndentation) else iDiffAnchor = SciCall_LineLength(iAnchorLine) - GetEOLLen(); } - EditSelectEx(hwnd, SciCall_GetLineEndPosition(iAnchorLine) - iDiffAnchor, SciCall_GetLineEndPosition(iCurLine) - iDiffCurrent); + EditSelectEx(hwnd, SciCall_GetLineEndPosition(iAnchorLine) - iDiffAnchor, SciCall_GetLineEndPosition(iCurLine) - iDiffCurrent, -1, -1); } } @@ -2850,7 +2851,7 @@ void EditAlignText(HWND hwnd,int nMode) iAnchorPos = SciCall_PositionFromLine(iLineStart); iCurPos = SciCall_PositionFromLine(iLineEnd + 1); } - EditSelectEx(hwnd, iAnchorPos, iCurPos); + EditSelectEx(hwnd, iAnchorPos, iCurPos, -1, -1); } else MsgBox(MBWARN, IDS_SELRECT); @@ -2900,7 +2901,7 @@ void EditEncloseSelection(HWND hwnd, LPCWSTR pwszOpen, LPCWSTR pwszClose) EditLeaveTargetTransaction(); // Fix selection - EditSelectEx(hwnd, iAnchorPos + iLenOpen, iCurPos + iLenOpen); + EditSelectEx(hwnd, iAnchorPos + iLenOpen, iCurPos + iLenOpen, -1, -1); } @@ -3016,11 +3017,11 @@ void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, BOOL bInsertAtStart) ObserveNotifyChangeEvent(); if (iCurPos < iAnchorPos) - EditSelectEx(hwnd, iAnchorPos + iSelEndOffset, iCurPos + iSelStartOffset); + EditSelectEx(hwnd, iAnchorPos + iSelEndOffset, iCurPos + iSelStartOffset, -1, -1); else if (iCurPos > iAnchorPos) - EditSelectEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelEndOffset); + EditSelectEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelEndOffset, -1, -1); else - EditSelectEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelStartOffset); + EditSelectEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelStartOffset, -1, -1); } @@ -3166,7 +3167,7 @@ void EditPadWithSpaces(HWND hwnd,BOOL bSkipEmpty,BOOL bNoUndoGroup) else iCurPos = SciCall_PositionFromLine(iLineEnd + 1); } - EditSelectEx(hwnd, iAnchorPos, iCurPos); + EditSelectEx(hwnd, iAnchorPos, iCurPos, -1, -1); } else if (bIsRectangular) { @@ -3545,17 +3546,17 @@ void EditCompressSpaces(HWND hwnd) const DocPos iNewLen = StringCchLenA(pszOut, LocalSize(pszOut)); if (iCurPos < iAnchorPos) { - EditSelectEx(hwnd, iCurPos + iNewLen, iCurPos); + EditSelectEx(hwnd, iCurPos + iNewLen, iCurPos, -1, -1); } else if (iCurPos > iAnchorPos) { - EditSelectEx(hwnd, iAnchorPos, iAnchorPos + iNewLen); + EditSelectEx(hwnd, iAnchorPos, iAnchorPos + iNewLen, -1, -1); } else { // empty selection DocPos iNewPos = iCurPos; if (iCurPos > 0) { iNewPos = SciCall_PositionBefore(SciCall_PositionAfter(iCurPos - remWSuntilCaretPos)); } - EditSelectEx(hwnd, iNewPos, iNewPos); + EditSelectEx(hwnd, iNewPos, iNewPos, -1, -1); } } } @@ -3568,7 +3569,7 @@ void EditCompressSpaces(HWND hwnd) // // EditRemoveBlankLines() // -void EditRemoveBlankLines(HWND hwnd,BOOL bMerge) +void EditRemoveBlankLines(HWND hwnd, BOOL bMerge, BOOL bRemoveWhiteSpace) { UNUSED(hwnd); @@ -3577,29 +3578,46 @@ void EditRemoveBlankLines(HWND hwnd,BOOL bMerge) return; } - DocPos iSelStart = SciCall_GetSelectionStart(); - DocPos iSelEnd = SciCall_GetSelectionEnd(); + const DocPos iSelStart = (SciCall_IsSelectionEmpty() ? 0 : SciCall_GetSelectionStart()); + const DocPos iSelEnd = (SciCall_IsSelectionEmpty() ? SciCall_GetTextLength() : SciCall_GetSelectionEnd()); - if (iSelStart == iSelEnd) { - iSelStart = 0; - iSelEnd = SciCall_GetTextLength(); - } + DocLn iBegLine = SciCall_LineFromPosition(iSelStart); + DocLn iEndLine = SciCall_LineFromPosition(iSelEnd); - DocLn iLineStart = SciCall_LineFromPosition(iSelStart); - DocLn iLineEnd = SciCall_LineFromPosition(iSelEnd); - - if (iSelStart > SciCall_PositionFromLine(iLineStart)) { ++iLineStart; } - if ((iSelEnd <= SciCall_PositionFromLine(iLineEnd)) && (iLineEnd != SciCall_GetLineCount() - 1)) { --iLineEnd; } + if (iSelStart > SciCall_PositionFromLine(iBegLine)) { ++iBegLine; } + if ((iSelEnd <= SciCall_PositionFromLine(iEndLine)) && (iEndLine != SciCall_GetLineCount() - 1)) { --iEndLine; } IgnoreNotifyChangeEvent(); EditEnterTargetTransaction(); - for (DocLn iLine = iLineStart; iLine <= iLineEnd; ) + for (DocLn iLine = iBegLine; iLine <= iEndLine; ) { - int nBlanks = 0; - while (((iLine + nBlanks) <= iLineEnd) && - (SciCall_PositionFromLine(iLine + nBlanks) == SciCall_GetLineEndPosition(iLine + nBlanks))) { - ++nBlanks; + DocLn nBlanks = 0; + bool bSpcOnly = true; + while (((iLine + nBlanks) <= iEndLine) && bSpcOnly) + { + bSpcOnly = false; + const DocPos posLnBeg = SciCall_PositionFromLine(iLine + nBlanks); + const DocPos posLnEnd = SciCall_GetLineEndPosition(iLine + nBlanks); + const int iLnLength = (posLnEnd - posLnBeg); + + if (iLnLength == 0) { + ++nBlanks; + bSpcOnly = true; + } + else if (bRemoveWhiteSpace) { + const char* pLine = SciCall_GetRangePointer(posLnBeg, (DocPos)iLnLength); + int i = 0; + for (; i < iLnLength; ++i) { + if (!IsWhiteSpace(pLine[i])) { + break; + } + } + if (i >= iLnLength) { + ++nBlanks; + bSpcOnly = true; + } + } } if ((nBlanks == 0) || ((nBlanks == 1) && bMerge)) { iLine += (nBlanks + 1); @@ -3611,7 +3629,7 @@ void EditRemoveBlankLines(HWND hwnd,BOOL bMerge) SciCall_ReplaceTarget(0, ""); if (bMerge) { ++iLine; } - iLineEnd -= nBlanks; + iEndLine -= nBlanks; } } EditLeaveTargetTransaction(); @@ -3632,12 +3650,11 @@ void EditRemoveDuplicateLines(HWND hwnd, bool bRemoveEmptyLines) return; } - DocLn iStartLine = 0; - DocLn iEndLine = 0; - const DocPos iSelStart = SciCall_GetSelectionStart(); const DocPos iSelEnd = SciCall_GetSelectionEnd(); + DocLn iStartLine = 0; + DocLn iEndLine = 0; if (iSelStart != iSelEnd) { iStartLine = SciCall_LineFromPosition(iSelStart); if (iSelStart > SciCall_PositionFromLine(iStartLine)) { ++iStartLine; } @@ -3845,7 +3862,7 @@ void EditWrapToColumn(HWND hwnd,DocPos nColumn/*,int nTabWidth*/) FreeMem(pszText); - EditSelectEx(hwnd, iAnchorPos, iCurPos); + EditSelectEx(hwnd, iAnchorPos, iCurPos, -1, -1); } } FreeMem(pszConvW); @@ -3952,7 +3969,7 @@ void EditJoinLinesEx(HWND hwnd, BOOL bPreserveParagraphs, BOOL bCRLF2Space) SendMessage(hwnd, SCI_REPLACETARGET, (WPARAM)cchJoin, (LPARAM)pszJoin); EditLeaveTargetTransaction(); - EditSelectEx(hwnd, iAnchorPos, iCurPos); + EditSelectEx(hwnd, iAnchorPos, iCurPos, -1, -1); } LocalFree(pszJoin); } @@ -4243,7 +4260,7 @@ void EditSortLines(HWND hwnd, int iSortFlags) SendMessage(hwnd, SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, (WPARAM)iCurPosVS, 0); } else { - EditSelectEx(hwnd, iAnchorPos, iCurPos); + EditSelectEx(hwnd, iAnchorPos, iCurPos, -1, -1); } } @@ -4253,7 +4270,7 @@ void EditSortLines(HWND hwnd, int iSortFlags) // // EditSelectEx() // -void EditSelectEx(HWND hwnd, DocPos iAnchorPos, DocPos iCurrentPos) +void EditSelectEx(HWND hwnd, DocPos iAnchorPos, DocPos iCurrentPos, int vSpcAnchor, int vSpcCurrent) { if ((iAnchorPos < 0) && (iCurrentPos < 0)) { SciCall_SelectAll(); @@ -4273,7 +4290,16 @@ void EditSelectEx(HWND hwnd, DocPos iAnchorPos, DocPos iCurrentPos) SciCall_EnsureVisible(iAnchorLine); if (iAnchorLine != iNewLine) { SciCall_EnsureVisible(iNewLine); } - SciCall_SetSel(iAnchorPos, iCurrentPos); + if ((vSpcAnchor >= 0) && (vSpcCurrent >= 0)) { + SciCall_SetRectangularSelectionAnchor(iAnchorPos); + if (vSpcAnchor > 0) + SciCall_SetRectangularSelectionAnchorVirtualSpace(vSpcAnchor); + SciCall_SetRectangularSelectionCaret(iCurrentPos); + if (vSpcCurrent > 0) + SciCall_SetRectangularSelectionCaretVirtualSpace(vSpcCurrent); + } + else + SciCall_SetSel(iAnchorPos, iCurrentPos); SciCall_ScrollRange(iAnchorPos, iCurrentPos); @@ -4297,20 +4323,15 @@ void EditJumpTo(HWND hwnd, DocLn iNewLine, DocPos iNewCol) SendMessage(hwnd, SCI_DOCUMENTEND, 0, 0); return; } - const DocLn iMaxLine = SciCall_GetLineCount(); - // Line maximum is iMaxLine - 1 (doc line count starts with 0) iNewLine = (min(iNewLine, iMaxLine) - 1); const DocPos iLineEndPos = SciCall_GetLineEndPosition(iNewLine); - // Column minimum is 1 iNewCol = max(0, min((iNewCol - 1), iLineEndPos)); + const DocPos iNewPos = SciCall_FindColumn(iNewLine, iNewCol); - const DocPos iNewPos = (DocPos)SendMessage(hwnd, SCI_FINDCOLUMN, (WPARAM)iNewLine, (LPARAM)iNewCol); - - EditSelectEx(hwnd, iNewPos, iNewPos); // <= SCI_GOTOPOS(pos) - + EditSelectEx(hwnd, iNewPos, iNewPos, -1, -1); // <= SCI_GOTOPOS(pos) } @@ -4353,7 +4374,7 @@ void EditEnsureSelectionVisible(HWND hwnd) { const DocPos iAnchorPos = SciCall_GetAnchor(); const DocPos iCurrentPos = SciCall_GetCurrentPos(); - EditSelectEx(hwnd, iAnchorPos, iCurrentPos); + EditSelectEx(hwnd, iAnchorPos, iCurrentPos, -1, -1); UNUSED(hwnd); } @@ -5508,10 +5529,10 @@ BOOL EditFindNext(HWND hwnd, LPCEDITFINDREPLACE lpefr, BOOL bExtendSelection, BO if (bExtendSelection) { DocPos iSelPos = SciCall_GetCurrentPos(); DocPos iSelAnchor = SciCall_GetAnchor(); - EditSelectEx(hwnd, min(iSelAnchor, iSelPos), end); + EditSelectEx(hwnd, min(iSelAnchor, iSelPos), end, -1, -1); } else { - EditSelectEx(hwnd, start, end); + EditSelectEx(hwnd, start, end, -1, -1); } return TRUE; } @@ -5579,10 +5600,10 @@ BOOL EditFindPrev(HWND hwnd, LPCEDITFINDREPLACE lpefr, BOOL bExtendSelection, BO if (bExtendSelection) { DocPos iSelPos = SciCall_GetCurrentPos(); DocPos iSelAnchor = SciCall_GetAnchor(); - EditSelectEx(hwnd, max(iSelPos, iSelAnchor), start); + EditSelectEx(hwnd, max(iSelPos, iSelAnchor), start, -1, -1); } else { - EditSelectEx(hwnd, end, start); + EditSelectEx(hwnd, end, start, -1, -1); } return TRUE; } @@ -5704,7 +5725,7 @@ BOOL EditReplace(HWND hwnd, LPCEDITFINDREPLACE lpefr) { if (iPos < 0) return EditFindNext(hwnd, lpefr, FALSE, FALSE); else { - EditSelectEx(hwnd, start, end); + EditSelectEx(hwnd, start, end, -1, -1); return TRUE; } } diff --git a/src/Edit.h b/src/Edit.h index ebde91b7f..3c58322ab 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -94,14 +94,14 @@ void EditPadWithSpaces(HWND,BOOL,BOOL); void EditStripFirstCharacter(HWND); void EditStripLastCharacter(HWND,BOOL,BOOL); void EditCompressSpaces(HWND); -void EditRemoveBlankLines(HWND,BOOL); +void EditRemoveBlankLines(HWND,BOOL,BOOL); void EditRemoveDuplicateLines(HWND,bool); void EditWrapToColumn(HWND,DocPos); void EditJoinLinesEx(HWND,BOOL,BOOL); void EditSortLines(HWND,int); void EditJumpTo(HWND, DocLn, DocPos); -void EditSelectEx(HWND, DocPos, DocPos); +void EditSelectEx(HWND, DocPos, DocPos, int, int); void EditFixPositions(HWND); void EditEnsureSelectionVisible(HWND); void EditGetExcerpt(HWND,LPWSTR,DWORD); diff --git a/src/Notepad3.c b/src/Notepad3.c index 9e7a17af2..49fc56cb9 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2085,7 +2085,7 @@ LRESULT MsgContextMenu(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) ptc.x = pt.x; ptc.y = pt.y; ScreenToClient(g_hwndEdit, &ptc); iNewPos = (DocPos)SendMessage(g_hwndEdit, SCI_POSITIONFROMPOINT, (WPARAM)ptc.x, (LPARAM)ptc.y); - EditSelectEx(g_hwndEdit, iNewPos, iNewPos); + EditSelectEx(g_hwndEdit, iNewPos, iNewPos, -1, -1); } if (pt.x == -1 && pt.y == -1) { @@ -2308,6 +2308,7 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam) //EnableCmd(hmenu,IDM_EDIT_TRIMLINES,!bReadOnly); //EnableCmd(hmenu,IDM_EDIT_MERGEBLANKLINES,!bReadOnly); //EnableCmd(hmenu,IDM_EDIT_REMOVEBLANKLINES,!bReadOnly); + //EnableCmd(hmenu,IDM_EDIT_REMOVEEMPTYLINES,!bReadOnly); //EnableCmd(hmenu,IDM_EDIT_REMOVEDUPLICATELINES,!bReadOnly); EnableCmd(hmenu, IDM_EDIT_SORTLINES, @@ -3237,7 +3238,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) { BeginWaitCursor(NULL); int token = BeginUndoAction(); - EditRemoveBlankLines(g_hwndEdit,TRUE); + EditRemoveBlankLines(g_hwndEdit, TRUE, TRUE); EndUndoAction(token); EndWaitCursor(); } @@ -3248,7 +3249,18 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) { BeginWaitCursor(NULL); int token = BeginUndoAction(); - EditRemoveBlankLines(g_hwndEdit,FALSE); + EditRemoveBlankLines(g_hwndEdit, FALSE, TRUE); + EndUndoAction(token); + EndWaitCursor(); + } + break; + + + case IDM_EDIT_REMOVEEMPTYLINES: + { + BeginWaitCursor(NULL); + int token = BeginUndoAction(); + EditRemoveBlankLines(g_hwndEdit, FALSE, FALSE); EndUndoAction(token); EndWaitCursor(); } @@ -7776,9 +7788,7 @@ BOOL FileLoad(BOOL bDontSave, BOOL bNew, BOOL bReload, BOOL bSkipUnicodeDetect, SendMessage(g_hwndEdit, SCI_GOTOPOS, (WPARAM)iCaretPos, 0); // adjust view const DocPos iCurPos = SciCall_GetCurrentPos(); - const DocLn iLine = SciCall_LineFromPosition(iCurPos); - const DocPos iCol = SciCall_GetColumn(iCurPos); - EditJumpTo(g_hwndEdit, iLine+1, iCol+1); + EditJumpTo(g_hwndEdit, SciCall_LineFromPosition(iCurPos) + 1, SciCall_GetColumn(iCurPos) + 1); } } @@ -7813,20 +7823,20 @@ BOOL FileLoad(BOOL bDontSave, BOOL bNew, BOOL bReload, BOOL bSkipUnicodeDetect, // BOOL FileRevert(LPCWSTR szFileName) { - if (wcslen(szFileName)) { + if (StringCchLen(szFileName, MAX_PATH) != 0) { + + const DocPos iCurPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionCaret() : SciCall_GetCurrentPos(); + const DocPos iAnchorPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionAnchor() : SciCall_GetAnchor(); + const int vSpcCaretPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionCaretVirtualSpace() : -1; + const int vSpcAnchorPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionAnchorVirtualSpace() : -1; - const DocPos iCurPos = SciCall_GetCurrentPos(); - const DocPos iAnchorPos = SciCall_GetAnchor(); const DocLn iCurrLine = SciCall_LineFromPosition(iCurPos); - DocLn iVisTopLine = (DocLn)SendMessage(g_hwndEdit,SCI_GETFIRSTVISIBLELINE,0,0); - DocLn iDocTopLine = (DocLn)SendMessage(g_hwndEdit,SCI_DOCLINEFROMVISIBLE,(WPARAM)iVisTopLine,0); - int iXOffset = (int)SendMessage(g_hwndEdit,SCI_GETXOFFSET,0,0); - BOOL bIsTail = (iCurPos == iAnchorPos) && (iCurrLine >= (SciCall_GetLineCount() - 1)); + const BOOL bIsTail = (iCurPos == iAnchorPos) && (iCurrLine >= (SciCall_GetLineCount() - 1)); Encoding_SrcWeak(Encoding_Current(CPI_GET)); WCHAR tchFileName2[MAX_PATH] = { L'\0' }; - StringCchCopy(tchFileName2,COUNTOF(tchFileName2),szFileName); + StringCchCopyW(tchFileName2,COUNTOF(tchFileName2),szFileName); if (FileLoad(TRUE,FALSE,TRUE,FALSE,TRUE,tchFileName2)) { @@ -7834,15 +7844,11 @@ BOOL FileRevert(LPCWSTR szFileName) SendMessage(g_hwndEdit, SCI_DOCUMENTEND, 0, 0); EditEnsureSelectionVisible(g_hwndEdit); } - else if (SendMessage(g_hwndEdit,SCI_GETLENGTH,0,0) >= 4) { + else if (SciCall_GetTextLength() >= 4) { char tch[5] = { '\0' }; - SendMessage(g_hwndEdit,SCI_GETTEXT,5,(LPARAM)tch); + SciCall_GetText(5, tch); if (StringCchCompareXA(tch,".LOG") != 0) { - SendMessage(g_hwndEdit,SCI_SETSEL,iAnchorPos,iCurPos); - SendMessage(g_hwndEdit,SCI_ENSUREVISIBLE,(WPARAM)iDocTopLine,0); - DocLn iNewTopLine = (DocLn)SendMessage(g_hwndEdit,SCI_GETFIRSTVISIBLELINE,0,0); - SendMessage(g_hwndEdit,SCI_LINESCROLL,0,(LPARAM)iVisTopLine - iNewTopLine); - SendMessage(g_hwndEdit,SCI_SETXOFFSET,(WPARAM)iXOffset,0); + EditSelectEx(g_hwndEdit, iAnchorPos, iCurPos, vSpcAnchorPos, vSpcCaretPos); } } return TRUE; diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 4172bfecf..9e49feb11 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -183,9 +183,10 @@ BEGIN MENUITEM "&Fuse Lines\tCtrl+Alt+J", IDM_EDIT_JOINLN_NOSP MENUITEM "&Preserve Paragraphs\tCtrl+Shift+J", IDM_EDIT_JOINLINES_PARA MENUITEM SEPARATOR - MENUITEM "Merge &Blank Lines\tAlt+Y", IDM_EDIT_MERGEBLANKLINES - MENUITEM "&Remove Blank Lines\tAlt+R", IDM_EDIT_REMOVEBLANKLINES - MENUITEM "Rem&ove Duplicate Lines\tCtrl+Alt+D", IDM_EDIT_REMOVEDUPLICATELINES + MENUITEM "Mer&ge Empty Lines\tAlt+Y", IDM_EDIT_MERGEBLANKLINES + MENUITEM "&Remove Empty Lines\tAlt+R", IDM_EDIT_REMOVEEMPTYLINES + MENUITEM "Remove &Blank Lines\tCtrl+Alt+B", IDM_EDIT_REMOVEBLANKLINES + MENUITEM "Rem&ove Duplicate Lines\tCtrl+Alt+D", IDM_EDIT_REMOVEDUPLICATELINES END POPUP "&Block" BEGIN @@ -451,6 +452,7 @@ BEGIN "B", IDM_EDIT_FINDMATCHINGBRACE, VIRTKEY, CONTROL, NOINVERT "B", IDM_EDIT_PADWITHSPACES, VIRTKEY, ALT, NOINVERT "B", IDM_EDIT_SELTOMATCHINGBRACE, VIRTKEY, SHIFT, CONTROL, NOINVERT + "B", IDM_EDIT_REMOVEBLANKLINES, VIRTKEY, CONTROL, ALT, NOINVERT "C", IDM_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT "C", IDM_EDIT_COPYALL, VIRTKEY, ALT, NOINVERT "C", IDM_EDIT_HEX2CHAR, VIRTKEY, CONTROL, ALT, NOINVERT @@ -505,7 +507,7 @@ BEGIN "Q", IDM_EDIT_ENCLOSESELECTION, VIRTKEY, ALT, NOINVERT "Q", IDM_EDIT_STREAMCOMMENT, VIRTKEY, SHIFT, CONTROL, NOINVERT "R", IDM_FILE_RUN, VIRTKEY, CONTROL, NOINVERT - "R", IDM_EDIT_REMOVEBLANKLINES, VIRTKEY, ALT, NOINVERT + "R", IDM_EDIT_REMOVEEMPTYLINES, VIRTKEY, ALT, NOINVERT "R", IDM_EDIT_UNESCAPECCHARS, VIRTKEY, CONTROL, ALT, NOINVERT "R", IDM_EDIT_URLDECODE, VIRTKEY, SHIFT, CONTROL, NOINVERT "S", IDM_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT diff --git a/src/SciCall.h b/src/SciCall.h index 755f887fd..613bd6f70 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -154,7 +154,6 @@ DeclareSciCallV1(SetRectangularSelectionCaretVirtualSpace, SETRECTANGULARSELECTI DeclareSciCallR0(GetRectangularSelectionAnchorVirtualSpace, GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, DocPos) DeclareSciCallV1(SetRectangularSelectionAnchorVirtualSpace, SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, DocPos, position) - // Multiselections (Lines of Rectangular selection) DeclareSciCallR0(GetSelections, GETSELECTIONS, DocPosU) DeclareSciCallR1(GetSelectionNCaret, GETSELECTIONNCARET, DocPos, DocPosU, selnum) @@ -174,7 +173,7 @@ DeclareSciCallV0(Clear, CLEAR) DeclareSciCallV0(CopyAllowLine, COPYALLOWLINE) DeclareSciCallV0(LineDelete, LINEDELETE) DeclareSciCallV2(CopyText, COPYTEXT, DocPos, length, const char*, text) -DeclareSciCallV2(GetTextFromBegin, GETTEXT, DocPos, length, const char*, text) +DeclareSciCallV2(GetText, GETTEXT, DocPos, length, const char*, text) DeclareSciCallV2(SetSel, SETSEL, DocPos, anchorPos, DocPos, currentPos) DeclareSciCallV0(SelectAll, SELECTALL) diff --git a/src/resource.h b/src/resource.h index 9fa8b17a0..d2ae8a376 100644 --- a/src/resource.h +++ b/src/resource.h @@ -363,6 +363,7 @@ #define IDM_EDIT_COMPLETEWORD 40373 #define IDM_EDIT_JOINLN_NOSP 40374 #define IDM_EDIT_REMOVEDUPLICATELINES 40375 +#define IDM_EDIT_REMOVEEMPTYLINES 40376 #define IDM_VIEW_SCHEME 40400 #define IDM_VIEW_USE2NDDEFAULT 40401 #define IDM_VIEW_SCHEMECONFIG 40402