From 505f98e69152103adfcb9ec5f7d72baaa7addd6d Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Tue, 16 May 2023 09:47:32 +0200 Subject: [PATCH] +fix: minor issue related to match selection counters --- src/Edit.c | 53 +++++++++++++++++++++++++++----------------------- src/Edit.h | 2 +- src/Notepad3.c | 29 +++++++++++++-------------- src/TypeDefs.h | 2 +- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index ee35437ca..9ca601788 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -6269,7 +6269,6 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar CheckDlgButton(hwnd, IDC_ALL_OCCURRENCES, SetBtn(s_pEfrData->bMarkOccurences)); if (!s_pEfrData->bMarkOccurences) { EditClearAllOccurrenceMarkers(s_pEfrData->hwnd); - Globals.iSelectionMarkNumber = Globals.iMarkOccurrencesCount = 0; } CheckDlgButton(hwnd, IDC_INST_INCR_SEARCH, SetBtn(s_pEfrData->bInstantIncrementalSearch)); @@ -6381,7 +6380,6 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar MarkAllOccurrences(_MQ_STD, true); } else { EditClearAllOccurrenceMarkers(s_pEfrData->hwnd); - Globals.iSelectionMarkNumber = Globals.iMarkOccurrencesCount = 0; } if (s_InitialTopLine >= 0) { @@ -6686,6 +6684,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar SendWMCommand(hwnd, IDC_TOGGLE_VISIBILITY); } else { EditClearAllOccurrenceMarkers(s_pEfrData->hwnd); + InvalidateRect(GetDlgItem(hwnd, IDC_FINDTEXT), NULL, TRUE); } } s_pEfrData->bStateChanged = false; @@ -6704,7 +6703,6 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar EditToggleView(s_pEfrData->hwnd); } EditClearAllOccurrenceMarkers(s_pEfrData->hwnd); - Globals.iSelectionMarkNumber = Globals.iMarkOccurrencesCount = 0; InvalidateRect(GetDlgItem(hwnd, IDC_FINDTEXT), NULL, TRUE); } } @@ -7181,7 +7179,10 @@ bool EditFindNext(HWND hwnd, const LPEDITFINDREPLACE lpefr, bool bExtendSelectio EditSetSelectionEx(iPos, end, -1, -1); } - if (Globals.iMarkOccurrencesCount) { + if (!Globals.iSelectionMarkNumber && lpefr->bMarkOccurences) { + _FindHasMatch(hwnd, lpefr, 0, true); + } + else { ++Globals.iSelectionMarkNumber; } @@ -7270,7 +7271,10 @@ bool EditFindPrev(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo EditSetSelectionEx(end, iPos, -1, -1); } - if (Globals.iMarkOccurrencesCount) { + if (!Globals.iSelectionMarkNumber && lpefr->bMarkOccurences) { + _FindHasMatch(hwnd, lpefr, 0, true); + } + else { --Globals.iSelectionMarkNumber; } @@ -7443,7 +7447,7 @@ bool EditReplace(HWND hwnd, LPEDITFINDREPLACE lpefr) // // -int EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos, DocPos iEndPos, DocPos *enlargement) +DocPosU EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos, DocPos iEndPos, DocPos *enlargement) { if (iStartPos > iEndPos) { swapos(&iStartPos, &iEndPos); @@ -7464,7 +7468,7 @@ int EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos, int iReplaceMsg = SCI_REPLACETARGET; char* const pszReplace = _GetReplaceString(hwnd, lpefr, &iReplaceMsg); if (!pszReplace) { - return -1; // recoding of clipboard canceled + return 0; // recoding of clipboard canceled } DocPos const _saveTargetBeg_ = SciCall_GetTargetStart(); @@ -7479,7 +7483,7 @@ int EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos, return 0; } - int iCount = 0; + DocPosU iCount = 0; UndoTransActionBegin(); @@ -7532,18 +7536,18 @@ bool EditReplaceAll(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bShowInfo) EndWaitCursor(); WCHAR wchOcc[64] = { L'\0' }; - StringCchPrintf(wchOcc, COUNTOF(wchOcc), L"%i", Globals.iReplacedOccurrences); + StringCchPrintf(wchOcc, COUNTOF(wchOcc), DOCPOSFMTW, Globals.iReplacedOccurrences); FormatNumberStr(wchOcc, COUNTOF(wchOcc), 0); if (bShowInfo) { - if (Globals.iReplacedOccurrences > 0) { + if (Globals.iReplacedOccurrences) { InfoBoxLng(MB_OK, L"MsgReplaceCount", IDS_MUI_REPLCOUNT, wchOcc); } else { InfoBoxLng(MB_OK, L"MsgNotFound", IDS_MUI_NOTFOUND); } } - return (Globals.iReplacedOccurrences > 0) ? true : false; + return (bool)Globals.iReplacedOccurrences; } @@ -7568,26 +7572,24 @@ bool EditReplaceAllInSelection(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bShowInf Globals.iReplacedOccurrences = EditReplaceAllInRange(hwnd, lpefr, start, end, &enlargement); EndWaitCursor(); - if (Globals.iReplacedOccurrences > 0) { + if (Globals.iReplacedOccurrences) { if (currPos < anchorPos) { SciCall_SetSel(anchorPos + enlargement, currPos); } else { SciCall_SetSel(anchorPos, currPos + enlargement); } - if (bShowInfo) { - if (Globals.iReplacedOccurrences > 0) { - WCHAR wchOcc[64] = { L'\0' }; - StringCchPrintf(wchOcc, COUNTOF(wchOcc), L"%i", Globals.iReplacedOccurrences); - FormatNumberStr(wchOcc, COUNTOF(wchOcc), 0); - InfoBoxLng(MB_OK, L"MsgReplaceCount", IDS_MUI_REPLCOUNT, wchOcc); - } else { - InfoBoxLng(MB_OK, L"MsgNotFound", IDS_MUI_NOTFOUND); - } + WCHAR wchOcc[64] = { L'\0' }; + StringCchPrintf(wchOcc, COUNTOF(wchOcc), DOCPOSFMTW, Globals.iReplacedOccurrences); + FormatNumberStr(wchOcc, COUNTOF(wchOcc), 0); + InfoBoxLng(MB_OK, L"MsgReplaceCount", IDS_MUI_REPLCOUNT, wchOcc); } } + else if (bShowInfo) { + InfoBoxLng(MB_OK, L"MsgNotFound", IDS_MUI_NOTFOUND); + } - return (Globals.iReplacedOccurrences > 0) ? true : false; + return (bool)Globals.iReplacedOccurrences; } @@ -7599,7 +7601,6 @@ bool EditReplaceAllInSelection(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bShowInf void EditClearAllOccurrenceMarkers(HWND hwnd) { UNREFERENCED_PARAMETER(hwnd); - Globals.iMarkOccurrencesCount = Globals.iMarkOccurrencesCount = 0; LimitNotifyEvents(); @@ -7608,6 +7609,8 @@ void EditClearAllOccurrenceMarkers(HWND hwnd) SciCall_MarkerDeleteAll(MARKER_NP3_OCCURRENCE); + Globals.iSelectionMarkNumber = Globals.iMarkOccurrencesCount = 0; + RestoreNotifyEvents(); } @@ -7811,7 +7814,9 @@ void EditMarkAll(LPCWSTR wchFind, int sFlags, DocPos rangeStart, DocPos rangeEnd SciCall_MarkerAdd(SciCall_LineFromPosition(iPos), MARKER_NP3_OCCURRENCE); } ++count; - if ((iSelStart >= start) && (iSelEnd <= end)) { found = count; } + if (!found && ((iSelStart <= end) && (start <= iSelEnd))) { // intersect + found = count; + } start = end; end = rangeEnd; iPos = _FindInTarget(wchText, sFlags, &start, &end, true, FRMOD_NORM); diff --git a/src/Edit.h b/src/Edit.h index 8a4cd9385..5db9694f4 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -103,7 +103,7 @@ HWND EditFindReplaceDlg(HWND hwnd, LPEDITFINDREPLACE lpefr, bool); bool EditFindNext(HWND hwnd, const LPEDITFINDREPLACE lpefr, bool bExtendSelection, bool bFocusWnd, bool bFillEmpty); bool EditFindPrev(HWND hwnd, const LPEDITFINDREPLACE lpefr, bool bExtendSelection, bool bFocusWnd, bool bFillEmpty); bool EditReplace(HWND hwnd, LPEDITFINDREPLACE lpefr); -int EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos, DocPos iEndPos, DocPos *enlargement); +DocPosU EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos, DocPos iEndPos, DocPos *enlargement); bool EditReplaceAll(HWND hwnd, LPEDITFINDREPLACE lpefr, bool); bool EditReplaceAllInSelection(HWND hwnd, LPEDITFINDREPLACE lpefr, bool); bool EditLinenumDlg(HWND hwnd); diff --git a/src/Notepad3.c b/src/Notepad3.c index 4c099b216..c7e42fb5c 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2059,9 +2059,7 @@ HWND InitInstance(const HINSTANCE hInstance, int nCmdShow) if (s_flagStartAsTrayIcon) { SetNotifyIconTitle(Globals.hwndMain); } - Globals.iReplacedOccurrences = 0; - Globals.iSelectionMarkNumber = 0; - Globals.iMarkOccurrencesCount = 0; + Globals.iSelectionMarkNumber = Globals.iMarkOccurrencesCount = Globals.iReplacedOccurrences = 0; ResetMouseDWellTime(); @@ -6001,8 +5999,6 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) MarkAllOccurrences(_MQ_FAST, true); } else { EditClearAllOccurrenceMarkers(Globals.hwndEdit); - Globals.iSelectionMarkNumber = 0; - Globals.iMarkOccurrencesCount = 0; } break; @@ -8766,7 +8762,7 @@ static LRESULT _MsgNotifyFromEdit(HWND hwnd, const SCNotification* const scn) if (bValidSel || Settings.MarkOccurrencesCurrentWord) { MarkAllOccurrences(-1, true); } else { - if (Globals.iMarkOccurrencesCount > 0) { + if (Globals.iMarkOccurrencesCount) { EditClearAllOccurrenceMarkers(Globals.hwndEdit); } } @@ -10358,7 +10354,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) if (bForceRedraw || ((s_bMOVisible != Settings.MarkOccurrencesMatchVisible) || (s_iSeletionMarkNumber != Globals.iSelectionMarkNumber) || (s_iMarkOccurrencesCount != Globals.iMarkOccurrencesCount))) { - if (Globals.iMarkOccurrencesCount > 0) { + if (Globals.iMarkOccurrencesCount) { StringCchPrintf(tchOccOf, COUNTOF(tchOccOf), DOCPOSFMTW, Globals.iSelectionMarkNumber); FormatNumberStr(tchOccOf, COUNTOF(tchOccOf), 0); StringCchPrintf(tchOcc2, COUNTOF(tchOcc2), DOCPOSFMTW, Globals.iMarkOccurrencesCount); @@ -10386,12 +10382,11 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) // number of replaced pattern if (g_iStatusbarVisible[STATUS_OCCREPLACE] || bIsWindowFindReplace) { - static int s_iReplacedOccurrences = -1; - + static DocPosU s_iReplacedOccurrences = 0; if (bForceRedraw || (s_iReplacedOccurrences != Globals.iReplacedOccurrences)) { - static WCHAR tchRepl[32] = { L'\0' }; - if (Globals.iReplacedOccurrences > 0) { - StringCchPrintf(tchRepl, COUNTOF(tchRepl), L"%i", Globals.iReplacedOccurrences); + static WCHAR tchRepl[64] = { L'\0' }; + if (Globals.iReplacedOccurrences) { + StringCchPrintf(tchRepl, COUNTOF(tchRepl), DOCPOSFMTW, Globals.iReplacedOccurrences); FormatNumberStr(tchRepl, COUNTOF(tchRepl), 0); } else { StringCchCopy(tchRepl, COUNTOF(tchRepl), L"--"); @@ -10568,10 +10563,12 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) // update Find/Replace dialog (if any) if (bIsWindowFindReplace) { - static WCHAR tchReplOccs[32] = { L'\0' }; - if (Globals.iReplacedOccurrences > 0) { - StringCchPrintf(tchReplOccs, COUNTOF(tchReplOccs), L"%i", Globals.iReplacedOccurrences); - } else { + static WCHAR tchReplOccs[64] = { L'\0' }; + if (Globals.iReplacedOccurrences) { + StringCchPrintf(tchReplOccs, COUNTOF(tchReplOccs), DOCPOSFMTW, Globals.iReplacedOccurrences); + FormatNumberStr(tchReplOccs, COUNTOF(tchReplOccs), 0); + } + else { StringCchCopy(tchReplOccs, COUNTOF(tchReplOccs), L"--"); } diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 3822fe2c5..09a63b8c9 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -522,7 +522,7 @@ typedef struct GLOBALS_T { bool bMinimizedToTray; bool bZeroBasedColumnIndex; bool bZeroBasedCharacterCount; - int iReplacedOccurrences; + DocPosU iReplacedOccurrences; DocPosU iSelectionMarkNumber; DocPosU iMarkOccurrencesCount; bool bUseLimitedAutoCCharSet;