diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index d50701e0e..bd8c648b8 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1400,10 +1400,13 @@ void Notepad_plus::removeEmptyLine(bool isBlankContained) env._str2Search = TEXT("^$(\\r\\n|\\r|\\n)"); } env._str4Replace = TEXT(""); - 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 an empty line. if (isBlankContained) @@ -1414,7 +1417,7 @@ void Notepad_plus::removeEmptyLine(bool isBlankContained) { env._str2Search = TEXT("(\\r\\n|\\r|\\n)^$"); } - _findReplaceDlg.processAll(ProcessReplaceAll, &env, true); + _findReplaceDlg.processAll(ProcessReplaceAll, &env, isEntireDoc); } void Notepad_plus::removeDuplicateLines()