Skip to content

Commit 8683144

Browse files
authored
Merge pull request #37 from ryuta46/develop
2 parents 32c7b76 + 07441af commit 8683144

5 files changed

Lines changed: 197 additions & 99 deletions

File tree

README.md

Lines changed: 83 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,43 @@ This extension can create command sequence as one command and bind a key, or cal
44

55
## Features
66

7-
* create command sequence as one command and bind a key.
8-
* call command sequence manually.
9-
* set interval between each command execution.
7+
- create command sequence as one command and bind a key.
8+
- call command sequence manually.
9+
- set interval between each command execution.
1010

1111
## Extension Settings
1212

13-
Settings has 2 steps.
13+
There is simple usage that uses only keybindings.json and a usage that uses settings.json.
14+
15+
### Simple Usage with keybindings.json
16+
17+
In keybindings.json, bind a key to `extension.multiCommand.execute` with passing a command sequence you want to execute as the argument.
18+
For example:
19+
20+
```json
21+
{
22+
"key": "alt+x",
23+
"command": "extension.multiCommand.execute",
24+
"args": {
25+
"sequence": [
26+
"cursorDown",
27+
"cursorDown",
28+
"cursorDown"
29+
]
30+
}
31+
}
32+
```
33+
This command sequence executes "cursorDown" command 3 times.
34+
35+
### Usage with settings.json.
36+
37+
This usage is useful for resusing the defined command sequence in another command sequnce or executing the sequence manually.
38+
39+
In case using settings.json, the settings has 2 steps.
1440

1541
1. Create command sequence as one command in settings.json.
1642
For example:
43+
1744
```json
1845
"multiCommand.commands": [
1946
{
@@ -36,22 +63,38 @@ Settings has 2 steps.
3663
}
3764
]
3865
```
66+
3967
First sequence is named "multiCommand.down3Lines" and executes "cursorDown" command 3 times.
4068

4169
Second sequence is named "multiCommand.swapChar". This sequence swaps cursor's left character and the right character. If a command is executed asynchronousely, you can set time interval between each command execution using "interval" configuration(milliseconds).
4270

