Skip to content

Commit 77c1da6

Browse files
committed
added reverse manager
1 parent 80d5ea3 commit 77c1da6

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ pops an alert, in the bottom right corner, with the information of the length of
7878
#### >Number of non ASCII Characters in Selection
7979
pops an alert, in the bottom right corner, with the information of the number of non ascii characters in the selected text
8080

81+
---
82+
#### >Reverse Selection
83+
It will reverse the selection, line by line
84+
8185
---
8286
#### >Lorem Ipsum on Selection
8387
replaces the selection with *lorem ipsum*, if nothing is selected will replace the whole line where the cursor is placed

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Selection Manager",
44
"description": "Manage selected text of a file.",
55
"icon": "images/manage-selection.png",
6-
"version": "0.0.20",
6+
"version": "0.0.21",
77
"license": "MIT",
88
"engines": {
99
"vscode": "^1.66.0"
@@ -30,7 +30,8 @@
3030
"onCommand:selection-manager.snake-to-kebab",
3131
"onCommand:selection-manager.length",
3232
"onCommand:selection-manager.lorem-ipsum",
33-
"onCommand:selection-manager.non-ascii"
33+
"onCommand:selection-manager.non-ascii",
34+
"onCommand:selection-manager.reverse"
3435
],
3536
"main": "./dist/extension.js",
3637
"contributes": {
@@ -110,6 +111,10 @@
110111
{
111112
"command": "selection-manager.non-ascii",
112113
"title": "Number of non ASCII Characters in Selection"
114+
},
115+
{
116+
"command": "selection-manager.reverse",
117+
"title": "Reverse Selection"
113118
}
114119
]
115120
},

src/extension.ts

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
kebabToSnakeManager,
1919
loremIpsumManager,
2020
nonAsciiManager,
21+
reverseManager,
2122
} from './managers';
2223
import { snakeToKebabManager } from './managers/snakeToKebab';
2324

@@ -46,6 +47,7 @@ export function activate(context: vscode.ExtensionContext) {
4647
['selection-manager.length', lengthManager],
4748
['selection-manager.lorem-ipsum', loremIpsumManager],
4849
['selection-manager.non-ascii', nonAsciiManager],
50+
['selection-manager.reverse', reverseManager]
4951
];
5052

5153
dispose.forEach(([key, manager]) => context.subscriptions.push(vscode.commands.registerCommand(key, manager)));

src/managers/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ export * from './kebabToSnake';
1717
export * from './snakeToCamel';
1818
export * from './loremIpsum';
1919
export * from './nonAscii';
20+
export * from './reverse';

src/managers/reverse.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as vscode from 'vscode';
2+
3+
export async function reverseManager(): Promise<void> {
4+
const editor = vscode.window.activeTextEditor;
5+
6+
if (!editor) return;
7+
8+
const selectedText = editor.document.getText(editor.selection);
9+
10+
const splitByLine = selectedText.split("\n");
11+
12+
const reversedByLine = splitByLine.map(line => line.split("").reverse().join(""));
13+
14+
const text = reversedByLine.join("\n");
15+
16+
const docText = editor.document.getText().replace(selectedText, text);
17+
18+
editor.edit(edit => {
19+
edit.replace(new vscode.Range(0, 0, editor.document.lineCount, 0), docText);
20+
});
21+
}

0 commit comments

Comments
 (0)