Skip to content

Commit 06921dc

Browse files
committed
Change the manager organisation and add url encoding manager
1 parent f629c2d commit 06921dc

File tree

8 files changed

+110
-62
lines changed

8 files changed

+110
-62
lines changed

images/manage-selection.png

4.32 KB
Loading

package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "selection-manager",
33
"displayName": "Selection Manager",
44
"description": "Manage selected text of a file.",
5-
"version": "0.0.2",
5+
"icon": "images/manage-selection.png",
6+
"version": "0.0.4",
67
"license": "MIT",
78
"engines": {
89
"vscode": "^1.66.0"
@@ -13,7 +14,8 @@
1314
"activationEvents": [
1415
"onCommand:selection-manager.copy",
1516
"onCommand:selection-manager.move",
16-
"onCommand:selection-manager.search"
17+
"onCommand:selection-manager.search",
18+
"onCommand:selection-manager.url-encode"
1719
],
1820
"main": "./dist/extension.js",
1921
"contributes": {
@@ -29,9 +31,17 @@
2931
{
3032
"command": "selection-manager.search",
3133
"title": "Search Selection"
34+
},
35+
{
36+
"command": "selection-manager.url-encode",
37+
"title": "URL Encode Selection"
3238
}
3339
]
3440
},
41+
"repository": {
42+
"type": "git",
43+
"url": "https://github.com/theteladras/vscode-selection-manager.git"
44+
},
3545
"scripts": {
3646
"vscode:prepublish": "yarn run package",
3747
"compile": "webpack",

src/extension.ts

+9-60
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,20 @@
11
import * as vscode from 'vscode';
2-
import { range } from './utils';
3-
4-
async function copyManager(): 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 document = await vscode.workspace.openTextDocument({
12-
language: editor.document.languageId,
13-
content: selectedText
14-
});
15-
16-
vscode.window.showTextDocument(document, undefined, true);
17-
}
18-
19-
async function moveManager(): Promise<void> {
20-
const editor = vscode.window.activeTextEditor;
21-
22-
if (!editor) return;
23-
24-
const selectedText = editor.document.getText(editor.selection);
25-
26-
const selectionStartIndex = editor.selection.start.line;
27-
const selectionEndIndex = editor.selection.end.line;
28-
29-
editor.edit(edit => {
30-
range(selectionStartIndex, selectionEndIndex).forEach(index => {
31-
const line = editor.document.lineAt(index);
32-
edit.delete(line.rangeIncludingLineBreak);
33-
});
34-
});
35-
36-
const document = await vscode.workspace.openTextDocument({
37-
language: editor.document.languageId,
38-
content: selectedText
39-
});
40-
41-
vscode.window.showTextDocument(document, undefined, true);
42-
}
43-
44-
async function searchManager(): Promise<void> {
45-
const editor = vscode.window.activeTextEditor;
46-
47-
if (!editor) return;
48-
49-
const selectedText = editor.document.getText(editor.selection);
50-
51-
const uri = vscode.Uri.from({
52-
path: 'search',
53-
query: `q=${selectedText}`,
54-
authority: 'google.com',
55-
scheme: 'https'
56-
});
57-
58-
vscode.env.openExternal(uri);
59-
}
2+
import { copyManager, moveManager, searchManager, urlEncodeManager } from './managers';
603

614
export function activate(context: vscode.ExtensionContext) {
625
console.log('Congratulations, your extension "selection-manager" is now active!');
636

647
let dispoeCopyManager = vscode.commands.registerCommand('selection-manager.copy', copyManager);
658
let dispoeMoveManager = vscode.commands.registerCommand('selection-manager.move', moveManager);
669
let dispoeSearchManager = vscode.commands.registerCommand('selection-manager.search', searchManager);
67-
68-
context.subscriptions.push(dispoeCopyManager, dispoeMoveManager, dispoeSearchManager);
10+
let dispoeUrlEncodeManager = vscode.commands.registerCommand('selection-manager.url-encode', urlEncodeManager);
11+
12+
context.subscriptions.push(
13+
dispoeCopyManager,
14+
dispoeMoveManager,
15+
dispoeSearchManager,
16+
dispoeUrlEncodeManager
17+
);
6918
}
7019

7120
export function deactivate() {}

src/managers/copy.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as vscode from 'vscode';
2+
3+
export async function copyManager(): 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 document = await vscode.workspace.openTextDocument({
11+
language: editor.document.languageId,
12+
content: selectedText
13+
});
14+
15+
vscode.window.showTextDocument(document, undefined, true);
16+
}

src/managers/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './copy';
2+
export * from './move';
3+
export * from './search';
4+
export * from './urlEncode';

src/managers/move.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as vscode from 'vscode';
2+
import { range } from "../utils";
3+
4+
export async function moveManager(): 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 selectionStartIndex = editor.selection.start.line;
12+
const selectionEndIndex = editor.selection.end.line;
13+
14+
editor.edit(edit => {
15+
range(selectionStartIndex, selectionEndIndex).forEach(index => {
16+
const line = editor.document.lineAt(index);
17+
edit.delete(line.rangeIncludingLineBreak);
18+
});
19+
});
20+
21+
const document = await vscode.workspace.openTextDocument({
22+
language: editor.document.languageId,
23+
content: selectedText
24+
});
25+
26+
vscode.window.showTextDocument(document, undefined, true);
27+
}

src/managers/search.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as vscode from 'vscode';
2+
3+
export async function searchManager(): 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 uri = vscode.Uri.from({
11+
path: 'search',
12+
query: `q=${selectedText}`,
13+
authority: 'google.com',
14+
scheme: 'https'
15+
});
16+
17+
vscode.env.openExternal(uri);
18+
}

src/managers/urlEncode.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as vscode from 'vscode';
2+
import { range } from "../utils";
3+
4+
export async function urlEncodeManager(): 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 encodedText = encodeURIComponent(selectedText);
12+
13+
const selectionStartIndex = editor.selection.start.line;
14+
const selectionEndIndex = editor.selection.end.line;
15+
16+
editor.edit(edit => {
17+
edit.replace
18+
range(selectionStartIndex, selectionEndIndex).forEach((index, i) => {
19+
const line = editor.document.lineAt(index);
20+
if (i === 0) return edit.replace(line.range, encodedText);
21+
edit.delete(line.rangeIncludingLineBreak);
22+
});
23+
});
24+
}

0 commit comments

Comments
 (0)