Refactor TODONT module with configurable hotkey and bulk archive#19
Refactor TODONT module with configurable hotkey and bulk archive#19salmonumbrella wants to merge 4 commits intoRoamJS:mainfrom
Conversation
When pressing Cmd/Ctrl+Enter on an ARCHIVED block, Roam prepends TODO to get TODO+ARCHIVED. This collapses that into just TODO. Also reads block text from Roam's data layer instead of the textarea DOM value, which can lag behind after API updates. Closes RoamJS#4
- Use .closest('.bp3-menu-item') for reliable context menu detection
instead of fragile parent element traversal
- Wrap keydown DONE/TODO detection in setTimeout to read block text
after Roam processes state changes, preventing stale reads
- Collect multi-select block UIDs before setTimeout to avoid race
conditions with DOM changes
- Add focusin/focusout tracking to detect manual DONE transitions
(blocks edited from non-TODO to DONE now fire onDone callbacks)
- Register cleanup for focus listeners on extension unload
Closes RoamJS#8, closes RoamJS#10
- Accept extensionAPI parameter, return { toggle, cleanup } for proper
lifecycle management
- Register Archive command via extensionAPI.ui.commandPalette.addCommand
with configurable hotkey (replaces raw keydown listener)
- Add archiveBlock helper using updateBlock for multi-select support
- Use CSS ::before pseudo-element for ARCHIVED button styling (keeps
text as "ARCHIVED" for accessibility, hides visually)
- Replace styleArchivedButtons with syncArchivedButton/syncArchivedButtons
pattern (handles added Text nodes, instanceof checks)
- Add null-safety guards for location in replaceText and
previousActiveElement
- Move TODONT Mode setting higher in settings panel
- Add settings caret style fix
- Guard Cmd/Ctrl+Shift+Enter in keydown (reserve for Archive command)
- Initialize default todont-mode if not set
- Add cleanupTodont() to extension unload
WalkthroughThe pull request refactors TODONT mode handling across three files. It introduces a new utility Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
| extensionAPI.ui.commandPalette.addCommand({ | ||
| label: ARCHIVE_COMMAND_LABEL, | ||
| callback: todontCallback, | ||
| defaultHotkey: defaultArchiveHotkey, | ||
| disableHotkey: false, | ||
| }); | ||
| unloads.add(() => { | ||
| extensionAPI.ui.commandPalette.removeCommand({ | ||
| label: ARCHIVE_COMMAND_LABEL, | ||
| }); | ||
| }); | ||
|
|
||
| if (todontMode === "off") { | ||
| return; | ||
| } |
There was a problem hiding this comment.
🚩 Command palette command is re-registered on every mode toggle
Each call to toggle() in src/utils/todont.ts:153-317 first calls cleanup() (which removes the command via removeCommand), then re-adds it via addCommand. This happens both on initialization and whenever the user changes the TODONT mode in settings. The command (with its hotkey) is registered even in "off" mode — only the visual styling (CSS, mutation observer) is mode-dependent. This means the archive hotkey (Cmd/Ctrl+Shift+Enter) is always available regardless of the TODONT mode setting, which may or may not be the intended UX. Worth confirming this is desired behavior.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
extensionAPI.ui.commandPalette.addCommandwith configurable default hotkey (replaces raw keydown listener)archiveBlockhelper usingupdateBlockfor multi-select support (Cmd/Ctrl+Shift+Enter on multi-selected blocks)::beforepseudo-element for ARCHIVED button styling (keeps text as "ARCHIVED" for accessibility, hides visually)styleArchivedButtonswithsyncArchivedButton/syncArchivedButtonspattern (handles added Text nodes, instanceof checks)locationinreplaceTextandpreviousActiveElementcleanupTodont, settings caret style)PR19.for.Droidian.mp4
Test plan
Closes #16
Summary by CodeRabbit
New Features
Improvements