(action, value)
| 201 | * @returns {boolean} Whether the action was performed |
| 202 | */ |
| 203 | export default function actions(action, value) { |
| 204 | setQuicktoolsUsed(); |
| 205 | |
| 206 | const { editor } = editorManager; |
| 207 | const { $input, $replaceInput } = quickTools; |
| 208 | |
| 209 | if (Object.keys(state).includes(action)) { |
| 210 | setInput(); |
| 211 | value = !state[action]; |
| 212 | state[action] = value; |
| 213 | events[action].forEach((cb) => cb(value)); |
| 214 | if (Object.values(state).includes(true)) { |
| 215 | $input.focus(); |
| 216 | } else if (input) { |
| 217 | input.focus(); |
| 218 | } else { |
| 219 | $input.blur(); |
| 220 | } |
| 221 | |
| 222 | return value; |
| 223 | } |
| 224 | |
| 225 | switch (action) { |
| 226 | case "insert": |
| 227 | return insertText(value); |
| 228 | |
| 229 | case "command": { |
| 230 | const commandName = |
| 231 | typeof value === "string" ? value : String(value ?? ""); |
| 232 | if (!commandName) return false; |
| 233 | return executeCommand(commandName, editor); |
| 234 | } |
| 235 | |
| 236 | case "key": { |
| 237 | value = Number.parseInt(value, 10); |
| 238 | if (value < 37 || value > 40) { |
| 239 | resetKeys(); |
| 240 | } |
| 241 | setInput(); |
| 242 | getInput().dispatchEvent( |
| 243 | KeyboardEvent("keydown", getKeys({ keyCode: value })), |
| 244 | ); |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | case "search": |
| 249 | toggleSearch(); |
| 250 | return actionStack.has("search-bar"); |
| 251 | |
| 252 | case "toggle": |
| 253 | toggle(); |
| 254 | return true; |
| 255 | |
| 256 | case "set-height": |
| 257 | if (typeof value === "object") { |
| 258 | setHeight(value.height, value.save); |
| 259 | } else { |
| 260 | setHeight(value); |
no test coverage detected