Skip to content

Commit 80d5ea3

Browse files
committed
added non ascii count manager
1 parent 4ab959e commit 80d5ea3

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ isolate the selection, results in having the content of the document replaced wi
2020

2121
---
2222
#### >Search Selection
23-
search for the selection on google
23+
search for the selection on *google*
2424

2525
---
2626
#### >URL Encode Selection
@@ -74,6 +74,10 @@ the selected snake case text will be turned to kebab case _(eg. call\_sync -> ca
7474
#### >Length of Selection
7575
pops an alert, in the bottom right corner, with the information of the length of the selected text
7676

77+
---
78+
#### >Number of non ASCII Characters in Selection
79+
pops an alert, in the bottom right corner, with the information of the number of non ascii characters in the selected text
80+
7781
---
7882
#### >Lorem Ipsum on Selection
79-
replaces the selection with lorem ipsum, if nothing is selected will replace the whole line where the cursor is placed
83+
replaces the selection with *lorem ipsum*, if nothing is selected will replace the whole line where the cursor is placed

package.json

+8-3
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.19",
6+
"version": "0.0.20",
77
"license": "MIT",
88
"engines": {
99
"vscode": "^1.66.0"
@@ -29,7 +29,8 @@
2929
"onCommand:selection-manager.kebab-to-snake",
3030
"onCommand:selection-manager.snake-to-kebab",
3131
"onCommand:selection-manager.length",
32-
"onCommand:selection-manager.loremIpsum"
32+
"onCommand:selection-manager.lorem-ipsum",
33+
"onCommand:selection-manager.non-ascii"
3334
],
3435
"main": "./dist/extension.js",
3536
"contributes": {
@@ -103,8 +104,12 @@
103104
"title": "Length of Selection"
104105
},
105106
{
106-
"command": "selection-manager.loremIpsum",
107+
"command": "selection-manager.lorem-ipsum",
107108
"title": "Lorem Ipsum on Selection"
109+
},
110+
{
111+
"command": "selection-manager.non-ascii",
112+
"title": "Number of non ASCII Characters in Selection"
108113
}
109114
]
110115
},

src/extension.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
camelToKebabManager,
1818
kebabToSnakeManager,
1919
loremIpsumManager,
20+
nonAsciiManager,
2021
} from './managers';
2122
import { snakeToKebabManager } from './managers/snakeToKebab';
2223

@@ -43,7 +44,8 @@ export function activate(context: vscode.ExtensionContext) {
4344
['selection-manager.kebab-to-snake', kebabToSnakeManager],
4445
['selection-manager.snake-to-kebab', snakeToKebabManager],
4546
['selection-manager.length', lengthManager],
46-
['selection-manager.loremIpsum', loremIpsumManager],
47+
['selection-manager.lorem-ipsum', loremIpsumManager],
48+
['selection-manager.non-ascii', nonAsciiManager],
4749
];
4850

4951
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
@@ -16,3 +16,4 @@ export * from './camelToKebab';
1616
export * from './kebabToSnake';
1717
export * from './snakeToCamel';
1818
export * from './loremIpsum';
19+
export * from './nonAscii';

src/managers/nonAscii.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as vscode from 'vscode';
2+
import { removeAsciiCharacters } from '../utils';
3+
4+
export async function nonAsciiManager(): Promise<void> {
5+
const editor = vscode.window.activeTextEditor;
6+
7+
if (!editor) return;
8+
9+
const selectedText = editor.document.getText(editor.selection);
10+
11+
const length = removeAsciiCharacters(selectedText).length;
12+
13+
vscode.window.showInformationMessage(`Number of non ASCII Characters: ${length}`);
14+
}

src/utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ export const kebabToSnake = (str: string): string => str.replace(/-/g, "_");
2929
export const snakeToKebab = (str: string): string => str.replace(/_/g, "-");
3030

3131
export const generateLoremIpsum = (): string => lorem.generator.generateRandomSentence();
32+
33+
export const removeAsciiCharacters = (str: string): string => str.replace(/[ -~]/g, "");

0 commit comments

Comments
 (0)