diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index e87986b86..aff8bce54 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -4032,6 +4032,31 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) } } + else if (!lstrcmp(nm, TEXT("SmartHighLightMode"))) + { + TiXmlNode *n = childNode->FirstChild(); + + if (n) + { + const TCHAR* val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("1"))) + { + _nppGUI._smartHiliteMode = NppGUI::SmartHiliteMode::anySelection; + } + else if (!lstrcmp(val, TEXT("2"))) + { + _nppGUI._smartHiliteMode = NppGUI::SmartHiliteMode::findDialog; + } + else + { + _nppGUI._smartHiliteMode = NppGUI::SmartHiliteMode::wordOnly; + } + } + } + } + else if (!lstrcmp(nm, TEXT("TagsMatchHighLight"))) { TiXmlNode *n = childNode->FirstChild(); @@ -5077,6 +5102,7 @@ bool NppParameters::writeGUIParams() bool menuBarExist = false; bool smartHighLightExist = false; bool smartHighLightCaseSensitiveExist = false; + bool smartHighLightModeExists = false; bool tagsMatchHighLightExist = false; bool caretExist = false; bool ScintillaGlobalSettingsExist = false; @@ -5286,7 +5312,37 @@ bool NppParameters::writeGUIParams() else childNode->InsertEndChild(TiXmlText(pStr)); } + else if (!lstrcmp(nm, TEXT("SmartHighLightMode"))) + { + smartHighLightModeExists = true; + const TCHAR *pStr; + switch (_nppGUI._smartHiliteMode) + { + case NppGUI::SmartHiliteMode::anySelection: + pStr = TEXT("1"); + break; + + case NppGUI::SmartHiliteMode::findDialog: + pStr = TEXT("2"); + break; + + default: // NppGUI::SmartHiliteMode::wordOnly + pStr = TEXT("0"); + break; + } + + TiXmlNode *n = childNode->FirstChild(); + + if (n) + { + n->SetValue(pStr); + } + else + { + childNode->InsertEndChild(TiXmlText(pStr)); + } + } else if (!lstrcmp(nm, TEXT("TagsMatchHighLight"))) { tagsMatchHighLightExist = true; @@ -5612,6 +5668,25 @@ bool NppParameters::writeGUIParams() { insertGUIConfigBoolNode(GUIRoot, TEXT("SmartHighLightCaseSensitive"), _nppGUI._smartHiliteCaseSensitive); } + + if (!smartHighLightModeExists) + { + const TCHAR *pStr = TEXT("0"); + + if (_nppGUI._smartHiliteMode == 1) + { + pStr = TEXT("1"); + } + else if (_nppGUI._smartHiliteMode == 2) + { + pStr = TEXT("2"); + } + + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("SmartHighLightMode")); + GUIConfigElement->InsertEndChild(TiXmlText(pStr)); + } + if (!tagsMatchHighLightExist) { TiXmlElement * ele = insertGUIConfigBoolNode(GUIRoot, TEXT("TagsMatchHighLight"), _nppGUI._enableTagsMatchHilite); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index bf02f9ac1..5db44a7e1 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -747,6 +747,10 @@ struct NppGUI final bool _maitainIndent = true; bool _enableSmartHilite = true; bool _smartHiliteCaseSensitive = false; + + enum SmartHiliteMode { wordOnly = 0, anySelection = 1, findDialog = 2 }; + SmartHiliteMode _smartHiliteMode = SmartHiliteMode::wordOnly; + bool _disableSmartHiliteTmp = false; bool _enableTagsMatchHilite = true; bool _enableTagAttrsHilite = true; diff --git a/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp b/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp index 11fb956c2..eb961153c 100644 --- a/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp +++ b/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp @@ -47,13 +47,40 @@ void SmartHighlighter::highlightView(ScintillaEditView * pHighlightView) return; auto curPos = pHighlightView->execute(SCI_GETCURRENTPOS); - auto wordStart = pHighlightView->execute(SCI_WORDSTARTPOSITION, curPos, true); - auto wordEnd = pHighlightView->execute(SCI_WORDENDPOSITION, wordStart, true); auto range = pHighlightView->getSelection(); + const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI(); + + // Determine mode for SmartHighlighting + NppGUI::SmartHiliteMode mode = nppGUI._smartHiliteMode; + bool wordOnly; + + if (mode == NppGUI::SmartHiliteMode::wordOnly) + { + wordOnly = true; + } + else if (mode == NppGUI::SmartHiliteMode::findDialog) + { + // fetch find dialog's setting + NppParameters *nppParams = NppParameters::getInstance(); + FindHistory &findHistory = nppParams->getFindHistory(); + wordOnly = findHistory._isMatchWord; + } + else + { + wordOnly = false; + } + + // additional checks for wordOnly mode // Make sure the "word" positions match the current selection - if (wordStart == wordEnd || wordStart != range.cpMin || wordEnd != range.cpMax) - return; + if (wordOnly) + { + auto wordStart = pHighlightView->execute(SCI_WORDSTARTPOSITION, curPos, true); + auto wordEnd = pHighlightView->execute(SCI_WORDENDPOSITION, wordStart, true); + + if (wordStart == wordEnd || wordStart != range.cpMin || wordEnd != range.cpMax) + return; + } int textlen = range.cpMax - range.cpMin + 1; char * text2Find = new char[textlen]; @@ -73,11 +100,9 @@ void SmartHighlighter::highlightView(ScintillaEditView * pHighlightView) auto currentLine = firstLine; int prevDocLineChecked = -1; //invalid start - const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI(); - FindOption fo; fo._isMatchCase = nppGUI._smartHiliteCaseSensitive; - fo._isWholeWord = true; + fo._isWholeWord = wordOnly; const TCHAR * searchText = NULL; diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index 87ddcad59..6b12ba93b 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -122,12 +122,13 @@ BEGIN CONTROL "Enable MRU behaviour",IDC_CHECK_STYLEMRU,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,28,140,10 CONTROL "Enable",IDC_CHECK_ENABLSMARTHILITE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,45,57,142,10 CONTROL "Match case",IDC_CHECK_SMARTHILITECASESENSITIVE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,45,71,142,10 - CONTROL "Enable Notepad++ auto-updater",IDC_CHECK_AUTOUPDATE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,100,150,10 - CONTROL "Autodetect character encoding",IDC_CHECK_DETECTENCODING,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,115,217,10 - CONTROL "Auto-indent",IDC_CHECK_MAINTAININDENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,130,150,10 - CONTROL "Minimize to system tray",IDC_CHECK_MIN2SYSTRAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,145,150,10 - CONTROL "Show only filename in title bar",IDC_CHECK_SHORTTITLE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,160,217,10 - CONTROL "Treat backslash as escape character for SQL",IDC_CHECK_BACKSLASHISESCAPECHARACTERFORSQL, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,175,217,10 + COMBOBOX IDC_COMBO_SMARTHILITEMODE, 45, 82, 142, 10, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Enable Notepad++ auto-updater",IDC_CHECK_AUTOUPDATE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,105,150,10 + CONTROL "Autodetect character encoding",IDC_CHECK_DETECTENCODING,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,120,217,10 + CONTROL "Auto-indent",IDC_CHECK_MAINTAININDENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,135,150,10 + CONTROL "Minimize to system tray",IDC_CHECK_MIN2SYSTRAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,150,150,10 + CONTROL "Show only filename in title bar",IDC_CHECK_SHORTTITLE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,165,217,10 + CONTROL "Treat backslash as escape character for SQL",IDC_CHECK_BACKSLASHISESCAPECHARACTERFORSQL, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,180,217,10 CONTROL "Enable",IDC_CHECK_CLICKABLELINK_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,267,15,140,10 CONTROL "No underline",IDC_CHECK_CLICKABLELINK_NOUNDERLINE, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,267,28,140,10 @@ -143,7 +144,7 @@ BEGIN EDITTEXT IDC_EDIT_SESSIONFILEEXT,381,157,34,14,ES_AUTOHSCROLL EDITTEXT IDC_EDIT_WORKSPACEFILEEXT,381,174,34,14,ES_AUTOHSCROLL GROUPBOX "Document Switcher (Ctrl+TAB)",IDC_DOCUMENTSWITCHER_STATIC,37,4,155,39,BS_CENTER - GROUPBOX "Smart Highlighting",IDC_SMARTHILITING_STATIC,37,47,155,39,BS_CENTER + GROUPBOX "Smart Highlighting",IDC_SMARTHILITING_STATIC,37,47,155,52,BS_CENTER GROUPBOX "Clickable Link Settings",IDC_CLICKABLELINK_STATIC,259,4,155,39,BS_CENTER GROUPBOX "File Status Auto-Detection",IDC_FILEAUTODETECTION_STATIC,259,47,155,50,BS_CENTER GROUPBOX "Highlight Matching Tags",IDC_TAGMATCHEDHILITE_STATIC,259,101,155,50,BS_CENTER diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index a70a59245..b9f03ccd6 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -932,9 +932,29 @@ INT_PTR CALLBACK SettingsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) ::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLTAGATTRHILITE, BM_SETCHECK, nppGUI._enableTagAttrsHilite, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_HIGHLITENONEHTMLZONE, BM_SETCHECK, nppGUI._enableHiliteNonHTMLZone, 0); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_SMARTHILITEMODE, CB_ADDSTRING, 0, (LPARAM)TEXT("Match whole word only")); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_SMARTHILITEMODE, CB_ADDSTRING, 0, (LPARAM)TEXT("Match any selection")); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_SMARTHILITEMODE, CB_ADDSTRING, 0, (LPARAM)TEXT("Same as Find dialog")); + + switch (nppGUI._smartHiliteMode) + { + case NppGUI::SmartHiliteMode::wordOnly: + ::SendMessage(::GetDlgItem(_hSelf, IDC_COMBO_SMARTHILITEMODE), CB_SETCURSEL, 0, 0); + break; + + case NppGUI::SmartHiliteMode::anySelection: + ::SendMessage(::GetDlgItem(_hSelf, IDC_COMBO_SMARTHILITEMODE), CB_SETCURSEL, 1, 0); + break; + + case NppGUI::SmartHiliteMode::findDialog: + ::SendMessage(::GetDlgItem(_hSelf, IDC_COMBO_SMARTHILITEMODE), CB_SETCURSEL, 2, 0); + break; + } + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_ENABLTAGATTRHILITE), nppGUI._enableTagsMatchHilite); ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_HIGHLITENONEHTMLZONE), nppGUI._enableTagsMatchHilite); ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_SMARTHILITECASESENSITIVE), nppGUI._enableSmartHilite); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_SMARTHILITEMODE), nppGUI._enableSmartHilite); ::SendDlgItemMessage(_hSelf, IDC_CHECK_SHORTTITLE, BM_SETCHECK, nppGUI._shortTitlebar, 0); @@ -1077,6 +1097,7 @@ INT_PTR CALLBACK SettingsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) ::SendMessage(grandParent, NPPM_INTERNAL_CLEARINDICATOR, 0, 0); } ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_SMARTHILITECASESENSITIVE), nppGUI._enableSmartHilite); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_SMARTHILITEMODE), nppGUI._enableSmartHilite); return TRUE; } @@ -1140,6 +1161,41 @@ INT_PTR CALLBACK SettingsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) nppGUI._backSlashIsEscapeCharacterForSql = isCheckedOrNot(IDC_CHECK_BACKSLASHISESCAPECHARACTERFORSQL); return TRUE; } + + default: + switch (HIWORD(wParam)) + { + case CBN_SELCHANGE: + { + switch (LOWORD(wParam)) + { + case IDC_COMBO_SMARTHILITEMODE : + { + auto index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_SMARTHILITEMODE, CB_GETCURSEL, 0, 0); + + switch (index) + { + case 0: + nppGUI._smartHiliteMode = NppGUI::SmartHiliteMode::wordOnly; + break; + + case 1: + nppGUI._smartHiliteMode = NppGUI::SmartHiliteMode::anySelection; + break; + + case 2: + nppGUI._smartHiliteMode = NppGUI::SmartHiliteMode::findDialog; + break; + } + + return TRUE; + } + + default: + break; + } + } + } } } } diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index c5df2e6cf..5bc3a6756 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -184,6 +184,7 @@ #define IDC_CHECK_BACKSLASHISESCAPECHARACTERFORSQL (IDD_PREFERENCE_SETTING_BOX + 35) #define IDC_EDIT_WORKSPACEFILEEXT (IDD_PREFERENCE_SETTING_BOX + 36) #define IDC_WORKSPACEFILEEXT_STATIC (IDD_PREFERENCE_SETTING_BOX + 37) + #define IDC_COMBO_SMARTHILITEMODE (IDD_PREFERENCE_SETTING_BOX + 38) //-- FLS: xFileEditViewHistoryParameterGUI: Additional Checkbox for enabling the history for restoring the edit view per file. #define IDC_PREFERENCE_OFFSET_FLS 40 #define IDC_CHECK_REMEMBEREDITVIEWPERFILE (IDD_PREFERENCE_SETTING_BOX + IDC_PREFERENCE_OFFSET_FLS + 1)