From ed5dbb219537b1960d516a5926c0c12cdb99e243 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Tue, 17 Sep 2019 22:25:42 +0200 Subject: [PATCH 1/2] + fix: crash on lexicographical sort --- src/Edit.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index bc9d4803d..a553df04a 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -4271,8 +4271,13 @@ int CmpStdIRev(const void* s1, const void* s2) { return -1 * CmpStdI(s1, s2); } // ---------------------------------------------------------------------------- int CmpLexicographical(const void *s1, const void *s2) { - int const cmp = wcscmp(((SORTLINE*)s1)->pwszSortEntry,((SORTLINE*)s2)->pwszSortEntry); - return (cmp) ? cmp : wcscmp(((SORTLINE*)s1)->pwszLine,((SORTLINE*)s2)->pwszLine); + LPCWSTR const pwszSE1 = ((SORTLINE*)s1)->pwszSortEntry; + LPCWSTR const pwszSE2 = ((SORTLINE*)s2)->pwszSortEntry; + if (pwszSE1 && pwszSE2) { + int const cmp = wcscmp(pwszSE1, pwszSE2); + return (cmp) ? cmp : wcscmp(((SORTLINE*)s1)->pwszLine, ((SORTLINE*)s2)->pwszLine); + } + return pwszSE1 ? -1 : (pwszSE2 ? 1 : 0); } //int CmpLexicographicalI(const void* s1, const void* s2) { From 8ab83f0e1c6b0dfa39d2b5d8bbcd0f5fc5d0a8e0 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 18 Sep 2019 00:02:47 +0200 Subject: [PATCH 2/2] + chg: Thin rectangular (multi) selection after toggeling line-comment block --- Versions/build.txt | 2 +- res/Notepad3.exe.manifest.conf | 2 +- src/Edit.c | 90 +++++++++++++++++++++------------- src/Notepad3.c | 47 +++++++++++------- src/SciCall.h | 1 + src/VersionEx.h | 4 +- 6 files changed, 90 insertions(+), 56 deletions(-) diff --git a/Versions/build.txt b/Versions/build.txt index bec09296c..48adac332 100644 --- a/Versions/build.txt +++ b/Versions/build.txt @@ -1 +1 @@ -2639 +2640 diff --git a/res/Notepad3.exe.manifest.conf b/res/Notepad3.exe.manifest.conf index 15241df9b..5c87d7550 100644 --- a/res/Notepad3.exe.manifest.conf +++ b/res/Notepad3.exe.manifest.conf @@ -3,7 +3,7 @@ Notepad3 BETA diff --git a/src/Edit.c b/src/Edit.c index a553df04a..28b3b6743 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -3181,8 +3181,9 @@ void EditEncloseSelection(HWND hwnd, LPCWSTR pwszOpen, LPCWSTR pwszClose) // void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, bool bInsertAtStart) { - const DocPos iCurPos = SciCall_GetCurrentPos(); - const DocPos iAnchorPos = SciCall_GetAnchor(); + UNUSED(hwnd); + //const DocPos iCurPos = SciCall_GetCurrentPos(); + //const DocPos iAnchorPos = SciCall_GetAnchor(); const DocPos iSelStart = SciCall_GetSelectionStart(); const DocPos iSelEnd = SciCall_GetSelectionEnd(); @@ -3235,9 +3236,14 @@ void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, bool bInsertAtStart) int iAction = 0; - for (DocLn iLine = iLineStart; iLine <= iLineEnd; iLine++) + UT_icd docpos_icd = { sizeof(DocPos), NULL, NULL, NULL }; + UT_array* sel_positions = NULL; + utarray_new(sel_positions, &docpos_icd); + utarray_reserve(sel_positions, (int)(iLineEnd - iLineStart + 1)); + + for (DocLn iLine = iLineStart; iLine <= iLineEnd; ++iLine) { - const DocPos iIndentPos = SciCall_GetLineIndentPosition(iLine); + DocPos const iIndentPos = SciCall_GetLineIndentPosition(iLine); if (iIndentPos == SciCall_GetLineEndPosition(iLine)) { // don't set comment char on "empty" (white-space only) lines @@ -3249,53 +3255,69 @@ void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, bool bInsertAtStart) if (StrCmpNIA(tchBuf, mszComment, (int)cchComment) == 0) { // remove comment chars + DocPos const iSelPos = iIndentPos + cchComment; switch (iAction) { - case 0: - iAction = 2; - case 2: - SciCall_SetTargetRange(iIndentPos, iIndentPos + cchComment); - SciCall_ReplaceTarget(0, ""); - iSelEndOffset -= cchComment; - if (iLine == iLineStart) { - iSelStartOffset = (iSelStart == SciCall_PositionFromLine(iLine)) ? 0 : (0 - cchComment); - } - break; - case 1: - break; + case 0: + iAction = 2; + case 2: + SciCall_SetTargetRange(iIndentPos, iSelPos); + SciCall_ReplaceTarget(0, ""); + iSelEndOffset -= cchComment; + if (iLine == iLineStart) { + iSelStartOffset = (iSelStart == SciCall_PositionFromLine(iLine)) ? 0 : (0 - cchComment); + } + utarray_push_back(sel_positions, &iIndentPos); + break; + case 1: + utarray_push_back(sel_positions, &iSelPos); + break; } } else { // set comment chars at indent pos switch (iAction) { - case 0: - iAction = 1; - case 1: + case 0: + iAction = 1; + case 1: { - SciCall_InsertText(SciCall_FindColumn(iLine, iCommentCol), mszComment); + DocPos const iPos = SciCall_FindColumn(iLine, iCommentCol); + SciCall_InsertText(iPos, mszComment); iSelEndOffset += cchComment; - if (iLine == iLineStart) { + if (iLine == iLineStart) { iSelStartOffset = (iCommentCol >= iSelBegCol) ? 0 : cchComment; } + DocPos const iSelPos = iIndentPos + cchComment; + utarray_push_back(sel_positions, &iSelPos); } break; - case 2: - break; + case 2: + break; } } } SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore - _OBSERVE_NOTIFY_CHANGE_; - if (iCurPos < iAnchorPos) { - EditSetSelectionEx(hwnd, iAnchorPos + iSelEndOffset, iCurPos + iSelStartOffset, -1, -1); - } - else if (iCurPos > iAnchorPos) { - EditSetSelectionEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelEndOffset, -1, -1); - } - else { - EditSetSelectionEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelStartOffset, -1, -1); + //if (iCurPos < iAnchorPos) { + // EditSetSelectionEx(hwnd, iAnchorPos + iSelEndOffset, iCurPos + iSelStartOffset, -1, -1); + //} + //else if (iCurPos > iAnchorPos) { + // EditSetSelectionEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelEndOffset, -1, -1); + //} + //else { + // EditSetSelectionEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelStartOffset, -1, -1); + //} + + DocPos* p = (DocPos*)utarray_next(sel_positions, NULL); + if (p) { SciCall_SetSelection(*p, *p); } + while (p) { + p = (DocPos*)utarray_next(sel_positions, p); + if (p) { SciCall_AddSelection(*p, *p); } } + utarray_free(sel_positions); + + + _OBSERVE_NOTIFY_CHANGE_; _END_UNDO_ACTION_ } @@ -4448,9 +4470,7 @@ void EditSortLines(HWND hwnd, int iSortFlags) char* pmszResOffset = pmszResult; char* pmszBuf = AllocMem(ichlMax + 1, HEAP_ZERO_MEMORY); - FNSTRCMP const pFctStrCmp = (iSortFlags & SORT_NOCASE) ? - ((iSortFlags & SORT_LEXICOGRAPH) ? _wcsicmp : StrCmpI) : - ((iSortFlags & SORT_LEXICOGRAPH) ? wcscmp : StrCmp); + FNSTRCMP const pFctStrCmp = (iSortFlags & SORT_NOCASE) ? StrCmpI : StrCmp; bool bLastDup = false; for (DocLn i = 0; i < iLineCount; ++i) { diff --git a/src/Notepad3.c b/src/Notepad3.c index 8d74a7cc1..1f160efbc 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -5566,24 +5566,37 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case CMD_ESCAPE: - if (SciCall_CallTipActive() || SciCall_AutoCActive()) { - CancelCallTip(); - SciCall_AutoCCancel(); - } - else if (s_bIndicMultiEdit) { - SciCall_SetIndicatorCurrent(INDIC_NP3_MULTI_EDIT); - SciCall_IndicatorClearRange(0, Sci_GetDocEndPosition()); - s_bIndicMultiEdit = false; - } - else if (Settings.EscFunction == 1) { - SendMessage(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0); - } - else if (Settings.EscFunction == 2) { - CloseApplication(true); - } - else { + { + DocPos const iCurPos = SciCall_GetCurrentPos(); + + if (SciCall_CallTipActive() || SciCall_AutoCActive()) { + CancelCallTip(); + SciCall_AutoCCancel(); + break; + } + else if (s_bIndicMultiEdit) { + _BEGIN_UNDO_ACTION_ + SciCall_SetIndicatorCurrent(INDIC_NP3_MULTI_EDIT); + SciCall_IndicatorClearRange(0, Sci_GetDocEndPosition()); + SciCall_ClearSelections(); + _END_UNDO_ACTION_ + s_bIndicMultiEdit = false; + } + else if (Settings.EscFunction == 1) { + SendMessage(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0); + break; + } + else if (Settings.EscFunction == 2) { + CloseApplication(true); + break; + } + if (!SciCall_IsSelectionEmpty()) { - DocPos const iCurPos = SciCall_GetCurrentPos(); + _BEGIN_UNDO_ACTION_ + EditSetSelectionEx(Globals.hwndEdit, iCurPos, iCurPos, -1, -1); + _END_UNDO_ACTION_ + } + else { EditSetSelectionEx(Globals.hwndEdit, iCurPos, iCurPos, -1, -1); } SciCall_Cancel(); diff --git a/src/SciCall.h b/src/SciCall.h index 958ea33ce..4e4d227e8 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -169,6 +169,7 @@ DeclareSciCallR0(GetSelectionMode, GETSELECTIONMODE, int) DeclareSciCallV1(SetSelectionMode, SETSELECTIONMODE, int, mode) DeclareSciCallR0(GetSelections, GETSELECTIONS, DocPosU) DeclareSciCallV2(SetSelection, SETSELECTION, DocPos, caretPos, DocPos, anchorPos) +DeclareSciCallV2(AddSelection, ADDSELECTION, DocPos, caretPos, DocPos, anchorPos) DeclareSciCallR0(GetMainSelection, GETMAINSELECTION, DocPosU) DeclareSciCallV1(SetMainSelection, SETMAINSELECTION, DocPosU, selnum) DeclareSciCallR1(GetSelectionNCaret, GETSELECTIONNCARET, DocPos, DocPosU, selnum) diff --git a/src/VersionEx.h b/src/VersionEx.h index 2ad2d4157..a70121fc2 100644 --- a/src/VersionEx.h +++ b/src/VersionEx.h @@ -7,8 +7,8 @@ #define SAPPNAME "Notepad3" #define VERSION_MAJOR 5 #define VERSION_MINOR 19 -#define VERSION_REV 916 -#define VERSION_BUILD 2639 +#define VERSION_REV 917 +#define VERSION_BUILD 2640 #define SCINTILLA_VER 420 #define ONIGURUMA_REGEX_VER 6.9.3 #define UCHARDET_VER 2018.09.27