[BUG_FIXED] Fix cursor position bug in Incremental search.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@469 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2009-04-28 17:11:44 +00:00
parent 342fa5b95a
commit 1a97505005
4 changed files with 72 additions and 29 deletions

View File

@ -3313,10 +3313,9 @@ void Notepad_plus::command(int id)
const int strSize = FINDREPLACE_MAXLENGTH;
TCHAR str[strSize];
_pEditView->getGenericSelectedText(str, strSize);
_incrementFindDlg.setSearchText(str, _pEditView->getCurrentBuffer()->getUnicodeMode() != uni8Bit);
_incrementFindDlg.display();
_pEditView->getGenericSelectedText(str, strSize, false);
if (0!=str[0]) // the selected text is not empty, then use it
_incrementFindDlg.setSearchText(str, _pEditView->getCurrentBuffer()->getUnicodeMode() != uni8Bit); _incrementFindDlg.display();
}
break;

View File

@ -1095,7 +1095,7 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, FindOption *options)
endPosition = 0;
}
if (pOptions->_isIncremental)
if (FirstIncremental==pOptions->_incrementalType)
{
startPosition = 0;
endPosition = docLength;
@ -1114,14 +1114,22 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, FindOption *options)
//when wrapping, use the rest of the document (entire document is usable)
if (pOptions->_whichDirection == DIR_DOWN)
{
startPosition = 0;
// the text to find is modified so use the current position
startPosition = cr.cpMin;
endPosition = docLength;
}
else
else if (NextIncremental==pOptions->_incrementalType)
{
startPosition = docLength;
// text to find is not modified, so use current position +1
startPosition = cr.cpMin +1;
endPosition = docLength;
if (pOptions->_whichDirection == DIR_UP)
{
//When searching upwards, start is the lower part, end the upper, for backwards search
startPosition = cr.cpMax - 1;
endPosition = 0;
}
}
//new target, search again
posFind = (*_ppEditView)->searchInTarget(pText, startPosition, endPosition);
@ -1129,7 +1137,7 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, FindOption *options)
if (posFind == -1)
{
//failed, or failed twice with wrap
if (!pOptions->_isIncremental) //incremental search doesnt trigger messages
if (NotIncremental==pOptions->_incrementalType) //incremental search doesnt trigger messages
{
generic_string msg = TEXT("Can't find the text:\r\n\"");
msg += pText;
@ -1840,10 +1848,13 @@ void FindIncrementDlg::display(bool toShow) const
return;
}
if (toShow)
::SetFocus(::GetDlgItem(_hSelf, IDC_INCFINDTEXT));
// select the whole find editor text
::SendDlgItemMessage(_hSelf, IDC_INCFINDTEXT, EM_SETSEL, 0, -1);
_pRebar->setIDVisible(_rbBand.wID, toShow);
}
#define SHIFTED 0x8000
BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
@ -1862,27 +1873,53 @@ BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
case IDC_INCFINDPREVOK :
case IDC_INCFINDNXTOK :
case IDOK :
{
FindOption fo;
fo._isWholeWord = false;
fo._isMatchCase = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDMATCHCASE, BM_GETCHECK, 0, 0));
if (LOWORD(wParam) == IDC_INCFINDPREVOK)
fo._whichDirection = DIR_UP;
else if (LOWORD(wParam) == IDOK)
{
SHORT nVirtKey = GetKeyState(VK_SHIFT);
if (nVirtKey & SHIFTED)
fo._whichDirection = DIR_UP;
}
generic_string str2Search = _pFRDlg->getTextFromCombo(::GetDlgItem(_hSelf, IDC_INCFINDTEXT), isUnicode);
_pFRDlg->processFindNext(str2Search.c_str(), &fo);
}
return TRUE;
case IDC_INCFINDMATCHCASE:
case IDC_INCFINDTEXT :
case IDC_INCFINDHILITEALL :
{
if (_doSearchFromBegin)
switch(HIWORD(wParam))
{
case EN_CHANGE :
{
FindOption fo;
fo._isWholeWord = false;
fo._isIncremental = true;
fo._isMatchCase = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDMATCHCASE, BM_GETCHECK, 0, 0));
fo._incrementalType = FirstIncremental;
generic_string str2Search = _pFRDlg->getTextFromCombo(::GetDlgItem(_hSelf, IDC_INCFINDTEXT), isUnicode);
_pFRDlg->processFindNext(str2Search.c_str(), &fo);
}
return TRUE;
case EN_KILLFOCUS :
case EN_SETFOCUS :
break;
}
}
return TRUE;
case IDC_INCFINDMATCHCASE:
{
FindOption fo;
fo._isWholeWord = false;
fo._incrementalType = NextIncremental;
fo._isMatchCase = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDMATCHCASE, BM_GETCHECK, 0, 0));
generic_string str2Search = _pFRDlg->getTextFromCombo(::GetDlgItem(_hSelf, IDC_INCFINDTEXT), isUnicode);
@ -1892,6 +1929,16 @@ BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection();
(*(_pFRDlg->_ppEditView))->execute(SCI_SETSEL, -1, range.cpMin);
}
}
case IDC_INCFINDHILITEALL :
{
FindOption fo;
fo._isWholeWord = false;
fo._incrementalType = FirstIncremental;
fo._isMatchCase = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDMATCHCASE, BM_GETCHECK, 0, 0));
generic_string str2Search = _pFRDlg->getTextFromCombo(::GetDlgItem(_hSelf, IDC_INCFINDTEXT), isUnicode);
bool isHiLieAll = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDHILITEALL, BM_GETCHECK, 0, 0));
if (str2Search == TEXT(""))
@ -1899,9 +1946,6 @@ BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
markSelectedTextInc(isHiLieAll, &fo);
}
else
_doSearchFromBegin = true;
}
return TRUE;
}

