From acb4e5ae1848c921a016bf348b698ca4ff779a9b Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Tue, 7 Jul 2020 15:28:26 -0400 Subject: [PATCH] Add ability to limit removal of consecutive duplicate lines to selected text Fix #8459, close #8535 --- PowerEditor/src/Notepad_plus.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index c175b08d5..a87477fe9 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1427,14 +1427,17 @@ void Notepad_plus::removeDuplicateLines() env._str2Search = TEXT("^(.*(\\r?\\n|\\r))(\\1)+"); env._str4Replace = TEXT("\\1"); - env._searchType = FindRegex; - _findReplaceDlg.processAll(ProcessReplaceAll, &env, true); + env._searchType = FindRegex; + auto mainSelStart = _pEditView->execute(SCI_GETSELECTIONSTART); + auto mainSelEnd = _pEditView->execute(SCI_GETSELECTIONEND); + auto mainSelLength = mainSelEnd - mainSelStart; + bool isEntireDoc = mainSelLength == 0; + env._isInSelection = !isEntireDoc; + _findReplaceDlg.processAll(ProcessReplaceAll, &env, isEntireDoc); // remove the last line if it's a duplicate line. env._str2Search = TEXT("^(.+)(\\r?\\n|\\r)(\\1)$"); - env._str4Replace = TEXT("\\1"); - env._searchType = FindRegex; - _findReplaceDlg.processAll(ProcessReplaceAll, &env, true); + _findReplaceDlg.processAll(ProcessReplaceAll, &env, isEntireDoc); } void Notepad_plus::getMatchedFileNames(const TCHAR *dir, const vector & patterns, vector & fileNames, bool isRecursive, bool isInHiddenDir)