Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
"title": "Sort lines (remove duplicate lines)"
},
{
"command": "sortLines.keepOnlyDuplicateLines",
"title": "Sort lines (keep only duplicated lines)"
},
"command": "sortLines.keepOnlyNotDuplicateLines",
"title": "Sort lines (keep only not duplicated lines)"
},
{
"command": "sortLines.sortLinesShuffle",
"title": "Sort lines (shuffle)"
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function activate(context: vscode.ExtensionContext): void {
vscode.commands.registerCommand('sortLines.sortLinesShuffle', sortLines.sortShuffle),
vscode.commands.registerCommand('sortLines.removeDuplicateLines', sortLines.removeDuplicateLines),
vscode.commands.registerCommand('sortLines.keepOnlyDuplicateLines', sortLines.keepOnlyDuplicateLines),
vscode.commands.registerCommand('sortLines.keepOnlyNotDuplicateLines', sortLines.keepOnlyNotDuplicateLines),
];

commands.forEach(command => context.subscriptions.push(command));
Expand Down
8 changes: 7 additions & 1 deletion src/sort-lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ function keepOnlyDuplicates(lines: string[]): string[] {
return Array.from(new Set(lines.filter((element, index, array) => array.indexOf(element) !== index)));
}

function keepOnlyNotDuplicates(lines: string[]): string[] {
return Array.from(new Set(lines.filter((element, index, array) => (array.lastIndexOf(element) == array.indexOf(element)))));
}

function removeBlanks(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
if (lines[i].trim() === '') {
Expand Down Expand Up @@ -143,7 +147,8 @@ const transformerSequences = {
sortNatural: [makeSorter(naturalCompare)],
sortShuffle: [shuffleSorter],
removeDuplicateLines: [removeDuplicates],
keepOnlyDuplicateLines: [keepOnlyDuplicates]
keepOnlyDuplicateLines: [keepOnlyDuplicates],
keepOnlyNotDuplicateLines: [keepOnlyNotDuplicates]
};

export const sortNormal = () => sortActiveSelection(transformerSequences.sortNormal);
Expand All @@ -159,3 +164,4 @@ export const sortNatural = () => sortActiveSelection(transformerSequences.sortNa
export const sortShuffle = () => sortActiveSelection(transformerSequences.sortShuffle);
export const removeDuplicateLines = () => sortActiveSelection(transformerSequences.removeDuplicateLines);
export const keepOnlyDuplicateLines = () => sortActiveSelection(transformerSequences.keepOnlyDuplicateLines);
export const keepOnlyNotDuplicateLines = () => sortActiveSelection(transformerSequences.keepOnlyNotDuplicateLines);