mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-17 21:03:19 +08:00
+rev: reverting changes to F/R behavior, correction for empty pattern
This commit is contained in:
parent
f2bc2d6032
commit
5df65e8910
114
src/Edit.c
114
src/Edit.c
@ -5666,18 +5666,18 @@ static void _EscapeWildcards(char* szFind2, size_t cch, LPEDITFINDREPLACE lpefr
|
||||
//
|
||||
// _EditGetFindStrg()
|
||||
//
|
||||
static void _EditGetFindStrg(HWND hwnd, LPEDITFINDREPLACE lpefr, LPSTR szFind, size_t cchCnt)
|
||||
static size_t _EditGetFindStrg(HWND hwnd, LPEDITFINDREPLACE lpefr, LPSTR szFind, size_t cchCnt, bool bReplEmpty)
|
||||
{
|
||||
if (!lpefr) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!StrIsEmptyA(lpefr->szFind)) {
|
||||
StringCchCopyA(szFind, cchCnt, lpefr->szFind);
|
||||
} else {
|
||||
if (StrIsEmptyA(lpefr->szFind) && bReplEmpty) {
|
||||
CopyFindPatternMB(szFind, cchCnt);
|
||||
} else {
|
||||
StringCchCopyA(szFind, cchCnt, lpefr->szFind);
|
||||
}
|
||||
if (StrIsEmptyA(szFind)) {
|
||||
if (StrIsEmptyA(szFind) && bReplEmpty) {
|
||||
// get most recently used find pattern
|
||||
WCHAR mruItem[FNDRPL_BUFFER] = { L'\0' };
|
||||
MRU_Enum(Globals.pMRUfind, 0, mruItem, COUNTOF(mruItem));
|
||||
@ -5685,7 +5685,7 @@ static void _EditGetFindStrg(HWND hwnd, LPEDITFINDREPLACE lpefr, LPSTR szFind, s
|
||||
WideCharToMultiByte(Encoding_SciCP, 0, mruItem, -1, szFind, (int)cchCnt, NULL, NULL);
|
||||
}
|
||||
}
|
||||
if (StrIsEmptyA(szFind)) {
|
||||
if (StrIsEmptyA(szFind) && bReplEmpty) {
|
||||
// get clipboard content
|
||||
char *const pClip = EditGetClipboardText(hwnd, false, NULL, NULL);
|
||||
if (!StrIsEmptyA(pClip)) {
|
||||
@ -5693,8 +5693,9 @@ static void _EditGetFindStrg(HWND hwnd, LPEDITFINDREPLACE lpefr, LPSTR szFind, s
|
||||
}
|
||||
FreeMem(pClip);
|
||||
}
|
||||
|
||||
if (StrIsEmptyA(szFind)) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ensure to F/R-dialog data structure consistency
|
||||
@ -5707,6 +5708,34 @@ static void _EditGetFindStrg(HWND hwnd, LPEDITFINDREPLACE lpefr, LPSTR szFind, s
|
||||
if (lpefr->bTransformBS || bIsRegEx) {
|
||||
TransformBackslashes(szFind, bIsRegEx, Encoding_SciCP, NULL);
|
||||
}
|
||||
|
||||
return StringCchLenA(szFind, cchCnt);
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// _GetReplaceString()
|
||||
//
|
||||
static char* _GetReplaceString(HWND hwnd, CLPCEDITFINDREPLACE lpefr, int* iReplaceMsg)
|
||||
{
|
||||
char* pszReplace = NULL; // replace text of arbitrary size
|
||||
if (StringCchCompareNIA(lpefr->szReplace, COUNTOF(lpefr->szReplace), "^c", 2) == 0) {
|
||||
*iReplaceMsg = SCI_REPLACETARGET;
|
||||
pszReplace = EditGetClipboardText(hwnd, true, NULL, NULL);
|
||||
}
|
||||
else {
|
||||
size_t const cch = StringCchLenA(lpefr->szReplace, COUNTOF(lpefr->szReplace));
|
||||
pszReplace = (char*)AllocMem(cch + 1, HEAP_ZERO_MEMORY);
|
||||
if (pszReplace) {
|
||||
StringCchCopyA(pszReplace, SizeOfMem(pszReplace), lpefr->szReplace);
|
||||
bool const bIsRegEx = (lpefr->fuFlags & SCFIND_REGEXP);
|
||||
if (lpefr->bTransformBS || bIsRegEx) {
|
||||
TransformBackslashes(pszReplace, bIsRegEx, Encoding_SciCP, iReplaceMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pszReplace; // move ownership
|
||||
}
|
||||
|
||||
|
||||
@ -5779,7 +5808,8 @@ typedef enum { MATCH = 0, NO_MATCH = 1, INVALID = 2 } RegExResult_t;
|
||||
|
||||
static RegExResult_t _FindHasMatch(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos, bool bMarkAll)
|
||||
{
|
||||
DocPos const slen = strlen(lpefr->szFind);
|
||||
char szFind[FNDRPL_BUFFER] = { '\0' };
|
||||
DocPos const slen = _EditGetFindStrg(hwnd, lpefr, szFind, COUNTOF(szFind), bMarkAll);
|
||||
if (slen == 0) {
|
||||
return NO_MATCH;
|
||||
}
|
||||
@ -5790,12 +5820,12 @@ static RegExResult_t _FindHasMatch(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iS
|
||||
|
||||
DocPos start = iStart;
|
||||
DocPos end = iTextEnd;
|
||||
DocPos const iPos = _FindInTarget(lpefr->szFind, slen, sFlags, &start, &end, false, FRMOD_IGNORE);
|
||||
DocPos const iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, false, FRMOD_IGNORE);
|
||||
|
||||
if (bMarkAll) {
|
||||
EditClearAllOccurrenceMarkers(hwnd);
|
||||
if (iPos >= 0) {
|
||||
EditMarkAll(lpefr->szFind, (int)(lpefr->fuFlags), 0, iTextEnd, false);
|
||||
EditMarkAll(szFind, (int)(lpefr->fuFlags), 0, iTextEnd, false);
|
||||
if (FocusedView.HideNonMatchedLines) {
|
||||
EditFoldMarkedLineRange(lpefr->hwnd, true);
|
||||
}
|
||||
@ -6381,7 +6411,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
|
||||
// if first time you bring up find/replace dialog,
|
||||
// use most recent search pattern to find box
|
||||
// in case of no history: paste clipboard
|
||||
_EditGetFindStrg(Globals.hwndEdit, s_pEfrDataDlg, lpszSelection, SizeOfMem(lpszSelection));
|
||||
_EditGetFindStrg(Globals.hwndEdit, s_pEfrDataDlg, lpszSelection, SizeOfMem(lpszSelection), true);
|
||||
}
|
||||
}
|
||||
if (lpszSelection) {
|
||||
@ -6402,6 +6432,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
|
||||
|
||||
_SetSearchFlags(hwnd, s_pEfrDataDlg);
|
||||
SetFindPatternMB(s_pEfrDataDlg->szFind);
|
||||
EditClearAllOccurrenceMarkers(s_pEfrDataDlg->hwnd);
|
||||
|
||||
if (s_pEfrDataDlg->bWildcardSearch) {
|
||||
_EscapeWildcards(s_pEfrDataDlg->szFind, COUNTOF(s_pEfrDataDlg->szFind), s_pEfrDataDlg);
|
||||
@ -6874,15 +6905,14 @@ bool EditFindNext(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo
|
||||
SetFocus(hwnd);
|
||||
}
|
||||
|
||||
DocPos const slen = strlen(lpefr->szFind);
|
||||
char szFind[FNDRPL_BUFFER];
|
||||
DocPos const slen = _EditGetFindStrg(hwnd, lpefr, szFind, COUNTOF(szFind), false);
|
||||
if (slen <= 0LL) {
|
||||
return false;
|
||||
}
|
||||
int const sFlags = (int)(lpefr->fuFlags);
|
||||
|
||||
DocPos const iDocEndPos = Sci_GetDocEndPosition();
|
||||
//DocPos const iSelStartPos = SciCall_GetSelectionStart();
|
||||
//DocPos const iSelEndPos = SciCall_GetSelectionEnd();
|
||||
|
||||
EditSetCaretToSelectionEnd(); // fluent swittch between Prev/Next
|
||||
DocPos start = SciCall_GetCurrentPos();
|
||||
@ -6890,7 +6920,7 @@ bool EditFindNext(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo
|
||||
|
||||
SciCall_CallTipCancel();
|
||||
|
||||
DocPos iPos = _FindInTarget(lpefr->szFind, slen, sFlags, &start, &end, true, FRMOD_NORM);
|
||||
DocPos iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, true, FRMOD_NORM);
|
||||
|
||||
if ((iPos < -1LL) && (lpefr->fuFlags & SCFIND_REGEXP)) {
|
||||
InfoBoxLng(MB_ICONWARNING, L"MsgInvalidRegex", IDS_MUI_REGEX_INVALID);
|
||||
@ -6902,7 +6932,7 @@ bool EditFindNext(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo
|
||||
//DocPos const _end = end;
|
||||
end = min_p(start, iDocEndPos);
|
||||
start = 0LL;
|
||||
iPos = _FindInTarget(lpefr->szFind, slen, sFlags, &start, &end, false, FRMOD_WRAPED);
|
||||
iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, false, FRMOD_WRAPED);
|
||||
|
||||
if ((iPos < 0LL) || (end == _start)) {
|
||||
if ((iPos < -1) && (lpefr->fuFlags & SCFIND_REGEXP)) {
|
||||
@ -6958,15 +6988,14 @@ bool EditFindPrev(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo
|
||||
if (bFocusWnd) {
|
||||
SetFocus(hwnd);
|
||||
}
|
||||
DocPos const slen = strlen(lpefr->szFind);
|
||||
char szFind[FNDRPL_BUFFER];
|
||||
DocPos const slen = _EditGetFindStrg(hwnd, lpefr, szFind, COUNTOF(szFind), false);
|
||||
if (slen <= 0LL) {
|
||||
return false;
|
||||
}
|
||||
int const sFlags = (int)(lpefr->fuFlags);
|
||||
|
||||
DocPos const iDocEndPos = Sci_GetDocEndPosition();
|
||||
//DocPos const iSelStartPos = SciCall_GetSelectionStart();
|
||||
//DocPos const iSelEndPos = SciCall_GetSelectionEnd();
|
||||
|
||||
EditSetCaretToSelectionStart(); // fluent switch between Next/Prev
|
||||
DocPos start = SciCall_GetCurrentPos();
|
||||
@ -6974,7 +7003,7 @@ bool EditFindPrev(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo
|
||||
|
||||
SciCall_CallTipCancel();
|
||||
|
||||
DocPos iPos = _FindInTarget(lpefr->szFind, slen, sFlags, &start, &end, true, FRMOD_NORM);
|
||||
DocPos iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, true, FRMOD_NORM);
|
||||
|
||||
if ((iPos < -1LL) && (sFlags & SCFIND_REGEXP)) {
|
||||
InfoBoxLng(MB_ICONWARNING, L"MsgInvalidRegex", IDS_MUI_REGEX_INVALID);
|
||||
@ -6986,7 +7015,7 @@ bool EditFindPrev(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo
|
||||
//DocPos const _end = end;
|
||||
end = max_p(start, 0LL);
|
||||
start = iDocEndPos;
|
||||
iPos = _FindInTarget(lpefr->szFind, slen, sFlags, &start, &end, false, FRMOD_WRAPED);
|
||||
iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, false, FRMOD_WRAPED);
|
||||
|
||||
if ((iPos < 0LL) || (start == _start)) {
|
||||
if ((iPos < -1LL) && (sFlags & SCFIND_REGEXP)) {
|
||||
@ -7108,31 +7137,6 @@ void EditSelectionMultiSelectAllEx(CLPCEDITFINDREPLACE edFndRpl)
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// _GetReplaceString()
|
||||
//
|
||||
static char* _GetReplaceString(HWND hwnd, CLPCEDITFINDREPLACE lpefr, int* iReplaceMsg)
|
||||
{
|
||||
char* pszReplace = NULL; // replace text of arbitrary size
|
||||
if (StringCchCompareNIA(lpefr->szReplace, COUNTOF(lpefr->szReplace), "^c", 2) == 0) {
|
||||
*iReplaceMsg = SCI_REPLACETARGET;
|
||||
pszReplace = EditGetClipboardText(hwnd, true, NULL, NULL);
|
||||
} else {
|
||||
size_t const cch = StringCchLenA(lpefr->szReplace, COUNTOF(lpefr->szReplace));
|
||||
pszReplace = (char*)AllocMem(cch + 1, HEAP_ZERO_MEMORY);
|
||||
if (pszReplace) {
|
||||
StringCchCopyA(pszReplace, SizeOfMem(pszReplace), lpefr->szReplace);
|
||||
bool const bIsRegEx = (lpefr->fuFlags & SCFIND_REGEXP);
|
||||
if (lpefr->bTransformBS || bIsRegEx) {
|
||||
TransformBackslashes(pszReplace, bIsRegEx, Encoding_SciCP, iReplaceMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pszReplace; // move ownership
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditReplace()
|
||||
@ -7153,9 +7157,10 @@ bool EditReplace(HWND hwnd, LPEDITFINDREPLACE lpefr)
|
||||
DocPos _start = start;
|
||||
Globals.iReplacedOccurrences = 0;
|
||||
|
||||
DocPos const slen = strlen(lpefr->szFind);
|
||||
int const sFlags = (int)(lpefr->fuFlags);
|
||||
DocPos const iPos = _FindInTarget(lpefr->szFind, slen, sFlags, &start, &end, false, FRMOD_NORM);
|
||||
char szFind[FNDRPL_BUFFER];
|
||||
DocPos const slen = _EditGetFindStrg(hwnd, lpefr, szFind, COUNTOF(szFind), false);
|
||||
int const sFlags = (int)(lpefr->fuFlags);
|
||||
DocPos const iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, false, FRMOD_NORM);
|
||||
|
||||
// w/o selection, replacement string is put into current position
|
||||
// but this maybe not intended here
|
||||
@ -7206,13 +7211,14 @@ int EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos,
|
||||
}
|
||||
DocPos const iOrigEndPos = iEndPos; // remember
|
||||
|
||||
DocPos const slen = strlen(lpefr->szFind);
|
||||
char szFind[FNDRPL_BUFFER];
|
||||
DocPos const slen = _EditGetFindStrg(hwnd, lpefr, szFind, COUNTOF(szFind), false);
|
||||
if (slen <= 0) {
|
||||
return FALSE;
|
||||
}
|
||||
int const sFlags = (int)(lpefr->fuFlags);
|
||||
bool const bIsRegExpr = (sFlags & SCFIND_REGEXP);
|
||||
bool const bRegexStartOfLine = bIsRegExpr && (lpefr->szFind[0] == '^');
|
||||
bool const bRegexStartOfLine = bIsRegExpr && (szFind[0] == '^');
|
||||
|
||||
// SCI_REPLACETARGET or SCI_REPLACETARGETRE
|
||||
int iReplaceMsg = SCI_REPLACETARGET;
|
||||
@ -7226,7 +7232,7 @@ int EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos,
|
||||
|
||||
DocPos start = iStartPos;
|
||||
DocPos end = iEndPos;
|
||||
DocPos iPos = _FindInTarget(lpefr->szFind, slen, sFlags, &start, &end, false, FRMOD_NORM);
|
||||
DocPos iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, false, FRMOD_NORM);
|
||||
|
||||
if ((iPos < -1LL) && bIsRegExpr) {
|
||||
InfoBoxLng(MB_ICONWARNING, L"MsgInvalidRegex", IDS_MUI_REGEX_INVALID);
|
||||
@ -7248,7 +7254,7 @@ int EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos,
|
||||
iEndPos += replLen - (end - iPos);
|
||||
start = iStartPos;
|
||||
end = iEndPos;
|
||||
iPos = (start <= end) ? _FindInTarget(lpefr->szFind, slen, sFlags, &start, &end, true, FRMOD_NORM) : -1LL;
|
||||
iPos = (start <= end) ? _FindInTarget(szFind, slen, sFlags, &start, &end, true, FRMOD_NORM) : -1LL;
|
||||
}
|
||||
EndUndoTransAction();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user