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