(plugin: ReactRNPlugin, powerup: string)
| 37 | user; on confirm, apply to the parent instead. (Applied to the current |
| 38 | card itself these would make the card vanish — almost always wrong.) |
| 39 | - For all other powerups → apply directly to the current card. |
| 40 | 2. If invoked outside the queue → apply to the editor selection. */ |
| 41 | async function runAddPowerupCommand(plugin: ReactRNPlugin, powerup: string) { |
| 42 | const url = await plugin.window.getURL(); |
| 43 | const currentCard = await plugin.queue.getCurrentCard(); |
| 44 | const sel = await plugin.editor.getSelection(); |
| 45 | const selType = sel?.type; |
| 46 | |
| 47 | if (url.includes('/flashcards') && currentCard) { |
| 48 | let isTargetingCurrentCard = false; |
| 49 | if (!selType) { |
| 50 | isTargetingCurrentCard = true; |
| 51 | } else if (selType === SelectionType.Rem && sel.remIds.includes(currentCard.remId)) { |
| 52 | isTargetingCurrentCard = true; |
| 53 | } else if (selType === SelectionType.Text && sel.remId === currentCard.remId) { |
| 54 | isTargetingCurrentCard = true; |
| 55 | } |
| 56 | |
| 57 | if (isTargetingCurrentCard) { |
| 58 | if (SELF_HIDING_POWERUPS.has(powerup)) { |
| 59 | const powerupName = POWERUP_DISPLAY_NAMES[powerup]; |
| 60 | const userConfirmed = window.confirm( |
| 61 | `Warning: "${powerupName}" is meant for parent/ancestor Rems, not the flashcard directly.\n\n` + |
| 62 | `Click "OK" to navigate to the parent Rem and apply the powerup there, or "Cancel" to abort.\n\n` + |
| 63 | `Consider these alternatives if you want to affect ONLY this flashcard, not other descendants from the same ancestor:\n` + |
| 64 | ` "Hide Parent" / "Hide Grandparent"\n` + |
| 65 | ` "Remove Parent" / "Remove Grandparent"\n\n` |
| 66 | ); |
| 67 | if (userConfirmed) { |
| 68 | const rem = await plugin.rem.findOne(currentCard.remId); |
| 69 | const parent = await rem?.getParentRem(); |
| 70 | if (parent) { |
| 71 | await parent.addPowerup(powerup); |
| 72 | await plugin.app.toast(`Applied "${powerupName}" to parent.`); |
| 73 | } else { |
| 74 | await plugin.app.toast('Could not find a parent Rem.'); |
| 75 | } |
| 76 | } |
| 77 | } else { |
| 78 | const rem = await plugin.rem.findOne(currentCard.remId); |
| 79 | await rem?.addPowerup(powerup); |
| 80 | await plugin.app.toast( |
| 81 | 'Powerup added (will take effect next time you see this card).' |
| 82 | ); |
| 83 | } |
| 84 | return; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // Outside the queue: apply to editor selection. |
| 89 | if (!selType) return; |
| 90 | if (selType === SelectionType.Rem) { |
| 91 | const rems = (await plugin.rem.findMany(sel.remIds)) || []; |
| 92 | rems.forEach((r) => r.addPowerup(powerup)); |
| 93 | } else { |
| 94 | const rem = await plugin.rem.findOne(sel.remId); |
| 95 | rem?.addPowerup(powerup); |
| 96 | } |
no outgoing calls
no test coverage detected