mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
+ fix: small issues on Find/Replace Next/Previous operations
This commit is contained in:
parent
6b662fdaa4
commit
803f7ba4e8
123
src/Edit.c
123
src/Edit.c
@ -2256,6 +2256,35 @@ void EditMoveDown(HWND hwnd)
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditJumpToSelectionStart()
|
||||
//
|
||||
void EditJumpToSelectionStart(HWND hwnd)
|
||||
{
|
||||
UNUSED(hwnd);
|
||||
if (!SciCall_IsSelectionRectangle()) {
|
||||
if (SciCall_GetCurrentPos() != SciCall_GetSelectionStart()) {
|
||||
SciCall_SwapMainAnchorCaret();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditJumpToSelectionEnd()
|
||||
//
|
||||
void EditJumpToSelectionEnd(HWND hwnd)
|
||||
{
|
||||
UNUSED(hwnd);
|
||||
if (!SciCall_IsSelectionRectangle()) {
|
||||
if (SciCall_GetCurrentPos() != SciCall_GetSelectionEnd()) {
|
||||
SciCall_SwapMainAnchorCaret();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditModifyLines()
|
||||
@ -3211,8 +3240,7 @@ void EditStripFirstCharacter(HWND hwnd)
|
||||
|
||||
DocPos remCount = 0;
|
||||
const DocPosU selCount = SciCall_GetSelections();
|
||||
for (DocPosU s = 0; s < selCount; ++s)
|
||||
{
|
||||
for (DocPosU s = 0; s < selCount; ++s) {
|
||||
const DocPos selCaretPos = SciCall_GetSelectionNCaret(s);
|
||||
const DocPos selAnchorPos = SciCall_GetSelectionNAnchor(s);
|
||||
//const DocPos vSpcCaretPos = SciCall_GetSelectionNCaretVirtualSpace(s);
|
||||
@ -3228,7 +3256,7 @@ void EditStripFirstCharacter(HWND hwnd)
|
||||
const DocPos len = (selTargetEnd - nextPos);
|
||||
if ((len >= 0) && (len < TEMPLINE_BUFFER)) //TODO: @@@ alloc memory dynamically
|
||||
{
|
||||
StringCchCopyNA(g_pTempLineBuffer, TEMPLINE_BUFFER, SciCall_GetRangePointer(nextPos, len+1), len);
|
||||
StringCchCopyNA(g_pTempLineBuffer, TEMPLINE_BUFFER, SciCall_GetRangePointer(nextPos, len + 1), len);
|
||||
SciCall_SetTargetRange(selTargetStart, selTargetEnd);
|
||||
SciCall_ReplaceTarget(len, g_pTempLineBuffer);
|
||||
}
|
||||
@ -4341,6 +4369,34 @@ void EditEnsureSelectionVisible(HWND hwnd)
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditScrollTo()
|
||||
//
|
||||
void EditScrollTo(HWND hwnd, DocLn iScrollToLine)
|
||||
{
|
||||
UNUSED(hwnd);
|
||||
|
||||
const DocLn iVisTopLine = SciCall_GetFirstVisibleLine();
|
||||
const int iXoff = SciCall_GetXoffset();
|
||||
const DocLn iMaxLine = SciCall_GetLineCount() - 1;
|
||||
|
||||
iScrollToLine = min(iScrollToLine, iMaxLine);
|
||||
const DocPos iViewPos = SciCall_PositionFromLine(iScrollToLine);
|
||||
|
||||
SciCall_ScrollRange(iViewPos, iViewPos);
|
||||
|
||||
// center line in view (if not already in view)
|
||||
const DocLn iNewVisTopLine = SciCall_GetFirstVisibleLine();
|
||||
if (iNewVisTopLine != iVisTopLine) {
|
||||
const DocLn iScrollLines = SciCall_LinesOnScreen() / 2;
|
||||
const int iScrollCnt = (iScrollToLine - iNewVisTopLine - iScrollLines);
|
||||
if (iScrollCnt != 0) { SciCall_LineScroll(0, iScrollCnt); }
|
||||
}
|
||||
SciCall_SetXoffset(iXoff);
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditJumpTo()
|
||||
@ -4360,7 +4416,11 @@ void EditJumpTo(HWND hwnd, DocLn iNewLine, DocPos iNewCol)
|
||||
iNewCol = max(0, min((iNewCol - 1), iLineEndPos));
|
||||
const DocPos iNewPos = SciCall_FindColumn(iNewLine, iNewCol);
|
||||
|
||||
EditSelectEx(hwnd, iNewPos, iNewPos, -1, -1); // <= SCI_GOTOPOS(pos)
|
||||
SciCall_GotoPos(iNewPos);
|
||||
EditScrollTo(hwnd, iNewLine);
|
||||
|
||||
// remember x-pos for moving caret vertically
|
||||
SciCall_ChooseCaretX();
|
||||
}
|
||||
|
||||
|
||||
@ -4655,23 +4715,17 @@ RegExResult_t __fastcall EditFindHasMatch(HWND hwnd, LPCEDITFINDREPLACE lpefr, B
|
||||
|
||||
const DocPos iStart = bFirstMatchOnly ? SciCall_GetSelectionStart() : 0;
|
||||
const DocPos iTextLength = SciCall_GetTextLength();
|
||||
const DocLn iVisTopLine = SciCall_GetFirstVisibleLine();
|
||||
|
||||
DocPos start = iStart;
|
||||
DocPos end = iTextLength;
|
||||
const DocPos iPos = EditFindInTarget(hwnd, szFind, slen, (int)(lpefr->fuFlags), &start, &end, FALSE, FRMOD_IGNORE);
|
||||
|
||||
if (bFirstMatchOnly) {
|
||||
if (bFirstMatchOnly && !bReplaceInitialized) {
|
||||
if (iPos >= 0) {
|
||||
SciCall_ScrollRange(iPos, iPos);
|
||||
const DocLn iScrollLines = SciCall_LinesOnScreen() / 2;
|
||||
if (SciCall_LineFromPosition(iPos) > (iVisTopLine + iScrollLines)) {
|
||||
SciCall_LineScroll(0, iScrollLines);
|
||||
}
|
||||
EditScrollTo(hwnd, SciCall_LineFromPosition(iPos));
|
||||
}
|
||||
else {
|
||||
const DocPos iCurPos = SciCall_GetCurrentPos();
|
||||
SciCall_ScrollRange(iCurPos, iCurPos);
|
||||
EditScrollTo(hwnd, SciCall_LineFromPosition(iStart));
|
||||
}
|
||||
}
|
||||
else // mark all matches
|
||||
@ -4727,6 +4781,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
|
||||
static int iSaveMarkOcc = -1;
|
||||
static BOOL bSaveOccVisible = FALSE;
|
||||
static BOOL bSaveTFBackSlashes = FALSE;
|
||||
static DocLn iVisTopLine = -1;
|
||||
|
||||
WCHAR tchBuf[FNDRPL_BUFFER] = { L'\0' };
|
||||
|
||||
@ -4734,12 +4789,13 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
iReplacedOccurrences = 0;
|
||||
g_FindReplaceMatchFoundState = FND_NOP;
|
||||
|
||||
SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam);
|
||||
lpefr = (LPEDITFINDREPLACE)lParam;
|
||||
|
||||
iReplacedOccurrences = 0;
|
||||
g_FindReplaceMatchFoundState = FND_NOP;
|
||||
iVisTopLine = SciCall_GetFirstVisibleLine();
|
||||
|
||||
if (lpefr->bMarkOccurences) {
|
||||
iSaveMarkOcc = iMarkOccurrences;
|
||||
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_ONOFF, FALSE);
|
||||
@ -4883,26 +4939,32 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
|
||||
|
||||
case WM_DESTROY:
|
||||
{
|
||||
if (!bSwitchedFindReplace) {
|
||||
if (!bSwitchedFindReplace)
|
||||
{
|
||||
lpefr = (LPEDITFINDREPLACE)GetWindowLongPtr(hwnd, DWLP_USER);
|
||||
lpefr->szFind[0] = '\0';
|
||||
|
||||
if (iSaveMarkOcc >= 0) {
|
||||
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_ONOFF, TRUE);
|
||||
if (iSaveMarkOcc != 0) {
|
||||
SendMessage(g_hwndMain, WM_COMMAND, (WPARAM)MAKELONG(IDM_VIEW_MARKOCCUR_ONOFF, 1), 0);
|
||||
}
|
||||
}
|
||||
bMarkOccurrencesMatchVisible = bSaveOccVisible;
|
||||
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_VISIBLE, bMarkOccurrencesMatchVisible);
|
||||
|
||||
iReplacedOccurrences = 0;
|
||||
g_FindReplaceMatchFoundState = FND_NOP;
|
||||
|
||||
SciCall_ScrollCaret();
|
||||
if (SciCall_GetFirstVisibleLine() != iVisTopLine) {
|
||||
SciCall_SetFirstVisibleLine(iVisTopLine);
|
||||
}
|
||||
}
|
||||
DeleteObject(hBrushRed);
|
||||
DeleteObject(hBrushGreen);
|
||||
DeleteObject(hBrushBlue);
|
||||
KillTimer(hwnd, IDT_TIMER_MRKALL);
|
||||
|
||||
if (iSaveMarkOcc >= 0) {
|
||||
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_ONOFF, TRUE);
|
||||
if (iSaveMarkOcc != 0) {
|
||||
SendMessage(g_hwndMain, WM_COMMAND, (WPARAM)MAKELONG(IDM_VIEW_MARKOCCUR_ONOFF, 1), 0);
|
||||
}
|
||||
}
|
||||
bMarkOccurrencesMatchVisible = bSaveOccVisible;
|
||||
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_VISIBLE, bMarkOccurrencesMatchVisible);
|
||||
|
||||
iReplacedOccurrences = 0;
|
||||
g_FindReplaceMatchFoundState = FND_NOP;
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
@ -5286,12 +5348,14 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
|
||||
case IDOK: // find next
|
||||
case IDACC_SELTONEXT:
|
||||
if (!bIsFindDlg) { bReplaceInitialized = TRUE; }
|
||||
if (!SciCall_IsSelectionEmpty()) { EditJumpToSelectionEnd(hwnd); }
|
||||
EditFindNext(lpefr->hwnd, lpefr, (LOWORD(wParam) == IDACC_SELTONEXT), HIBYTE(GetKeyState(VK_F3)));
|
||||
break;
|
||||
|
||||
case IDC_FINDPREV: // find previous
|
||||
case IDACC_SELTOPREV:
|
||||
if (!bIsFindDlg) { bReplaceInitialized = TRUE; }
|
||||
if (!SciCall_IsSelectionEmpty()) { EditJumpToSelectionStart(hwnd); }
|
||||
EditFindPrev(lpefr->hwnd, lpefr, (LOWORD(wParam) == IDACC_SELTOPREV), HIBYTE(GetKeyState(VK_F3)));
|
||||
break;
|
||||
|
||||
@ -5318,6 +5382,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
|
||||
}
|
||||
}
|
||||
bFlagsChanged = TRUE;
|
||||
iVisTopLine = SciCall_GetFirstVisibleLine();
|
||||
EditSetTimerMarkAll(hwnd,50);
|
||||
break;
|
||||
|
||||
|
||||
@ -85,6 +85,8 @@ void EditSpacesToTabs(HWND,int,BOOL);
|
||||
|
||||
void EditMoveUp(HWND);
|
||||
void EditMoveDown(HWND);
|
||||
void EditJumpToSelectionEnd(HWND);
|
||||
void EditJumpToSelectionStart(HWND);
|
||||
void EditModifyLines(HWND,LPCWSTR,LPCWSTR);
|
||||
void EditIndentBlock(HWND,int,BOOL);
|
||||
void EditAlignText(HWND,int);
|
||||
@ -101,6 +103,7 @@ void EditJoinLinesEx(HWND,BOOL,BOOL);
|
||||
void EditSortLines(HWND,int);
|
||||
|
||||
void EditJumpTo(HWND, DocLn, DocPos);
|
||||
void EditScrollTo(HWND, DocLn);
|
||||
void EditSelectEx(HWND, DocPos, DocPos, int, int);
|
||||
void EditFixPositions(HWND);
|
||||
void EditEnsureSelectionVisible(HWND);
|
||||
|
||||
@ -3942,14 +3942,14 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
case IDM_EDIT_FINDNEXT:
|
||||
if (!SciCall_IsSelectionEmpty()) {
|
||||
SendMessage(hwnd, WM_COMMAND, MAKELONG(CMD_JUMP2SELEND, 1), 0);
|
||||
EditJumpToSelectionEnd(g_hwndEdit);
|
||||
}
|
||||
EditFindNext(g_hwndEdit,&g_efrData,FALSE,FALSE);
|
||||
break;
|
||||
|
||||
case IDM_EDIT_FINDPREV:
|
||||
if (!SciCall_IsSelectionEmpty()) {
|
||||
SendMessage(hwnd, WM_COMMAND, MAKELONG(CMD_JUMP2SELSTART, 1), 0);
|
||||
EditJumpToSelectionStart(g_hwndEdit);
|
||||
}
|
||||
EditFindPrev(g_hwndEdit,&g_efrData,FALSE,FALSE);
|
||||
break;
|
||||
@ -3963,14 +3963,14 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
case IDM_EDIT_SELTONEXT:
|
||||
if (!SciCall_IsSelectionEmpty()) {
|
||||
SendMessage(hwnd, WM_COMMAND, MAKELONG(CMD_JUMP2SELEND, 1), 0);
|
||||
EditJumpToSelectionEnd(g_hwndEdit);
|
||||
}
|
||||
EditFindNext(g_hwndEdit,&g_efrData,TRUE,FALSE);
|
||||
break;
|
||||
|
||||
case IDM_EDIT_SELTOPREV:
|
||||
if (!SciCall_IsSelectionEmpty()) {
|
||||
SendMessage(hwnd, WM_COMMAND, MAKELONG(CMD_JUMP2SELSTART, 1), 0);
|
||||
EditJumpToSelectionStart(g_hwndEdit);
|
||||
}
|
||||
EditFindPrev(g_hwndEdit,&g_efrData,TRUE,FALSE);
|
||||
break;
|
||||
@ -4019,14 +4019,14 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
case CMD_FINDNEXTSEL:
|
||||
if (!SciCall_IsSelectionEmpty()) {
|
||||
SendMessage(hwnd, WM_COMMAND, MAKELONG(CMD_JUMP2SELEND, 1), 0);
|
||||
EditJumpToSelectionEnd(g_hwndEdit);
|
||||
}
|
||||
EditFindNext(g_hwndEdit, &g_efrData, FALSE, FALSE);
|
||||
break;
|
||||
|
||||
case CMD_FINDPREVSEL:
|
||||
if (!SciCall_IsSelectionEmpty()) {
|
||||
SendMessage(hwnd, WM_COMMAND, MAKELONG(CMD_JUMP2SELSTART, 1), 0);
|
||||
EditJumpToSelectionStart(g_hwndEdit);
|
||||
}
|
||||
EditFindPrev(g_hwndEdit, &g_efrData, FALSE, FALSE);
|
||||
break;
|
||||
@ -4983,22 +4983,13 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
|
||||
case CMD_JUMP2SELSTART:
|
||||
if (!SciCall_IsSelectionRectangle()) {
|
||||
if (SciCall_GetCurrentPos() != SciCall_GetSelectionStart()) {
|
||||
SendMessage(g_hwndEdit, SCI_SWAPMAINANCHORCARET, 0, 0);
|
||||
SciCall_ChooseCaretX();
|
||||
}
|
||||
}
|
||||
EditJumpToSelectionStart(g_hwndEdit);
|
||||
SciCall_ChooseCaretX();
|
||||
break;
|
||||
|
||||
|
||||
case CMD_JUMP2SELEND:
|
||||
if (!SciCall_IsSelectionRectangle()) {
|
||||
if (SciCall_GetCurrentPos() != SciCall_GetSelectionEnd()) {
|
||||
SendMessage(g_hwndEdit, SCI_SWAPMAINANCHORCARET, 0, 0);
|
||||
SciCall_ChooseCaretX();
|
||||
}
|
||||
}
|
||||
EditJumpToSelectionEnd(g_hwndEdit);
|
||||
SciCall_ChooseCaretX();
|
||||
break;
|
||||
|
||||
|
||||
|
||||
@ -159,6 +159,7 @@ DeclareSciCallV1(SetRectangularSelectionAnchorVirtualSpace, SETRECTANGULARSELECT
|
||||
|
||||
// Multiselections (Lines of Rectangular selection)
|
||||
DeclareSciCallV0(ClearSelections, CLEARSELECTIONS)
|
||||
DeclareSciCallV0(SwapMainAnchorCaret, SWAPMAINANCHORCARET)
|
||||
DeclareSciCallR0(GetSelections, GETSELECTIONS, DocPosU)
|
||||
DeclareSciCallR1(GetSelectionNCaret, GETSELECTIONNCARET, DocPos, DocPosU, selnum)
|
||||
DeclareSciCallR1(GetSelectionNAnchor, GETSELECTIONNANCHOR, DocPos, DocPosU, selnum)
|
||||
@ -169,6 +170,7 @@ DeclareSciCallV2(SetSelectionNAnchor, SETSELECTIONNANCHOR, DocPosU, selnum, DocP
|
||||
DeclareSciCallV2(SetSelectionNCaretVirtualSpace, SETSELECTIONNCARETVIRTUALSPACE, DocPosU, selnum, DocPos, position)
|
||||
DeclareSciCallV2(SetSelectionNAnchorVirtualSpace, SETSELECTIONNANCHORVIRTUALSPACE, DocPosU, selnum, DocPos, position)
|
||||
|
||||
|
||||
// Operations
|
||||
DeclareSciCallV0(Cut, CUT)
|
||||
DeclareSciCallV0(Copy, COPY)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user