From 874f0d01401e7c73b9965294cec41f3245acfc5a Mon Sep 17 00:00:00 2001
From: Scott Sumner <30118311+sasumner@users.noreply.github.com>
Date: Sat, 13 Mar 2021 19:02:54 -0500
Subject: [PATCH] Add ability to avoid accumulating multiple search results
Fix #8777, close #9653
---
PowerEditor/installer/nativeLang/english.xml | 1 +
PowerEditor/src/Parameters.cpp | 9 +++++-
PowerEditor/src/Parameters.h | 1 +
.../src/ScintillaComponent/FindReplaceDlg.cpp | 32 +++++++++++++++++++
.../src/ScintillaComponent/FindReplaceDlg.h | 2 ++
PowerEditor/src/resource.h | 1 +
6 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml
index 5d470b1a1..c39b22107 100644
--- a/PowerEditor/installer/nativeLang/english.xml
+++ b/PowerEditor/installer/nativeLang/english.xml
@@ -1360,6 +1360,7 @@ Find in all files except exe, obj && log:
+
diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp
index 9ba4f8268..35c4786dd 100644
--- a/PowerEditor/src/Parameters.cpp
+++ b/PowerEditor/src/Parameters.cpp
@@ -4682,6 +4682,11 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
{
_nppGUI._finderLinesAreCurrentlyWrapped = (!lstrcmp(val, TEXT("yes")));
}
+ val = element->Attribute(TEXT("purgeBeforeEverySearch"));
+ if (val)
+ {
+ _nppGUI._finderPurgeBeforeEverySearch = (!lstrcmp(val, TEXT("yes")));
+ }
}
else if (!lstrcmp(nm, TEXT("NewDocDefaultSettings")))
@@ -5926,12 +5931,14 @@ void NppParameters::createXmlTreeFromGUIParams()
GUIConfigElement->SetAttribute(TEXT("bottom"), _nppGUI._findWindowPos.bottom);
}
- //
+ //
{
TiXmlElement* GUIConfigElement = (newGUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement();
GUIConfigElement->SetAttribute(TEXT("name"), TEXT("FinderConfig"));
const TCHAR* pStr = _nppGUI._finderLinesAreCurrentlyWrapped ? TEXT("yes") : TEXT("no");
GUIConfigElement->SetAttribute(TEXT("wrappedLines"), pStr);
+ pStr = _nppGUI._finderPurgeBeforeEverySearch ? TEXT("yes") : TEXT("no");
+ GUIConfigElement->SetAttribute(TEXT("purgeBeforeEverySearch"), pStr);
}
// no
diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h
index 66c075c52..e06bcd92e 100644
--- a/PowerEditor/src/Parameters.h
+++ b/PowerEditor/src/Parameters.h
@@ -801,6 +801,7 @@ struct NppGUI final
bool _tabReplacedBySpace = false;
bool _finderLinesAreCurrentlyWrapped = false;
+ bool _finderPurgeBeforeEverySearch = false;
int _fileAutoDetection = cdEnabledNew;
diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
index f899e9bf3..888a1aace 100644
--- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
+++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
@@ -2498,6 +2498,8 @@ void FindReplaceDlg::findAllIn(InWhat op)
_pFinder->_scintView.setWrapMode(LINEWRAP_INDENT);
_pFinder->_scintView.showWrapSymbol(true);
+ _pFinder->_purgeBeforeEverySearch = nppGUI._finderPurgeBeforeEverySearch;
+
// allow user to start selecting as a stream block, then switch to a column block by adding Alt keypress
_pFinder->_scintView.execute(SCI_SETMOUSESELECTIONRECTANGULARSWITCH, true);
@@ -2516,6 +2518,11 @@ void FindReplaceDlg::findAllIn(InWhat op)
}
_pFinder->setFinderStyle();
+ if (_pFinder->_purgeBeforeEverySearch)
+ {
+ _pFinder->removeAll();
+ }
+
if (justCreated)
{
// Send the address of _MarkingsStruct to the lexer
@@ -3910,6 +3917,19 @@ void Finder::wrapLongLinesToggle()
}
}
+void Finder::purgeToggle()
+{
+ _purgeBeforeEverySearch = !_purgeBeforeEverySearch;
+
+ if (!_canBeVolatiled)
+ {
+ // only remember this setting from the original finder
+ NppParameters& nppParam = NppParameters::getInstance();
+ NppGUI& nppGUI = const_cast(nppParam.getNppGUI());
+ nppGUI._finderPurgeBeforeEverySearch = _purgeBeforeEverySearch;
+ }
+}
+
bool Finder::isLineActualSearchResult(const generic_string & s) const
{
// actual-search-result lines are the only type that start with a tab character
@@ -4159,6 +4179,12 @@ INT_PTR CALLBACK Finder::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
return TRUE;
}
+ case NPPM_INTERNAL_SCINTILLAFINDERPURGE:
+ {
+ purgeToggle();
+ return TRUE;
+ }
+
default :
{
return FALSE;
@@ -4185,6 +4211,7 @@ INT_PTR CALLBACK Finder::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
generic_string copyVerbatim = pNativeSpeaker->getLocalizedStrFromID("finder-copy-verbatim", TEXT("Copy"));
generic_string selectAll = pNativeSpeaker->getLocalizedStrFromID("finder-select-all", TEXT("Select all"));
generic_string clearAll = pNativeSpeaker->getLocalizedStrFromID("finder-clear-all", TEXT("Clear all"));
+ generic_string purgeForEverySearch = pNativeSpeaker->getLocalizedStrFromID("finder-purge-for-every-search", TEXT("Purge for every search"));
generic_string openAll = pNativeSpeaker->getLocalizedStrFromID("finder-open-all", TEXT("Open all"));
generic_string wrapLongLines = pNativeSpeaker->getLocalizedStrFromID("finder-wrap-long-lines", TEXT("Word wrap long lines"));
@@ -4201,12 +4228,17 @@ INT_PTR CALLBACK Finder::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINDERCLEARALL, clearAll));
tmp.push_back(MenuItemUnit(0, TEXT("Separator")));
tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINDEROPENALL, openAll));
+ // configuration items go at the bottom:
tmp.push_back(MenuItemUnit(0, TEXT("Separator")));
tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINDERWRAP, wrapLongLines));
+ tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINDERPURGE, purgeForEverySearch));
scintillaContextmenu.create(_hSelf, tmp);
scintillaContextmenu.enableItem(NPPM_INTERNAL_SCINTILLAFINDERCLEARALL, !_canBeVolatiled);
+
+ scintillaContextmenu.enableItem(NPPM_INTERNAL_SCINTILLAFINDERPURGE, !_canBeVolatiled);
+ scintillaContextmenu.checkItem(NPPM_INTERNAL_SCINTILLAFINDERPURGE, _purgeBeforeEverySearch && !_canBeVolatiled);
scintillaContextmenu.checkItem(NPPM_INTERNAL_SCINTILLAFINDERWRAP, _longLinesAreWrapped);
diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h
index a86b2efc0..15b4e06b6 100644
--- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h
+++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h
@@ -124,6 +124,7 @@ public:
void removeAll();
void openAll();
void wrapLongLinesToggle();
+ void purgeToggle();
void copy();
void beginNewFilesSearch();
void finishFilesSearch(int count, int searchedCount, bool isMatchLines, bool searchedEntireNotSelection);
@@ -160,6 +161,7 @@ private:
bool _canBeVolatiled = true;
bool _longLinesAreWrapped = false;
+ bool _purgeBeforeEverySearch = false;
generic_string _prefixLineStr;
diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h
index 4d274ab64..be151353b 100644
--- a/PowerEditor/src/resource.h
+++ b/PowerEditor/src/resource.h
@@ -444,6 +444,7 @@
#define NPPM_INTERNAL_MINIMIZED_TRAY (NOTEPADPLUS_USER_INTERNAL + 54)
#define NPPM_INTERNAL_SCINTILLAFINDERCOPYVERBATIM (NOTEPADPLUS_USER_INTERNAL + 55)
#define NPPM_INTERNAL_FINDINPROJECTS (NOTEPADPLUS_USER_INTERNAL + 56)
+ #define NPPM_INTERNAL_SCINTILLAFINDERPURGE (NOTEPADPLUS_USER_INTERNAL + 57)
// See Notepad_plus_msgs.h
//#define NOTEPADPLUS_USER (WM_USER + 1000)