mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-28 16:24:27 +02:00
Fix newline bug when not sorting all lines.
This commit is contained in:
parent
351b9b6bff
commit
6e84be21f4
@ -2958,6 +2958,16 @@ void ScintillaEditView::sortLines(size_t fromLine, size_t toLine, bool isDescend
|
|||||||
const int endPos = execute(SCI_POSITIONFROMLINE, toLine) + execute(SCI_LINELENGTH, toLine);
|
const int endPos = execute(SCI_POSITIONFROMLINE, toLine) + execute(SCI_LINELENGTH, toLine);
|
||||||
const generic_string text = getGenericTextAsString(startPos, endPos);
|
const generic_string text = getGenericTextAsString(startPos, endPos);
|
||||||
std::vector<generic_string> splitText = stringSplit(text, getEOLString());
|
std::vector<generic_string> splitText = stringSplit(text, getEOLString());
|
||||||
|
const size_t lineCount = execute(SCI_GETLINECOUNT);
|
||||||
|
const bool sortAllLines = toLine == lineCount - 1;
|
||||||
|
if (!sortAllLines)
|
||||||
|
{
|
||||||
|
if (splitText.rbegin()->empty())
|
||||||
|
{
|
||||||
|
splitText.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(toLine - fromLine + 1 == splitText.size());
|
||||||
std::sort(splitText.begin(), splitText.end(), [isDescending](generic_string a, generic_string b)
|
std::sort(splitText.begin(), splitText.end(), [isDescending](generic_string a, generic_string b)
|
||||||
{
|
{
|
||||||
if (isDescending)
|
if (isDescending)
|
||||||
@ -2970,8 +2980,15 @@ void ScintillaEditView::sortLines(size_t fromLine, size_t toLine, bool isDescend
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const generic_string joined = stringJoin(splitText, getEOLString());
|
const generic_string joined = stringJoin(splitText, getEOLString());
|
||||||
|
if (sortAllLines)
|
||||||
|
{
|
||||||
replaceTarget(joined.c_str(), startPos, endPos);
|
replaceTarget(joined.c_str(), startPos, endPos);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
replaceTarget((joined + getEOLString()).c_str(), startPos, endPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ScintillaEditView::isTextDirectionRTL() const
|
bool ScintillaEditView::isTextDirectionRTL() const
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user