71+
You can also use an object style that uses the command name as a key instead of an array.
72+
```json
73+
"multiCommand.commands": {
74+
"multiCommand.down3Lines": {
75+
"sequence": [
76+
"cursorDown",
77+
"cursorDown",
78+
"cursorDown"
79+
]
80+
}
81+
}
82+
```
83+
This style is useful when you want to merge user settings and the workspace settings.
84+
4385
2. Bind a key to created command sequence in keybindings.json.
44-
For example:
86+
For example:
87+
4588
```json
46-
{
47-
"key": "F1",
48-
"command": "extension.multiCommand.execute" ,
89+
{
90+
"key": "F1",
91+
"command": "extension.multiCommand.execute",
4992
"args": { "command": "multiCommand.down3Lines" },
5093
"when": "editorTextFocus"
5194
},
52-
{
53-
"key": "F21",
54-
"command": "extension.multiCommand.execute" ,
95+
{
96+
"key": "F21",
97+
"command": "extension.multiCommand.execute",
5598
"args": { "command": "multiCommand.swapChar" },
5699
"when": "editorTextFocus"
57100
}
@@ -60,10 +103,20 @@ Settings has 2 steps.
60103
You can bind a key to the command directly.
61104

62105
For example:
106+
63107
```json
64-
{ "key": "F1", "command": "multiCommand.down3Lines", "when": "editorTextFocus"},
65-
{ "key": "F2", "command": "multiCommand.swapChar", "when": "editorTextFocus"}
108+
{
109+
"key": "F1",
110+
"command": "multiCommand.down3Lines",
111+
"when": "editorTextFocus"
112+
},
113+
{
114+
"key": "F2",
115+
"command": "multiCommand.swapChar",
116+
"when": "editorTextFocus"
117+
}
66118
```
119+
67120
But when you use this key bind style, Visual Studio Code may warn about the command name. see: https://github.com/ryuta46/vscode-multi-command/issues/16
68121

69122
### Manual Execution
@@ -77,17 +130,19 @@ You can call a defined command sequence from command palette.
77130
If you want to call a command sequence in shorter steps, bind a key to "extension.multiCommand.execute".
78131

79132
For example:
133+
80134
```json
81-
{
82-
"key": "cmd+shift+m",
83-
"command": "extension.multiCommand.execute"
84-
}
135+
{
136+
"key": "cmd+shift+m",
137+
"command": "extension.multiCommand.execute"
138+
}
85139
```
86140

87141
If you set `label` and `description` parameters in settings.json, they are displayed when you choose a command sequence.
88142
Both parameters are optional.
89143

90144
For example:
145+
91146
```json
92147
"multiCommand.commands": [
93148
{
@@ -113,23 +168,21 @@ For Example:
113168
{
114169
"command": "multiCommand.cutAndType",
115170
"sequence": [
116-
"editor.action.clipboardCutAction",
117-
{"command": "type", "args": {"text": "CUT !!"}}
171+
"editor.action.clipboardCutAction",
172+
{ "command": "type", "args": { "text": "CUT !!" } }
118173
]
119174
}
120175
```
121176

122177
This sequence cut selected text and type "CUT !!".
123178

124-
125179
### Find the name of the command you want to execute
126180

127181
1. Execute "Developer: Set Log Level..." and select "trace" in the command palette.
128182

129183
2. Execute command of you want to know the name.
130-
131184
3. You can see the name in output panel for Log(Window) process( you can set the process for output in the rightside of the output panel).
132-
![command-name-output.png](assets/command-name-output.png)
185+
![command-name-output.png](assets/command-name-output.png)
133186

134187
### Using shell commands in a command sequence
135188

@@ -141,7 +194,10 @@ With Command Runner extension, you can write a command sequence with shell comma
141194
{
142195
"command": "multiCommand.checkoutDevelop",
143196
"sequence": [
144-
{ "command": "command-runner.run", "args": {"command": "git checkout develop"} },
197+
{
198+
"command": "command-runner.run",
199+
"args": { "command": "git checkout develop" }
200+
},
145201
"git.sync"
146202
]
147203
}
@@ -151,6 +207,10 @@ See the [Command Runner document](https://marketplace.visualstudio.com/items?ite
151207

152208
## Release Notes
153209

210+
### 1.5.0
211+
New Feature: Simple usage only with keybindings.json
212+
New Feature: Object style settings for merging user settings and workspace settings.
213+
154214
### 1.4.0
155215

156216
Added new style for binding a key to created commands.
@@ -171,4 +231,3 @@ Now, you can use a custom multi-command immediately after adding it in the setti
171231
### 1.0.0
172232

173233
Initial release.
174-

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "multi-command",
33
"displayName": "multi-command",
44
"description": "Invoke multiple commands as one command.",
5-
"version": "1.4.0",
5+
"version": "1.5.0",
66
"publisher": "ryuta46",
77
"repository": {
88
"type": "git",
@@ -31,7 +31,10 @@
3131
"title": "multi-command",
3232
"properties": {
3333
"multiCommand.commands": {
34-
"type": "array",
34+
"type": [
35+
"array",
36+
"object"
37+
],
3538
"items": {
3639
"type": "object",
3740
"title": "command sequence",
@@ -69,10 +72,10 @@
6972
"test": "npm run compile && node ./node_modules/vscode/bin/test"
7073
},
7174
"devDependencies": {
72-
"typescript": "^2.0.3",
75+
"typescript": "^3.9.7",
7376
"vscode": "^1.0.0",
7477
"mocha": "^2.3.3",
75-
"@types/node": "^6.0.40",
78+
"@types/node": "^7.0.7",
7679
"@types/mocha": "^2.2.32"
7780
}
7881
}

src/command.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as vscode from "vscode";
22

33
export class Command {
4-
constructor(private readonly exe: string, private readonly args: object | null) {}
4+
constructor(
5+
private readonly exe: string,
6+
private readonly args: object | null
7+
) {}
58

69
public execute() {
710
if (this.args === null) {
8-
return vscode.commands.executeCommand(this.exe)
11+
return vscode.commands.executeCommand(this.exe);
912
} else {
10-
return vscode.commands.executeCommand(this.exe, this.args)
13+
return vscode.commands.executeCommand(this.exe, this.args);
1114
}
1215
}
1316
}

0 commit comments

Comments
 (0)