From 247910f41fc8fcec0c9f0e31bfe93a88810db7db Mon Sep 17 00:00:00 2001 From: Xan Date: Thu, 28 Sep 2023 16:55:19 -0300 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20Add=20option=20to=20keep=20only?= =?UTF-8?q?=20not=20duplicated=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 +++--- src/extension.ts | 1 + src/sort-lines.ts | 8 +++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 24baee5..8bb4e1b 100644 --- a/package.json +++ b/package.json @@ -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)" diff --git a/src/extension.ts b/src/extension.ts index c7ae77f..2688918 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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)); diff --git a/src/sort-lines.ts b/src/sort-lines.ts index a789846..9c79e7b 100644 --- a/src/sort-lines.ts +++ b/src/sort-lines.ts @@ -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() === '') { @@ -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); @@ -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); From 10ac80ad01af2620993155a04e03ffec2ed3c002 Mon Sep 17 00:00:00 2001 From: Xan Date: Mon, 2 Oct 2023 15:37:33 -0300 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=90=9B=20Undo=20delete=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index 8bb4e1b..abe26c2 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,10 @@ "command": "sortLines.removeDuplicateLines", "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)" From 82f36f29ecc3f74d25c28e597dc6bd970102ecde Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 8 Nov 2024 05:29:58 -0800 Subject: [PATCH 3/5] Add new command to context menu --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a70edeb..de820b2 100644 --- a/package.json +++ b/package.json @@ -182,9 +182,13 @@ "command": "sortLines.keepOnlyDuplicateLines", "group": "2_sortLines@12" }, + { + "command": "sortLines.keepOnlyNotDuplicateLines", + "group": "2_sortLines@13" + }, { "command": "sortLines.sortLinesShuffle", - "group": "2_sortLines@13" + "group": "2_sortLines@14" } ] }, From 5834c6626b472b0ce6ddad0e2aec78a7338229b0 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 8 Nov 2024 05:35:24 -0800 Subject: [PATCH 4/5] Add fixtures for new command --- .../keepOnlyNotDuplicateLines | 15 +++++++++++++++ .../keepOnlyNotDuplicateLines | 7 +++++++ .../unicode_expected/keepOnlyNotDuplicateLines | 3 +++ .../variables_expected/keepOnlyNotDuplicateLines | 2 ++ 4 files changed, 27 insertions(+) create mode 100644 fixtures/line_length_expected/keepOnlyNotDuplicateLines create mode 100644 fixtures/shuffled_lowercase_expected/keepOnlyNotDuplicateLines create mode 100644 fixtures/unicode_expected/keepOnlyNotDuplicateLines create mode 100644 fixtures/variables_expected/keepOnlyNotDuplicateLines diff --git a/fixtures/line_length_expected/keepOnlyNotDuplicateLines b/fixtures/line_length_expected/keepOnlyNotDuplicateLines new file mode 100644 index 0000000..fa8020d --- /dev/null +++ b/fixtures/line_length_expected/keepOnlyNotDuplicateLines @@ -0,0 +1,15 @@ +back +band +blah +buck +burp +deck +drill +duck +grand +hello +help +puck +quill +trill +zebra \ No newline at end of file diff --git a/fixtures/shuffled_lowercase_expected/keepOnlyNotDuplicateLines b/fixtures/shuffled_lowercase_expected/keepOnlyNotDuplicateLines new file mode 100644 index 0000000..0d6968c --- /dev/null +++ b/fixtures/shuffled_lowercase_expected/keepOnlyNotDuplicateLines @@ -0,0 +1,7 @@ +cc +d +aa +c +b +bb +a \ No newline at end of file diff --git a/fixtures/unicode_expected/keepOnlyNotDuplicateLines b/fixtures/unicode_expected/keepOnlyNotDuplicateLines new file mode 100644 index 0000000..686eaba --- /dev/null +++ b/fixtures/unicode_expected/keepOnlyNotDuplicateLines @@ -0,0 +1,3 @@ +012345 +0123456789 +𝟘𝟙𝟚𝟛 \ No newline at end of file diff --git a/fixtures/variables_expected/keepOnlyNotDuplicateLines b/fixtures/variables_expected/keepOnlyNotDuplicateLines new file mode 100644 index 0000000..9ee2944 --- /dev/null +++ b/fixtures/variables_expected/keepOnlyNotDuplicateLines @@ -0,0 +1,2 @@ +var test10 = 1; +var test100 = 100; \ No newline at end of file From 22a8f39ce6565ed7ce54491b1da64c9ede2e316d Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 8 Nov 2024 05:37:56 -0800 Subject: [PATCH 5/5] Fix lint --- src/extension.ts | 2 +- src/sort-lines.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 2688918..1666a63 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -16,7 +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), + vscode.commands.registerCommand('sortLines.keepOnlyNotDuplicateLines', sortLines.keepOnlyNotDuplicateLines) ]; commands.forEach(command => context.subscriptions.push(command)); diff --git a/src/sort-lines.ts b/src/sort-lines.ts index c1fbe13..64da0c4 100644 --- a/src/sort-lines.ts +++ b/src/sort-lines.ts @@ -61,7 +61,7 @@ function keepOnlyDuplicates(lines: string[]): string[] { } function keepOnlyNotDuplicates(lines: string[]): string[] { - return Array.from(new Set(lines.filter((element, index, array) => (array.lastIndexOf(element) == array.indexOf(element))))); + return Array.from(new Set(lines.filter((element, index, array) => (array.lastIndexOf(element) === array.indexOf(element))))); } function removeBlanks(lines: string[]): void {