Skip to content

Commit f7e771c

Browse files
authored
Merge pull request #132 from almeidaxan/master
Add option to keep only not duplicated lines
2 parents 1b182fe + 22a8f39 commit f7e771c

File tree

7 files changed

+45
-3
lines changed

7 files changed

+45
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
back
2+
band
3+
blah
4+
buck
5+
burp
6+
deck
7+
drill
8+
duck
9+
grand
10+
hello
11+
help
12+
puck
13+
quill
14+
trill
15+
zebra
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cc
2+
d
3+
aa
4+
c
5+
b
6+
bb
7+
a
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
012345
2+
0123456789
3+
𝟘𝟙𝟚𝟛
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var test10 = 1;
2+
var test100 = 100;

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
"command": "sortLines.keepOnlyDuplicateLines",
8484
"title": "Sort lines (keep only duplicated lines)"
8585
},
86+
{
87+
"command": "sortLines.keepOnlyNotDuplicateLines",
88+
"title": "Sort lines (keep only not duplicated lines)"
89+
},
8690
{
8791
"command": "sortLines.sortLinesShuffle",
8892
"title": "Sort lines (shuffle)"
@@ -178,9 +182,13 @@
178182
"command": "sortLines.keepOnlyDuplicateLines",
179183
"group": "2_sortLines@12"
180184
},
185+
{
186+
"command": "sortLines.keepOnlyNotDuplicateLines",
187+
"group": "2_sortLines@13"
188+
},
181189
{
182190
"command": "sortLines.sortLinesShuffle",
183-
"group": "2_sortLines@13"
191+
"group": "2_sortLines@14"
184192
}
185193
]
186194
},

src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export function activate(context: vscode.ExtensionContext): void {
1515
vscode.commands.registerCommand('sortLines.sortLinesUnique', sortLines.sortUnique),
1616
vscode.commands.registerCommand('sortLines.sortLinesShuffle', sortLines.sortShuffle),
1717
vscode.commands.registerCommand('sortLines.removeDuplicateLines', sortLines.removeDuplicateLines),
18-
vscode.commands.registerCommand('sortLines.keepOnlyDuplicateLines', sortLines.keepOnlyDuplicateLines)
18+
vscode.commands.registerCommand('sortLines.keepOnlyDuplicateLines', sortLines.keepOnlyDuplicateLines),
19+
vscode.commands.registerCommand('sortLines.keepOnlyNotDuplicateLines', sortLines.keepOnlyNotDuplicateLines)
1920
];
2021

2122
commands.forEach(command => context.subscriptions.push(command));

src/sort-lines.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ function keepOnlyDuplicates(lines: string[]): string[] {
6060
return Array.from(new Set(lines.filter((element, index, array) => array.indexOf(element) !== index)));
6161
}
6262

63+
function keepOnlyNotDuplicates(lines: string[]): string[] {
64+
return Array.from(new Set(lines.filter((element, index, array) => (array.lastIndexOf(element) === array.indexOf(element)))));
65+
}
66+
6367
function removeBlanks(lines: string[]): void {
6468
for (let i = 0; i < lines.length; ++i) {
6569
if (lines[i].trim() === '') {
@@ -143,7 +147,8 @@ const transformerSequences = {
143147
sortNatural: [makeSorter(naturalCompare)],
144148
sortShuffle: [shuffleSorter],
145149
removeDuplicateLines: [removeDuplicates],
146-
keepOnlyDuplicateLines: [keepOnlyDuplicates]
150+
keepOnlyDuplicateLines: [keepOnlyDuplicates],
151+
keepOnlyNotDuplicateLines: [keepOnlyNotDuplicates]
147152
};
148153

149154
export const sortNormal = () => sortActiveSelection(transformerSequences.sortNormal);
@@ -159,3 +164,4 @@ export const sortNatural = () => sortActiveSelection(transformerSequences.sortNa
159164
export const sortShuffle = () => sortActiveSelection(transformerSequences.sortShuffle);
160165
export const removeDuplicateLines = () => sortActiveSelection(transformerSequences.removeDuplicateLines);
161166
export const keepOnlyDuplicateLines = () => sortActiveSelection(transformerSequences.keepOnlyDuplicateLines);
167+
export const keepOnlyNotDuplicateLines = () => sortActiveSelection(transformerSequences.keepOnlyNotDuplicateLines);

0 commit comments

Comments
 (0)