Fix BLOCKMENTIONSDATED parsing, hotkey add behavior, and FORM focus handling#149
Fix BLOCKMENTIONSDATED parsing, hotkey add behavior, and FORM focus handling#149salmonumbrella wants to merge 8 commits intoRoamJS:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WalkthroughThe PR addresses issues with BLOCKMENTIONSDATED command date handling and hotkey entry creation. Two new utility modules are introduced: Estimated code review effort🎯 3 (Moderate) | ⏱️ ~40 minutes 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/HotKeyPanel.tsx`:
- Around line 160-169: The callback passed to setKeys calls
getNextAvailableHotKey which can throw and crash React; wrap the call to
getNextAvailableHotKey in a try/catch inside the setKeys updater (the function
that currently builds newKeys and calls extensionAPI.settings.set) and on error
do not throw—show a user-friendly notification (or toast) and return currentKeys
unchanged so state and settings are not mutated; only call
extensionAPI.settings.set("hot-keys", newKeys) when getNextAvailableHotKey
succeeds. Ensure you reference getNextAvailableHotKey, setKeys,
extensionAPI.settings.set, and randomWorkflow.uid when locating the code.
🧹 Nitpick comments (2)
src/HotKeyPanel.tsx (1)
55-69: Side effects inside React state updaters.Calling
extensionAPI.settings.set(...)insidesetKeys(currentKeys => {...})is a side effect inside a state updater, which React expects to be pure. This pattern is repeated inonKeyDown(Line 67),onItemSelect(Line 86),delete(Line 104), andAdd Hot Key(Line 167). While it works correctly in practice, if React ever double-invokes the updater (e.g., StrictMode), the settings call would fire twice. If this isn't a concern today, it's fine to leave as-is.src/utils/core.ts (1)
2805-2818: Verify thefinalTextinsertion logic handles the suffix correctly throughtextPostProcess.The new approach implicitly preserves the suffix (from the original block text) because
textPostProcess=getTextByBlockUid(uid)already containsprefix + suffixfrom the earlierupdateBlockon Line 2770–2773. The insertion point (indexDiffered) naturally splits around where the suffix begins. This is correct but subtler than the previous approach.Note:
props.suffix(set at Line 2776) appears to be unused now — it can be cleaned up.
| setKeys((currentKeys) => { | ||
| const nextHotkey = getNextAvailableHotKey(currentKeys); | ||
| const newKeys = Object.fromEntries( | ||
| Object.entries(currentKeys).concat([ | ||
| [nextHotkey, randomWorkflow.uid], | ||
| ]) | ||
| ); | ||
| extensionAPI.settings.set("hot-keys", newKeys); | ||
| return newKeys; | ||
| }); |
There was a problem hiding this comment.
getNextAvailableHotKey can throw inside a state updater, which may crash the component.
If all 144 hotkey combinations are exhausted, getNextAvailableHotKey throws. Since this throw occurs inside the setKeys callback (a React state updater), React will propagate it as an unhandled error, potentially unmounting the component tree. Consider catching the error and showing a user-friendly notification instead.
🛡️ Proposed fix
setKeys((currentKeys) => {
+ let nextHotkey: string;
+ try {
+ nextHotkey = getNextAvailableHotKey(currentKeys);
+ } catch {
+ // All combinations exhausted — return state unchanged
+ return currentKeys;
+ }
- const nextHotkey = getNextAvailableHotKey(currentKeys);
const newKeys = Object.fromEntries(
Object.entries(currentKeys).concat([
[nextHotkey, randomWorkflow.uid],
])
);
extensionAPI.settings.set("hot-keys", newKeys);
return newKeys;
});📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| setKeys((currentKeys) => { | |
| const nextHotkey = getNextAvailableHotKey(currentKeys); | |
| const newKeys = Object.fromEntries( | |
| Object.entries(currentKeys).concat([ | |
| [nextHotkey, randomWorkflow.uid], | |
| ]) | |
| ); | |
| extensionAPI.settings.set("hot-keys", newKeys); | |
| return newKeys; | |
| }); | |
| setKeys((currentKeys) => { | |
| let nextHotkey: string; | |
| try { | |
| nextHotkey = getNextAvailableHotKey(currentKeys); | |
| } catch { | |
| // All combinations exhausted — return state unchanged | |
| return currentKeys; | |
| } | |
| const newKeys = Object.fromEntries( | |
| Object.entries(currentKeys).concat([ | |
| [nextHotkey, randomWorkflow.uid], | |
| ]) | |
| ); | |
| extensionAPI.settings.set("hot-keys", newKeys); | |
| return newKeys; | |
| }); |
🤖 Prompt for AI Agents
In `@src/HotKeyPanel.tsx` around lines 160 - 169, The callback passed to setKeys
calls getNextAvailableHotKey which can throw and crash React; wrap the call to
getNextAvailableHotKey in a try/catch inside the setKeys updater (the function
that currently builds newKeys and calls extensionAPI.settings.set) and on error
do not throw—show a user-friendly notification (or toast) and return currentKeys
unchanged so state and settings are not mutated; only call
extensionAPI.settings.set("hot-keys", newKeys) when getNextAvailableHotKey
succeeds. Ensure you reference getNextAvailableHotKey, setKeys,
extensionAPI.settings.set, and randomWorkflow.uid when locating the code.
|
Hi — thank you for putting this together. I appreciate the effort here. We just added a formal contributing guide, so this likely wasn’t visible when you started the PR. Going forward, we’re trying to standardize reviews around it to keep things manageable: https://github.com/RoamJS/contributing/blob/main/contributing.md A couple adjustments are needed before this can move forward:
PRs that touch multiple concerns are significantly harder to review, and I have limited bandwidth right now. Following the guide helps ensure contributions can be reviewed and merged much more quickly. Once this is split up and the Loom is added, I’ll be happy to take a look. |
Summary
BLOCKMENTIONSDATEDdate argument parsing for comma-containing dates and normalizefirst of ...date phrasescontrol+o%FORM%dialog focus to reduce keyboard-input method issues in form workflowsStream Output+Stream Delay) and thread it through trigger pathsBREADCRUMBSpage-only/parents-only prefixes in command helpresearch.mdIssue Links
Validation
npm test(12 passed)Summary by CodeRabbit
Release Notes
New Features
Improvements