You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/Advanced/onePageInputs.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -184,3 +184,4 @@ Behavior:
184
184
- Preflight may import user script modules to statically read `quickadd.inputs`. This can execute module top-level code.
185
185
- Inline scripts aren’t scanned for input declarations yet.
186
186
- If needed, you can still prompt ad-hoc (e.g., using inputPrompt or suggester) and those values will skip future one-page prompts due to being prefilled.
187
+
- Closing the modal without submitting triggers `MacroAbortError("Input cancelled by user")`, which stops the macro unless you catch it.
Copy file name to clipboardExpand all lines: docs/docs/QuickAddAPI.md
+20-12Lines changed: 20 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,7 @@ Opens a one-page modal to collect multiple inputs in one go. Values already pres
38
38
**Behavior:**
39
39
- Uses existing values for any ids that already exist in `variables` (including empty strings).
40
40
- Prompts only for missing (`undefined`/`null`) inputs.
41
+
- If the user closes the modal without submitting, the promise rejects with `MacroAbortError("Input cancelled by user")`.
41
42
42
43
**Field Types:**
43
44
-`text`: Single-line text input
@@ -115,18 +116,25 @@ Opens a prompt that asks for text input.
115
116
- `placeholder`: (Optional) Placeholder text in the input field
116
117
- `value`: (Optional) Default value
117
118
118
-
**Returns:** Promise resolving to the entered string, or `null` if cancelled
119
+
**Returns:** Promise resolving to the entered string.
120
+
121
+
**Cancellation:** If the user cancels or presses Escape, the promise rejects with `MacroAbortError("Input cancelled by user")`. Letting it bubble will stop the macro automatically. Catch it only if your script wants to handle the cancellation itself.
119
122
120
123
**Example:**
121
124
```javascript
122
-
constname=awaitquickAddApi.inputPrompt(
123
-
"What's your name?",
124
-
"Enter your full name",
125
-
"John Doe"
126
-
);
127
-
128
-
if (name) {
129
-
console.log(`Hello, ${name}!`);
125
+
try {
126
+
constname=awaitquickAddApi.inputPrompt(
127
+
"What's your name?",
128
+
"Enter your full name",
129
+
"John Doe"
130
+
);
131
+
console.log(`Hello, ${name}!`);
132
+
} catch (error) {
133
+
if (error?.name==="MacroAbortError") {
134
+
// Optional: perform cleanup before QuickAdd aborts the macro
135
+
return;
136
+
}
137
+
throw error;
130
138
}
131
139
```
132
140
@@ -135,7 +143,7 @@ Opens a wider prompt for longer text input (multi-line).
135
143
136
144
**Parameters:** Same as `inputPrompt`
137
145
138
-
**Returns:** Promise resolving to the entered string, or `null` if cancelled
146
+
**Returns:** Promise resolving to the entered string. Cancelling rejects with `MacroAbortError` (same as `inputPrompt`).
139
147
140
148
**Example:**
141
149
```javascript
@@ -153,7 +161,7 @@ Opens a confirmation dialog with Yes/No buttons.
153
161
- `header`: The dialog title
154
162
- `text`: (Optional) Additional explanation text
155
163
156
-
**Returns:** Promise resolving to `true` (Yes) or `false` (No)
164
+
**Returns:** Promise resolving to `true` (Yes) or `false` (No). If the user closes the dialog without answering, the promise rejects with `MacroAbortError`.
157
165
158
166
**Example:**
159
167
```javascript
@@ -196,7 +204,7 @@ Opens a selection prompt with searchable options. Can optionally allow custom in
196
204
- `allowCustomInput`: (Optional) When `true`, allows users to enter custom text not in `actualItems`. Defaults to `false`
197
205
- `options.renderItem`: (Optional) Custom renderer `(value, el) =>void` to control how each suggestion row is drawn
198
206
199
-
**Returns:** Promise resolving to the selected value or custom input, or `null` if cancelled
207
+
**Returns:** Promise resolving to the selected value or custom input. Cancelling rejects with `MacroAbortError`.
-You want to provide a custom message after catching a `MacroAbortError`
291
291
- Prerequisites not met (e.g., required plugin not installed)
292
292
293
+
Prompt cancellations already throw `MacroAbortError` and halt macros automatically, so only call `abort()` in those scenarios if you need to surface a custom message or you're stopping for a non-prompt reason.
294
+
293
295
**What happens when you call `abort()`:**
294
296
- Macro execution stops immediately
295
297
- A message is logged: "Macro execution aborted: [your message]"
296
298
- Remaining commands in the macro are skipped
297
299
- No error is thrown to the user
298
300
299
301
**QuickAdd API methods that can be cancelled:**
300
-
-`inputPrompt()` - Returns `undefined` if cancelled
301
-
-`wideInputPrompt()` - Returns `undefined` if cancelled
302
-
-`yesNoPrompt()` - Returns `undefined` if cancelled
303
-
-`suggester()` - Aborts macro if cancelled
304
-
-`checkboxPrompt()` - Returns `undefined` if cancelled
302
+
-`inputPrompt()`
303
+
-`wideInputPrompt()`
304
+
-`yesNoPrompt()`
305
+
-`suggester()`
306
+
-`checkboxPrompt()`
307
+
308
+
Each of these now rejects with `MacroAbortError("Input cancelled by user")` when the user presses Escape or closes the dialog. If you do nothing, the macro will automatically stop (matching user expectations). If you want to handle cancellation in your script, wrap the call in `try/catch` and intercept the error before it reaches the macro engine.
// Optional custom handling (e.g., cleanup) before the macro aborts
316
+
return;
317
+
}
318
+
throw error; // real errors should still bubble up
319
+
}
320
+
```
305
321
306
-
**Important:**When using the QuickAdd API, check for `undefined`to handle cancellations gracefully:
322
+
**Important:** Because cancellations now throw, you should only call `abort()` yourself when you want to provide a custom message or stop execution for a non-prompt reason.
0 commit comments