Skip to content

Commit f19bc49

Browse files
committed
Register new command and add to configs
1 parent 542fc6c commit f19bc49

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

package.json

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@
1919
"vscode": "^1.44.0"
2020
},
2121
"activationEvents": [
22-
"onCommand:snippet-copy.copyWithoutLeadingIndentation"
22+
"onCommand:snippet-copy.copySnippet",
23+
"onCommand:snippet-copy.copySnippetAsMarkdownCodeBlock"
2324
],
2425
"main": "./out/extension.js",
2526
"contributes": {
2627
"commands": [
2728
{
28-
"command": "snippet-copy.copyWithoutLeadingIndentation",
29-
"title": "Copy Without Leading Indentation"
29+
"command": "snippet-copy.copySnippet",
30+
"title": "Copy Snippet Without Leading Indentation"
31+
},
32+
{
33+
"command": "snippet-copy.copySnippetAsMarkdownCodeBlock",
34+
"title": "Copy Snippet Without Leading Indentation as Markdown Code Block"
3035
}
3136
],
3237
"configuration": {
@@ -41,19 +46,31 @@
4146
},
4247
"keybindings": [
4348
{
44-
"command": "snippet-copy.copyWithoutLeadingIndentation",
49+
"command": "snippet-copy.copySnippet",
4550
"mac": "Cmd+Ctrl+c",
4651
"linux": "Meta+Ctrl+c",
4752
"win": "Win+Ctrl+c",
4853
"when": "editorHasSelection"
54+
},
55+
{
56+
"command": "snippet-copy.copySnippetAsMarkdownCodeBlock",
57+
"mac": "Cmd+Ctrl+Shift+c",
58+
"linux": "Meta+Ctrl+Shift+c",
59+
"win": "Win+Ctrl+Shift+c",
60+
"when": "editorHasSelection"
4961
}
5062
],
5163
"menus": {
5264
"editor/context": [
5365
{
54-
"command": "snippet-copy.copyWithoutLeadingIndentation",
66+
"command": "snippet-copy.copySnippet",
5567
"when": "editorHasSelection",
5668
"group": "9_cutcopypaste@2"
69+
},
70+
{
71+
"command": "snippet-copy.copySnippetAsMarkdownCodeBlock",
72+
"when": "editorHasSelection",
73+
"group": "9_cutcopypaste@3"
5774
}
5875
]
5976
}

src/extension.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
import * as vscode from 'vscode';
2-
import { ExtensionContext } from 'vscode';
1+
import { commands, env, ExtensionContext } from 'vscode';
32
import { generateSnippet } from './lib/textHelpers';
43

54
export function activate(context: ExtensionContext) {
6-
let disposable = vscode.commands.registerTextEditorCommand('snippet-copy.copyWithoutLeadingIndentation', async (editor) => {
7-
const snippet = generateSnippet(editor.document, editor.selections);
5+
context.subscriptions.push(
6+
commands.registerTextEditorCommand('snippet-copy.copySnippet', async (editor) => {
7+
const snippet = generateSnippet(editor.document, editor.selections, false);
88

9-
await vscode.env.clipboard.writeText(snippet);
10-
});
9+
await env.clipboard.writeText(snippet);
10+
})
11+
);
12+
context.subscriptions.push(
13+
commands.registerTextEditorCommand('snippet-copy.copySnippetAsMarkdownCodeBlock', async (editor) => {
14+
const snippet = generateSnippet(editor.document, editor.selections, true);
1115

12-
context.subscriptions.push(disposable);
16+
await env.clipboard.writeText(snippet);
17+
})
18+
);
1319
}
1420

1521
export function deactivate() { }

0 commit comments

Comments
 (0)