Skip to content

Commit 3c14f78

Browse files
committed
0.0.1 got it all working alright
1 parent d8a1b0c commit 3c14f78

File tree

10 files changed

+178
-180
lines changed

10 files changed

+178
-180
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Change Log
22

3-
All notable changes to the "pasteregex" extension will be documented in this file.
3+
All notable changes to the "PasteRegEx" extension will be documented in this file.
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

README.md

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
1-
# pasteregex README
1+
# PasteRegEx README
22

3-
This is the README for your extension "pasteregex". After writing up a brief description, we recommend including the following sections.
3+
PasteRegEx is a simple extension which applies Regular Expressions (RegEx) to text selected in an active editor.
4+
5+
-----------------------------------------------------------------------------------------------------------
46

57
## Features
68

7-
Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
9+
After you select some text in an editor you can then select a PasteRegEx command and it will apply the Regular Expression to that selected text.
10+
11+
This is a list of the current regular expressions that are currently implemented. They are shown in this format:
812

9-
For example if there is an image subfolder under your extension project workspace:
13+
functionName - function description - "regular expression", "flags" - "replacement text"
1014

15+
- rmHangingSpaces - This function removes all of the spaces that appear at the end of sentences - " $", "gm" - ""
16+
- rmNewLines - This function removes all of the new lines in the selection - "\n", "gm" - " "
17+
- rmHyphenLineEnd - This function removes all of the hyphens that appear at the end of the line - "(?<=[a-z])-$\n(?=[a-z])", "gm" - ""
18+
- rmSentenceBreaks - This function removes all of the newlines that appear to break up a sentence - "[a-z]$\n+[a-z]", "gm" - " "
19+
<!--
1120
\!\[feature X\]\(images/feature-x.png\)
1221
1322
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
23+
-->
24+
25+
-----------------------------------------------------------------------------------------------------------
1426

1527
## Requirements
1628

17-
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
29+
I do not believe there are any special requirements needed to run this extension.
1830

31+
<!--
1932
## Extension Settings
2033
2134
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
@@ -26,40 +39,50 @@ This extension contributes the following settings:
2639
2740
* `myExtension.enable`: enable/disable this extension
2841
* `myExtension.thing`: set to `blah` to do something
42+
-->
43+
-----------------------------------------------------------------------------------------------------------
2944

30-
## Known Issues
31-
32-
Calling out known issues can help limit users opening duplicate issues against your extension.
33-
34-
## Release Notes
35-
36-
Users appreciate release notes as you update your extension.
37-
38-
### 1.0.0
39-
40-
Initial release of ...
41-
42-
### 1.0.1
45+
## Plans for Future Releases
46+
47+
These plans are very much a wishlist that may or may not ever be completed. Feel free to create issues and/or pull requests to add features.
48+
49+
- add more regular expressions
50+
- add the ability to combine multiple regular expressions in sequence
51+
- [set up webpack to reduce the size of the extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension)
52+
<!-- - [publish the extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) -->
53+
- [set up a CI workflow](https://code.visualstudio.com/api/working-with-extensions/continuous-integration)
54+
- add the ability to choose to apply the regular expression to either the selection or the clipboard
55+
- regular expression maker
56+
- this is a very low priority and likely not to happen without help
57+
- this would allow you to enter a regular expression yourself and choose some options some of these options could include
58+
- prefix characters that will not be replaced
59+
- main body expression to be replaced
60+
- post body characters to not be replaced
61+
- change what characters are replacing the body of regular expression
62+
- refactor the commands to be selected from a menu rather than each one being a separate command
63+
- I'm not sure I want this or not so I'll give it some more thought
64+
- testing (I have NO experience with software testing so this will almost certainly happen ONLY if someone else takes on the task)
4365

44-
Fixed issue #.
66+
-----------------------------------------------------------------------------------------------------------
4567

46-
### 1.1.0
68+
## Known Issues
4769

48-
Added features X, Y, and Z.
70+
At the moment there are no known issues
4971

5072
-----------------------------------------------------------------------------------------------------------
5173

52-
## Working with Markdown
74+
## Release Notes
5375

54-
**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
76+
### 0.0.1
5577

56-
* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux)
57-
* Toggle preview (`Shift+CMD+V` on macOS or `Shift+Ctrl+V` on Windows and Linux)
58-
* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (macOS) to see a list of Markdown snippets
78+
Initial release of PasteRegEx
5979

