Added fix for sort lines by selected text - #1106
Open
wstagg wants to merge 1 commit into
Open
Conversation
dail8859
requested changes
Aug 12, 2026
| const QByteArray text = readEditorText(); | ||
| QVector<QByteArrayView> lines = ByteArrayUtils::split(text, eol); | ||
| QByteArray text = readEditorText(); | ||
| const QByteArray selectedText = editor->getSelText(); |
Owner
There was a problem hiding this comment.
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.
|
|
||
| if (!selectedText.isEmpty()) | ||
| { | ||
| textStartIndex = text.indexOf(selectedText); |
Owner
There was a problem hiding this comment.
This will give incorrect results if the selectedText is in multiple location in the document.
| QByteArray result = ByteArrayUtils::join(lines, eol); | ||
| writeEditorText(result); | ||
|
|
||
| text.replace(textStartIndex, result.size(), result.data()); |
Owner
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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