From 6e84be21f4c0a3c4b214e005531c52a199d71f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20J=C3=B6nsson?= Date: Sat, 9 May 2015 10:22:50 +0200 Subject: [PATCH] Fix newline bug when not sorting all lines. --- .../ScitillaComponent/ScintillaEditView.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index a81f837c2..e19757cff 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -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 generic_string text = getGenericTextAsString(startPos, endPos); std::vector 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) { if (isDescending) @@ -2970,7 +2980,14 @@ void ScintillaEditView::sortLines(size_t fromLine, size_t toLine, bool isDescend } }); const generic_string joined = stringJoin(splitText, getEOLString()); - replaceTarget(joined.c_str(), startPos, endPos); + if (sortAllLines) + { + replaceTarget(joined.c_str(), startPos, endPos); + } + else + { + replaceTarget((joined + getEOLString()).c_str(), startPos, endPos); + } } bool ScintillaEditView::isTextDirectionRTL() const