View File

@ -53,6 +53,7 @@ struct TargetRange {
int targetEnd;
};
enum SearchIncrementalType { NotIncremental, FirstIncremental, NextIncremental };
enum SearchType { FindNormal, FindExtended, FindRegex };
enum ProcessOperation { ProcessFindAll, ProcessReplaceAll, ProcessCountAll, ProcessMarkAll, ProcessMarkAll_2, ProcessMarkAll_IncSearch, ProcessMarkAllExt };
@ -61,10 +62,11 @@ struct FindOption {
bool _isMatchCase;
bool _isWrapAround;
bool _whichDirection;
bool _isIncremental;
SearchIncrementalType _incrementalType;
SearchType _searchType;
FindOption() :_isWholeWord(true), _isMatchCase(true), _searchType(FindNormal),\
_isWrapAround(true), _whichDirection(DIR_DOWN), _isIncremental(false){};
_isWrapAround(true), _whichDirection(DIR_DOWN), _incrementalType(NotIncremental){};
};
//This class contains generic search functions as static functions for easy access
@ -554,7 +556,6 @@ public :
virtual void display(bool toShow = true) const;
void setSearchText(const TCHAR * txt2find, bool isUTF8 = false) {
_doSearchFromBegin = false;
#ifdef UNICODE
::SendDlgItemMessage(_hSelf, IDC_INCFINDTEXT, WM_SETTEXT, 0, (LPARAM)txt2find);
#else
@ -586,7 +587,6 @@ private :
ReBar * _pRebar;
REBARBANDINFO _rbBand;
bool _doSearchFromBegin;
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
void markSelectedTextInc(bool enable, FindOption *opt = NULL);
};

View File

@ -81,9 +81,9 @@ FONT 8, TEXT("MS Shell Dlg")
BEGIN
PUSHBUTTON "X",IDCANCEL,2,3,16,14
RTEXT "Find :",IDC_INCSTATIC,20,6,25,12
EDITTEXT IDC_INCFINDTEXT,45,4,175,12,ES_AUTOHSCROLL | ES_WANTRETURN | NOT WS_BORDER,WS_EX_STATICEDGE
PUSHBUTTON "<",IDC_INCFINDPREVOK,223,3,16,14
DEFPUSHBUTTON ">",IDC_INCFINDNXTOK,243,3,16,14
EDITTEXT IDC_INCFINDTEXT,45,4,175,12,ES_AUTOHSCROLL | ES_WANTRETURN | NOT WS_BORDER | WS_TABSTOP /*|WS_GROUP*/ ,WS_EX_STATICEDGE
PUSHBUTTON "<",IDC_INCFINDPREVOK | WS_TABSTOP,223,3,16,14
PUSHBUTTON ">",IDC_INCFINDNXTOK | WS_TABSTOP,243,3,16,14
CONTROL "Highlight all", IDC_INCFINDHILITEALL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,270,5,65,12
CONTROL "Match case", IDC_INCFINDMATCHCASE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,335,5,60,12
END