Skip to content

Refactor TODONT module with configurable hotkey and bulk archive#19

Open
salmonumbrella wants to merge 4 commits intoRoamJS:mainfrom
salmonumbrella:feat/todont-refactor
Open

Refactor TODONT module with configurable hotkey and bulk archive#19
salmonumbrella wants to merge 4 commits intoRoamJS:mainfrom
salmonumbrella:feat/todont-refactor

Conversation

@salmonumbrella
Copy link
Copy Markdown

@salmonumbrella salmonumbrella commented Feb 28, 2026

Summary

  • Register Archive command via extensionAPI.ui.commandPalette.addCommand with configurable default hotkey (replaces raw keydown listener)
  • Add archiveBlock helper using updateBlock for multi-select support (Cmd/Ctrl+Shift+Enter on multi-selected blocks)
  • 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 for discoverability
  • Guard Cmd/Ctrl+Shift+Enter in keydown handler (reserve for Archive command)
  • Proper cleanup on extension unload (cleanupTodont, settings caret style)

Stacked PR — depends on #17 and #18. Merge those first; this PR's diff will auto-update to show only its own changes.

PR19.for.Droidian.mp4

Test plan

  • Cmd/Ctrl+Shift+Enter on a TODO block → becomes ARCHIVED
  • Cmd/Ctrl+Shift+Enter on a DONE block → becomes ARCHIVED
  • Cmd/Ctrl+Shift+Enter on an ARCHIVED block → ARCHIVED removed
  • Select multiple blocks → Cmd/Ctrl+Shift+Enter → all toggle to ARCHIVED
  • Change hotkey in Roam command palette → new hotkey works
  • Toggle TODONT mode (off / icon / strikethrough) → styling updates live
  • Unload extension → no stale listeners, styles, or commands remain

Closes #16

Summary by CodeRabbit

  • New Features

    • Added TODONT Mode setting in the extension UI for customizing styling behavior.
  • Improvements

    • Enhanced state handling for TODO and ARCHIVED blocks with automatic prefix normalization.
    • Improved keyboard (Enter/Ctrl+Enter) and menu-based state transitions.
    • Better per-block edit state tracking to detect completion more accurately.
    • Improved cleanup and resource management on extension unload.

Open with Devin

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
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 28, 2026

Walkthrough

The pull request refactors TODONT mode handling across three files. It introduces a new utility normalizeTodoArchivedPrefix that strips archived prefixes from TODO blocks. The main entry point (src/index.ts) is reworked to initialize TODONT mode with a default "icon" setting, manage per-block edit state via focusin/focusout listeners, introduce a dynamic style element for caret orientation, and implement keyboard/click handling with intentional delays to read Roam's data layer before state transitions. The todont.ts utility is restructured to accept extensionAPI as a parameter and return an object with toggle and cleanup methods, integrating command palette registration and block archival logic with enhanced UI synchronization.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: refactoring TODONT module to support configurable hotkey and bulk archive functionality.
Linked Issues check ✅ Passed The pull request implements all coding requirements from issue #16: extensionAPI parameter, { toggle, cleanup } return object, command palette registration, archiveBlock helper, ::before styling, null-safety guards, and cleanup logic.
Out of Scope Changes check ✅ Passed All changes are directly related to the TODONT refactoring objectives. Changes include new utility module (normalizeTodoArchivedPrefix), TODONT module refactor (initializeTodont signature, command registration, archiveBlock), and main index.ts updates for integration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mdroidian
Copy link
Copy Markdown
Contributor

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 11, 2026

✅ Actions performed

Full review triggered.

coderabbitai[bot]

This comment was marked as resolved.

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

Comment on lines +167 to +181
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;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor TODONT module with configurable hotkey and bulk archive

2 participants