Skip to content

Commit 17aa7ca

Browse files
committed
Use single input for same placeholder variables
1 parent 0166246 commit 17aa7ca

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Save Commands",
44
"description": "Simple VSCode Extension to save and execute terminal commands.",
55
"icon": "media/save-commands.png",
6-
"version": "1.0.1",
6+
"version": "1.0.2",
77
"engines": {
88
"vscode": "^1.74.0"
99
},

src/models/command.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,15 @@ export default class Command {
9898
}
9999

100100
const inputs: Record<string, string> = {};
101-
for (const placeholder of matches) {
101+
102+
for (const placeholder in matches) {
102103
const input = await takeSingleInput({
103104
promptText: `${resolveCommandType} | ${this.name} | ${placeholder} | `,
104105
placeholder: `Enter ${placeholder}`,
105106
});
106-
inputs[placeholder] = input;
107+
matches[placeholder].forEach((match) => {
108+
inputs[match] = input;
109+
});
107110
}
108111
const resolvedCommand = this.command.replace(regex, (match) => {
109112
if (match in inputs) {

src/models/placeholder_types.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ export abstract class PlaceholderType {
44

55
abstract wrapLabel(label: string): string;
66

7-
extractPlaceholders = (str: string): Array<string> | null => {
8-
return str.match(this.regex);
7+
extractPlaceholders = (str: string): Record<string, Set<string>> | null => {
8+
const matches = str.match(this.regex) ?? null;
9+
if (!matches) return null;
10+
const placeholders: Record<string, Set<string>> = {}
11+
matches?.map((m) => {
12+
const text = m.replace(/^\W+|\W+$/g, '')
13+
if (!placeholders[text]) {
14+
placeholders[text] = new Set([m])
15+
} else {
16+
placeholders[text].add(m)
17+
}
18+
});
19+
return placeholders;
920
};
1021

1122
static getPlaceholderTypeFromId(id: string) {

0 commit comments

Comments
 (0)