Skip to content

Commit

Permalink
Fix case sensitive sorting (#4023)
Browse files Browse the repository at this point in the history
Fixes #3939
noslaver authored and J-Fields committed Sep 1, 2019

Verified

This commit was signed with the committer’s verified signature. The key has expired.
sohkai Brett Sun
1 parent afe8b1c commit c246ac6
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/cmd_line/commands/sort.ts
Original file line number Diff line number Diff line change
@@ -58,11 +58,9 @@ export class SortCommand extends node.CommandBase {

let lastLineLength = originalLines[originalLines.length - 1].length;

const compareFn = this._arguments.ignoreCase
? (a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase())
: (a: string, b: string) => a.localeCompare(b);

let sortedLines = originalLines.sort(compareFn);
let sortedLines = this._arguments.ignoreCase
? originalLines.sort((a: string, b: string) => a.localeCompare(b))
: originalLines.sort();

if (this._arguments.reverse) {
sortedLines.reverse();
4 changes: 2 additions & 2 deletions test/cmd_line/sort.test.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ suite('Basic sort', () => {
test('Sort whole file, asc', async () => {
await modeHandler.handleMultipleKeyEvents([
'i',
'b',
'B',
'<Esc>',
'o',
'a',
@@ -30,7 +30,7 @@ suite('Basic sort', () => {
]);
await commandLine.Run('sort', vimState);

assertEqualLines(['a', 'b', 'c']);
assertEqualLines(['B', 'a', 'c']);
});

test('Sort whole file, asc, ignoreCase', async () => {

0 comments on commit c246ac6

Please sign in to comment.