mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-23 13:54:54 +02:00
More performance optimization for the Remove Empty Lines command
Close #12544
This commit is contained in:
parent
891f2ed682
commit
cffdf79a9b
@ -1493,11 +1493,11 @@ void Notepad_plus::removeEmptyLine(bool isBlankContained)
|
|||||||
FindOption env;
|
FindOption env;
|
||||||
if (isBlankContained)
|
if (isBlankContained)
|
||||||
{
|
{
|
||||||
env._str2Search = TEXT("^([\\t ]*$(\\r?\\n|\\r))(\\1)*");
|
env._str2Search = TEXT("^(?>[\\t ]*[\\r\\n]+)+");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
env._str2Search = TEXT("^$(\\r?\\n|\\r)(\\1)*");
|
env._str2Search = TEXT("^[\\r\\n]+");
|
||||||
}
|
}
|
||||||
env._str4Replace = TEXT("");
|
env._str4Replace = TEXT("");
|
||||||
env._searchType = FindRegex;
|
env._searchType = FindRegex;
|
||||||
@ -1509,15 +1509,22 @@ void Notepad_plus::removeEmptyLine(bool isBlankContained)
|
|||||||
_findReplaceDlg.processAll(ProcessReplaceAll, &env, isEntireDoc);
|
_findReplaceDlg.processAll(ProcessReplaceAll, &env, isEntireDoc);
|
||||||
|
|
||||||
// remove the last line if it's an empty line.
|
// remove the last line if it's an empty line.
|
||||||
if (isBlankContained)
|
auto lastLineDoc = _pEditView->execute(SCI_GETLINECOUNT) - 1;
|
||||||
|
auto str2Search = isBlankContained ? TEXT("[\\r\\n]+^[\\t ]*$|^[\\t ]+$") : TEXT("[\\r\\n]+^$");
|
||||||
|
auto startPos = _pEditView->execute(SCI_POSITIONFROMLINE, lastLineDoc - 1);
|
||||||
|
auto endPos = _pEditView->execute(SCI_GETLENGTH);
|
||||||
|
if (!isEntireDoc)
|
||||||
{
|
{
|
||||||
env._str2Search = TEXT("(\\r?\\n|\\r)^[\\t ]*$");
|
startPos = _pEditView->execute(SCI_GETSELECTIONSTART);
|
||||||
|
endPos = _pEditView->execute(SCI_GETSELECTIONEND);
|
||||||
|
auto endLine = _pEditView->execute(SCI_LINEFROMPOSITION, endPos);
|
||||||
|
if (endPos != (_pEditView->execute(SCI_POSITIONFROMLINE, endLine) + _pEditView->execute(SCI_LINELENGTH, endLine)))
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
_pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP|SCFIND_POSIX);
|
||||||
{
|
auto posFound = _pEditView->searchInTarget(str2Search, lstrlen(str2Search), startPos, endPos);
|
||||||
env._str2Search = TEXT("(\\r?\\n|\\r)^$");
|
if (posFound >= 0)
|
||||||
}
|
_pEditView->replaceTarget(TEXT(""), posFound, endPos);
|
||||||
_findReplaceDlg.processAll(ProcessReplaceAll, &env, isEntireDoc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notepad_plus::removeDuplicateLines()
|
void Notepad_plus::removeDuplicateLines()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user