Page MenuHomePhabricator

Add button and keyboard shortcut to sort lines of text
Closed, ResolvedPublic

Description

Requested on Discord.

Many IDEs offer a "sort lines" option, and CodeMirror could, too. At minimum we could add a keyboard shortcut, or maybe two – one for ascending, then the other using Shift to sort descending. Additionally we could add a button to WikiEditor in the "Advanced" section, perhaps as part of the "Format" group of buttons.

Sorting should be done using localeCompare with "base" sensitivity, so that accents and capitalization are taken into account. If a particular language or wiki needs further customization, we can offer it either as a gadget or directly in CodeMirror, depending on how widespread the needs are.

Related Objects

Event Timeline

Change #1268944 had a related patch set uploaded (by Manvi Kesarwani; author: Manvi Kesarwani):

[mediawiki/extensions/CodeMirror@master] Add sort lines feature for CodeMirror 6 in WikiEditor

https://gerrit.wikimedia.org/r/1268944

i have uploaded a patchset for this task can you review it

@Manvikesarwani09: Thanks; please don't duplicate a patch notification two minutes after that patch notification.

Change #1268944 had a related patch set uploaded (by Manvi Kesarwani; author: Manvi Kesarwani):

[mediawiki/extensions/CodeMirror@master] Add sort lines feature for CodeMirror 6 in WikiEditor

https://gerrit.wikimedia.org/r/1268944

Change #1271822 had a related patch set uploaded (by Manvi Kesarwani; author: Manvi Kesarwani):

[mediawiki/extensions/CodeMirror@master] Add line sorting actions for CodeMirror and WikiEditor

https://gerrit.wikimedia.org/r/1271822

Change #1268944 abandoned by Manvi Kesarwani:

[mediawiki/extensions/CodeMirror@master] Add sort lines feature for CodeMirror 6 in WikiEditor

Reason:

abondon

https://gerrit.wikimedia.org/r/1268944

please review this new patchset of mine.

There will be some breaking changes to be deployed next week for T373720: Deprecate use of CodeMirror 5, so I had better review new feature proposals after that.

Change #1271822 abandoned by Manvi Kesarwani:

[mediawiki/extensions/CodeMirror@master] Add line sorting actions for CodeMirror and WikiEditor

Reason:

abondon

https://gerrit.wikimedia.org/r/1271822

Change #1271822 restored by MusikAnimal:

[mediawiki/extensions/CodeMirror@master] Add line sorting actions for CodeMirror and WikiEditor

https://gerrit.wikimedia.org/r/1271822

Change #1271822 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] Add line sorting actions for CodeMirror and WikiEditor

https://gerrit.wikimedia.org/r/1271822

The selection becomes very strange after sorting if the original selection was not whole lines, and there is a RangeError thrown in the console.

The selection becomes very strange after sorting if the original selection was not whole lines, and there is a RangeError thrown in the console.

I think you mean when you don't select from the start of the line, yeah? Indeed that doesn't cause weirdness… I will try to fix it.

Change #1322248 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] CodeMirrorSortLines: keep lines selected after sorting

https://gerrit.wikimedia.org/r/1322248

MusikAnimal changed the task status from Open to In Progress.Aug 7 2026, 12:54 AM

Change #1322276 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] CodeMirrorWikiEditor: add custom icons for sort asc/desc; add RTL support

https://gerrit.wikimedia.org/r/1322276

Change #1322284 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] Add svgo@4.0.2 and update icons with pretty format and tabs

https://gerrit.wikimedia.org/r/1322284

Change #1322248 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirrorSortLines: keep lines selected after sorting

https://gerrit.wikimedia.org/r/1322248

Change #1322276 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirrorWikiEditor: add icons for sort asc/desc

https://gerrit.wikimedia.org/r/1322276

Change #1322284 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] Add svgo@4.0.2 and update icons with pretty format and tabs

https://gerrit.wikimedia.org/r/1322284