60-
### For more information
80+
Includes:
6181

62-
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
63-
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
82+
- apply regular expression to selected text
83+
- implimented the following commands
84+
- rmHangingSpaces
85+
- rmNewLines
86+
- rmHyphenLineEnd
87+
- rmSentenceBreaks
6488

65-
**Enjoy!**

images/PasteRegEx.png

21.2 KB
Loading

package-lock.json

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,54 @@
11
{
22
"name": "pasteregex",
3-
"displayName": "PasteRegex",
3+
"displayName": "PasteRegEx",
44
"description": "This extension allows you to run a regex statement on your clipboard text before pasting that text content",
5-
"version": "0.0.1",
5+
"version": "0.0.1",
6+
"publisher": "ldsands",
7+
"author": {
8+
"name": "Levi Sands"
9+
},
10+
"keywords": ["RegEx", "edit", "text", "formatter", "plain text"],
611
"engines": {
712
"vscode": "^1.44.0"
8-
},
13+
},
14+
"icon": "images/PasteRegEx.png",
915
"categories": [
1016
"Other"
11-
],
17+
],
18+
"license": "SEE LICENSE IN LICENSE.txt",
19+
"homepage": "https://github.com/ldsands/PasteRegEx/blob/master/README.md",
20+
"bugs": {
21+
"url": "https://github.com/ldsands/PasteRegEx/issues"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/ldsands/PasteRegEx.git"
26+
},
1227
"activationEvents": [
13-
"onCommand:pasteregex.helloWorld"
28+
"onCommand:PasteRegEx.rmHangingSpaces",
29+
"onCommand:PasteRegEx.rmNewLines",
30+
"onCommand:PasteRegEx.rmHyphenLineEnd",
31+
"onCommand:PasteRegEx.rmSentenceBreaks"
1432
],
1533
"main": "./out/extension.js",
1634
"contributes": {
1735
"commands": [
1836
{
19-
"command": "pasteregex.helloWorld",
20-
"title": "Hello World"
21-
}
37+
"command": "PasteRegEx.rmHangingSpaces",
38+
"title": "PasteRegEx: Remove Hanging Spaces"
39+
},
40+
{
41+
"command": "PasteRegEx.rmNewLines",
42+
"title": "PasteRegEx: Remove New Lines"
43+
},
44+
{
45+
"command": "PasteRegEx.rmHyphenLineEnd",
46+
"title": "PasteRegEx: Remove New Lines"
47+
},
48+
{
49+
"command": "PasteRegEx.rmSentenceBreaks",
50+
"title": "PasteRegEx: Remove New Lines"
51+
}
2252
]
2353
},
2454
"scripts": {
@@ -30,13 +60,13 @@
3060
"test": "node ./out/test/runTest.js"
3161
},
3262
"devDependencies": {
33-
"@types/vscode": "^1.44.0",
3463
"@types/glob": "^7.1.1",
3564
"@types/mocha": "^7.0.2",
3665
"@types/node": "^13.11.0",
37-
"eslint": "^6.8.0",
38-
"@typescript-eslint/parser": "^2.26.0",
66+
"@types/vscode": "^1.44.0",
3967
"@typescript-eslint/eslint-plugin": "^2.26.0",
68+
"@typescript-eslint/parser": "^2.26.0",
69+
"eslint": "^6.8.0",
4070
"glob": "^7.1.6",
4171
"mocha": "^7.1.1",
4272
"typescript": "^3.8.3",

src/extension.ts

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,84 @@
1-
// The module 'vscode' contains the VS Code extensibility API
2-
// Import the module and reference it with the alias vscode in your code below
1+
'use strict';
32
import * as vscode from 'vscode';
3+
import { TextDocument, Position, Selection } from 'vscode';
4+
// import { commands, window, TextDocument, TextEditorEdit, ExtensionContext, Position, SnippetString, Selection } from 'vscode';
45

5-
// this method is called when your extension is activated
6-
// your extension is activated the very first time the command is executed
7-
export function activate(context: vscode.ExtensionContext) {
86

9-
// Use the console to output diagnostic information (console.log) and errors (console.error)
10-
// This line of code will only be executed once when your extension is activated
11-
console.log('Congratulations, your extension "pasteregex" is now active!');
7+
// declaring constants
8+
const editor = vscode.window.activeTextEditor;
9+
10+
function getSelectedText(): string {
11+
/*
12+
This function is meant to get the text that is currently selected
13+
*/
14+
let document = editor?.document;
15+
let selection = editor?.selection;
16+
let selectedText = document?.getText(selection);
17+
return selectedText as string
18+
}
19+
20+
function insertNewString(modifiedString: string) {
21+
/*
22+
This function is meant to get the text that is currently selected
23+
*/
24+
if (editor) {
25+
let selection = editor.selection;
26+
editor.edit(editBuilder => {
27+
editBuilder.replace(selection, modifiedString);
28+
});
29+
}
30+
}
31+
32+
// export the vscode commands that'll show up in the command pallette
33+
export function activate(context: vscode.ExtensionContext) {
34+
let disposable = vscode.commands.registerCommand("PasteRegEx.rmHangingSpaces", async () => {
35+
/*
36+
This function removes all of the spaces that appear at the end of sentences
37+
*/
38+
var selectionText: String = getSelectedText();
39+
let editor = vscode.window.activeTextEditor;
40+
let RegEx = new RegExp(" $", "gm")
41+
var modifiedString: string = selectionText.replace(RegEx, "");
42+
insertNewString(modifiedString)
43+
});
1244

13-
// The command has been defined in the package.json file
14-
// Now provide the implementation of the command with registerCommand
15-
// The commandId parameter must match the command field in package.json
16-
let disposable = vscode.commands.registerCommand('pasteregex.helloWorld', () => {
17-
// The code you place here will be executed every time your command is executed
45+
disposable = vscode.commands.registerCommand("PasteRegEx.rmNewLines", async () => {
46+
/*
47+
This function removes all of the new lines in the selection
48+
*/
49+
var selectionText: String = getSelectedText();
50+
let editor = vscode.window.activeTextEditor;
51+
let RegEx = new RegExp("\n", "gm")
52+
var modifiedString: string = selectionText.replace(RegEx, " ");
53+
insertNewString(modifiedString)
54+
});
1855

19-
// Display a message box to the user
20-
vscode.window.showInformationMessage('Hello World from PasteRegex!');
21-
});
56+
disposable = vscode.commands.registerCommand("PasteRegEx.rmHyphenLineEnd", async () => {
57+
/*
58+
This function removes all of the hyphens that appear at the end of the line
59+
*/
60+
var selectionText: String = getSelectedText();
61+
let editor = vscode.window.activeTextEditor;
62+
let RegEx = new RegExp("(?<=[a-z])-$\n(?=[a-z])", "gm")
63+
var modifiedString: string = selectionText.replace(RegEx, "");
64+
insertNewString(modifiedString)
65+
});
2266

23-
context.subscriptions.push(disposable);
67+
disposable = vscode.commands.registerCommand("PasteRegEx.rmSentenceBreaks", async () => {
68+
/*
69+
This function removes all of the newlines that appear to break up a sentence
70+
*/
71+
var selectionText: String = getSelectedText();
72+
let editor = vscode.window.activeTextEditor;
73+
let RegEx = new RegExp("[a-z]$\n+[a-z]", "gm")
74+
var modifiedString: string = selectionText.replace(RegEx, " ");
75+
insertNewString(modifiedString)
76+
});
2477
}
2578

26-
// this method is called when your extension is deactivated
27-
export function deactivate() {}
79+
export function deactivate() { }
80+
81+
/*
82+
Getting access to the clipboard text
83+
// var clipboardText = await vscode.env.clipboard.readText();
84+
*/

src/test/runTest.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/test/suite/extension.test.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)