[EN[ENHANCEMENT] Enhance Incremental search: make highlighting follow typing.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1336 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2015-02-06 18:18:04 +00:00
parent 3d2f570aba
commit 9a54f90312

View File

@ -2718,92 +2718,93 @@ BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
case WM_COMMAND :
{
bool updateSearch = false;
bool forward = true;
bool advance = false;
bool updateHiLight = false;
bool updateSearch = false;
bool forward = true;
bool advance = false;
bool updateHiLight = false;
bool updateCase = false;
switch (LOWORD(wParam))
{
case IDCANCEL :
(*(_pFRDlg->_ppEditView))->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_INC);
//::SetFocus((*(_pFRDlg->_ppEditView))->getHSelf());
(*(_pFRDlg->_ppEditView))->getFocus();
::SendDlgItemMessage(_hSelf, IDC_INCFINDHILITEALL, BM_SETCHECK, BST_UNCHECKED, 0);
display(false);
return TRUE;
case IDM_SEARCH_FINDINCREMENT: // Accel table: Start incremental search
// if focus is on a some other control, return it to the edit field
if (::GetFocus() != ::GetDlgItem(_hSelf, IDC_INCFINDTEXT))
{
::PostMessage(_hSelf, WM_NEXTDLGCTL, (WPARAM)::GetDlgItem(_hSelf, IDC_INCFINDTEXT), TRUE);
return TRUE;
}
// otherwise, repeat the search
case IDM_SEARCH_FINDPREV: // Accel table: find prev
case IDM_SEARCH_FINDNEXT: // Accel table: find next
case IDC_INCFINDPREVOK:
case IDC_INCFINDNXTOK:
case IDM_SEARCH_FINDINCREMENT: // Accel table: Start incremental search
// if focus is on a some other control, return it to the edit field
if (::GetFocus() != ::GetDlgItem(_hSelf, IDC_INCFINDTEXT))
{
::PostMessage(_hSelf, WM_NEXTDLGCTL, (WPARAM)::GetDlgItem(_hSelf, IDC_INCFINDTEXT), TRUE);
return TRUE;
}
// otherwise, repeat the search
case IDM_SEARCH_FINDPREV: // Accel table: find prev
case IDM_SEARCH_FINDNEXT: // Accel table: find next
case IDC_INCFINDPREVOK:
case IDC_INCFINDNXTOK:
case IDOK:
updateSearch = true;
advance = true;
forward = (LOWORD(wParam) == IDC_INCFINDNXTOK) ||
(LOWORD(wParam) == IDM_SEARCH_FINDNEXT) ||
(LOWORD(wParam) == IDM_SEARCH_FINDINCREMENT) ||
((LOWORD(wParam) == IDOK) && !(GetKeyState(VK_SHIFT) & SHIFTED));
break;
case IDC_INCFINDMATCHCASE:
updateSearch = true;
updateCase = true;
updateHiLight = true;
break;
case IDC_INCFINDHILITEALL:
updateHiLight = true;
break;
case IDC_INCFINDTEXT:
if (HIWORD(wParam) == EN_CHANGE)
{
updateSearch = true;
break;
}
// treat other edit notifications as unhandled
default:
return DefWindowProc(getHSelf(), message, wParam, lParam);
}
FindOption fo;
fo._isWholeWord = false;
fo._incrementalType = advance ? NextIncremental : FirstIncremental;
fo._whichDirection = forward ? DIR_DOWN : DIR_UP;
fo._isMatchCase = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDMATCHCASE, BM_GETCHECK, 0, 0));
bool isUnicode = (*(_pFRDlg->_ppEditView))->getCurrentBuffer()->getUnicodeMode() != uni8Bit;
generic_string str2Search = _pFRDlg->getTextFromCombo(::GetDlgItem(_hSelf, IDC_INCFINDTEXT), isUnicode);
if (updateSearch)
{
FindStatus findStatus = FSFound;
bool isFound = _pFRDlg->processFindNext(str2Search.c_str(), &fo, &findStatus);
setFindStatus(findStatus);
// If case-sensitivity changed (to Match=yes), there may have been a matched selection that
// now does not match; so if Not Found, clear selection and put caret at beginning of what was
// selected (no change, if there was no selection)
updateSearch = true;
advance = true;
forward = (LOWORD(wParam) == IDC_INCFINDNXTOK) ||
(LOWORD(wParam) == IDM_SEARCH_FINDNEXT) ||
(LOWORD(wParam) == IDM_SEARCH_FINDINCREMENT) ||
((LOWORD(wParam) == IDOK) && !(GetKeyState(VK_SHIFT) & SHIFTED));
break;
case IDC_INCFINDMATCHCASE:
updateSearch = true;
updateCase = true;
updateHiLight = true;
break;
case IDC_INCFINDHILITEALL:
updateHiLight = true;
break;
case IDC_INCFINDTEXT:
if (HIWORD(wParam) == EN_CHANGE)
{
updateSearch = true;
updateHiLight = isCheckedOrNot(IDC_INCFINDHILITEALL);
updateCase = isCheckedOrNot(IDC_INCFINDMATCHCASE);
break;
}
// treat other edit notifications as unhandled
default:
return DefWindowProc(getHSelf(), message, wParam, lParam);
}
FindOption fo;
fo._isWholeWord = false;
fo._incrementalType = advance ? NextIncremental : FirstIncremental;
fo._whichDirection = forward ? DIR_DOWN : DIR_UP;
fo._isMatchCase = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDMATCHCASE, BM_GETCHECK, 0, 0));
bool isUnicode = (*(_pFRDlg->_ppEditView))->getCurrentBuffer()->getUnicodeMode() != uni8Bit;
generic_string str2Search = _pFRDlg->getTextFromCombo(::GetDlgItem(_hSelf, IDC_INCFINDTEXT), isUnicode);
if (updateSearch)
{
FindStatus findStatus = FSFound;
bool isFound = _pFRDlg->processFindNext(str2Search.c_str(), &fo, &findStatus);
setFindStatus(findStatus);
// If case-sensitivity changed (to Match=yes), there may have been a matched selection that
// now does not match; so if Not Found, clear selection and put caret at beginning of what was
// selected (no change, if there was no selection)
if (updateCase && !isFound)
{
CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection();
CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection();
(*(_pFRDlg->_ppEditView))->execute(SCI_SETSEL, (WPARAM)-1, range.cpMin);
}
}
if (updateHiLight)
{
bool highlight = !str2Search.empty() &&
(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDHILITEALL, BM_GETCHECK, 0, 0));
markSelectedTextInc(highlight, &fo);
}
if (updateHiLight)
{
bool highlight = !str2Search.empty() &&
(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDHILITEALL, BM_GETCHECK, 0, 0));
markSelectedTextInc(highlight, &fo);
}
return TRUE;
}