ENG-1438: Port Keyboard shortcut keys/triggers settings#794
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
6272ec7 to
fdb14fe
Compare
fdb14fe to
179b9e3
Compare
d1168f9 to
ac0a069
Compare
ac0a069 to
547a44d
Compare
1be546e to
f4cc95b
Compare
01ef4ec to
8c85845
Compare
f4cc95b to
75bb8c1
Compare
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThe pull request refactors keyboard shortcut handling to use a structured data format with modifiers and key properties instead of plain strings, adds persistence of shortcuts via personal settings storage, and centralizes shortcut string generation through a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
apps/roam/src/components/settings/utils/zodSchema.ts (1)
233-242: Asymmetric schema for the two shortcut fields — is the union on"Personal node menu trigger"intentional?
"Personal node menu trigger"acceptsz.union([object, z.literal("")])while"Discourse tool shortcut"only accepts the object shape. This means consumers of"Personal node menu trigger"must do a type-narrowing check (typeof value === "string") before accessing.modifiers/.key, which is easy to miss and could cause runtime errors.If the empty-string variant is for backward compatibility with previously stored string values, consider using
.transform()to normalize""into{ modifiers: 0, key: "" }at parse time so the output type is always uniform. If this asymmetry is intentional (the two fields genuinely have different semantics), a brief comment explaining why would help future readers.Example normalization
"Personal node menu trigger": z .union([ z.object({ modifiers: z.number(), key: z.string() }), z.literal(""), ]) - .default({ modifiers: 0, key: "" }), + .default({ modifiers: 0, key: "" }) + .transform((val) => (val === "" ? { modifiers: 0, key: "" } : val)),This way the inferred type is always
{ modifiers: number; key: string }, matching"Discourse tool shortcut".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/roam/src/components/settings/utils/zodSchema.ts` around lines 233 - 242, The "Personal node menu trigger" schema currently uses z.union([z.object(...), z.literal("")]) which produces an inconsistent output type vs the "Discourse tool shortcut" object; change the schema so the parsed output is always the object shape (matching "Discourse tool shortcut") by handling the empty-string legacy case with a transform or preprocess: accept the union but .transform() (or z.preprocess) to map "" to { modifiers: 0, key: "" } so downstream consumers of "Personal node menu trigger" can safely access .modifiers and .key without type-narrowing; alternatively make both schemas identical objects if no legacy string values must be supported, and add a short comment explaining the chosen approach.apps/roam/src/components/DiscourseNodeMenu.tsx (1)
410-415: Consider extractingcomboToString(and related helpers) to a shared utility file.
comboToString,getModifiersFromCombo,normalizeKeyCombo, and the modifier/alias constants are pure utility logic with no component dependencies. Exporting them fromDiscourseNodeMenu.tsxforcesKeyboardShortcutInput.tsx(a settings component) to import from a menu component, creating an awkward cross-concern coupling.Moving these to e.g.
~/utils/keyComboUtils.tswould improve module boundaries and make it easier to reuse across additional settings components.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/roam/src/components/DiscourseNodeMenu.tsx` around lines 410 - 415, Extract the pure utility logic from DiscourseNodeMenu.tsx into a shared module (e.g., create ~/utils/keyComboUtils.ts): move comboToString, getModifiersFromCombo, normalizeKeyCombo and the modifier/alias constants into that file and export them, then update DiscourseNodeMenu.tsx and KeyboardShortcutInput.tsx to import these helpers from the new utils module; ensure exports keep the same names/signatures so no other call sites need changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/roam/src/components/DiscourseNodeMenu.tsx`:
- Around line 460-464: The onClick clear handler uses an empty string "" for
extensionAPI.settings.set and setPersonalSetting but elsewhere
(KeyboardShortcutInput.handleClear) clears with the structured object {
modifiers: 0, key: "" }, causing validation and type inconsistencies; update the
onClick handler to persist the same structured object ({ modifiers: 0, key: ""
}) to extensionAPI.settings.set and setPersonalSetting and keep setComboKey({
modifiers: 0, key: "" }) so the clear behavior is consistent with
KeyboardShortcutInput.handleClear.
In `@apps/roam/src/components/DiscourseNodeSearchMenu.tsx`:
- Around line 631-632: The code writes the trigger to two different keys
(extensionAPI.settings.set("node-search-trigger", ...) and
setPersonalSetting(["Node search menu trigger"], ...)) while reads only use
getSetting("node-search-trigger", "@"), risking divergence; fix by consolidating
to a single canonical store: remove the redundant setPersonalSetting call and
persist only via extensionAPI.settings.set("node-search-trigger", trigger), or
if you must keep both, update read logic (where
getSetting("node-search-trigger", "@") is used) to also read and merge the
personal setting with a clear precedence. Ensure references to
setPersonalSetting and extensionAPI.settings.set are consistent and update any
docs/tests accordingly.
---
Nitpick comments:
In `@apps/roam/src/components/DiscourseNodeMenu.tsx`:
- Around line 410-415: Extract the pure utility logic from DiscourseNodeMenu.tsx
into a shared module (e.g., create ~/utils/keyComboUtils.ts): move
comboToString, getModifiersFromCombo, normalizeKeyCombo and the modifier/alias
constants into that file and export them, then update DiscourseNodeMenu.tsx and
KeyboardShortcutInput.tsx to import these helpers from the new utils module;
ensure exports keep the same names/signatures so no other call sites need
changes.
In `@apps/roam/src/components/settings/utils/zodSchema.ts`:
- Around line 233-242: The "Personal node menu trigger" schema currently uses
z.union([z.object(...), z.literal("")]) which produces an inconsistent output
type vs the "Discourse tool shortcut" object; change the schema so the parsed
output is always the object shape (matching "Discourse tool shortcut") by
handling the empty-string legacy case with a transform or preprocess: accept the
union but .transform() (or z.preprocess) to map "" to { modifiers: 0, key: "" }
so downstream consumers of "Personal node menu trigger" can safely access
.modifiers and .key without type-narrowing; alternatively make both schemas
identical objects if no legacy string values must be supported, and add a short
comment explaining the chosen approach.
mdroidian
left a comment
There was a problem hiding this comment.
Let's go!
One devin comment worth looking into. Can defer, not blocking.
d9a05d4
into
eng-1217-page-groups-left-sidebar

https://www.loom.com/share/c49cc82577c847368c521e0a7680fc5e
Summary by CodeRabbit