Skip to content

Added fix for sort lines by selected text - #1106

Open
wstagg wants to merge 1 commit into
dail8859:masterfrom
wstagg:fix/Sort_Selection_#1099
Open

Added fix for sort lines by selected text#1106
wstagg wants to merge 1 commit into
dail8859:masterfrom
wstagg:fix/Sort_Selection_#1099

Conversation

@wstagg

@wstagg wstagg commented Aug 11, 2026

Copy link
Copy Markdown

When doing line operations -> sort lines ascending/descending now only the selected text is sorted

Example of three rows I want to Edit > Line Operations > Sort Lines Ascending:

Action

5
2 (selected)
4 (selected)
1 (selected)
3

Result:

5
1
2
4
3

Comment thread src/ScintillaSorter.cpp
const QByteArray text = readEditorText();
QVector<QByteArrayView> lines = ByteArrayUtils::split(text, eol);
QByteArray text = readEditorText();
const QByteArray selectedText = editor->getSelText();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just using the selected text will give odd results if partial lines are selected. It would need to sort whole lines. From the beginning of the line the selection starts, to the end of the line the end of the selection is on.

Comment thread src/ScintillaSorter.cpp

if (!selectedText.isEmpty())
{
textStartIndex = text.indexOf(selectedText);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will give incorrect results if the selectedText is in multiple location in the document.

Comment thread src/ScintillaSorter.cpp
QByteArray result = ByteArrayUtils::join(lines, eol);
writeEditorText(result);

text.replace(textStartIndex, result.size(), result.data());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to update the entire file, once the start and end location are determined then only that section of the editor's contents can be replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants