-
Notifications
You must be signed in to change notification settings - Fork 4
[ENG-606] Open the file as canvas view right when open #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENG-606] Open the file as canvas view right when open #573
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThe changes implement a deferred canvas view-switching mechanism for the Obsidian plugin. Instead of immediately switching canvas views on file-open, the system now marks files in a tracking set and defers the switch until the active leaf changes, improving coordination with canvas readiness. Changes
Sequence DiagramsequenceDiagram
participant User
participant FileOpen as File Open Event
participant PendingState as Pending Switches
participant LeafChange as Active Leaf Change Event
participant ViewMgr as View Manager
participant Canvas as Canvas Preview
User->>FileOpen: Opens Markdown file with canvas frontmatter
FileOpen->>PendingState: Mark file path in pendingCanvasSwitches
PendingState-->>FileOpen: Marked (deferred)
User->>LeafChange: Navigate/focus changes
LeafChange->>PendingState: Check if file has pending switch
alt Pending Switch Exists
PendingState->>ViewMgr: Confirm not already in canvas view
ViewMgr->>Canvas: Switch to VIEW_TYPE_TLDRAW_DG_PREVIEW
Canvas-->>ViewMgr: View switched
ViewMgr->>PendingState: Clear pending state
PendingState-->>LeafChange: Cleared
else No Pending Switch
PendingState-->>LeafChange: No action needed
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks✅ Passed checks (3 passed)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/obsidian/src/index.ts (1)
81-90:file-openhandler correctly scopes pending switches; consider clearing rare stale entriesThe
file-openhandler’s frontmatter check ensures only canvas‑enabled files are marked inpendingCanvasSwitches, which keeps the deferred logic focused and cheap. If you want to be extra defensive, you could also clear entries whose cache no longer hasFRONTMATTER_KEY(e.g., in the"active-leaf-change"path whenisCanvasFileis false) to avoid very rare cases where frontmatter is edited betweenfile-openand the next leaf change, leaving an entry that will never be consumed.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/obsidian/src/index.ts(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/main.mdc)
**/*.{ts,tsx}: Use Tailwind CSS for styling where possible
When refactoring inline styles, use tailwind classes
Prefertypeoverinterfacein TypeScript
Use explicit return types for functions
Avoidanytypes when possible
Prefer arrow functions over regular function declarations
Use named parameters (object destructuring) when a function has more than 2 parameters
Use PascalCase for components and types
Use camelCase for variables and functions
Use UPPERCASE for constants
Function names should describe their purpose clearly
Prefer early returns over nested conditionals for better readability
Files:
apps/obsidian/src/index.ts
apps/obsidian/**
📄 CodeRabbit inference engine (.cursor/rules/obsidian.mdc)
apps/obsidian/**: Prefer existing dependencies from apps/obsidian/package.json when adding dependencies to the Obsidian plugin
Follow the Obsidian style guide from help.obsidian.md/style-guide and docs.obsidian.md/Developer+policies for UI and code styling
Use Lucide and custom Obsidian icons alongside detailed elements to provide visual representation of features in platform-native UI
Files:
apps/obsidian/src/index.ts
🧬 Code graph analysis (1)
apps/obsidian/src/index.ts (1)
apps/obsidian/src/constants.ts (2)
FRONTMATTER_KEY(72-72)VIEW_TYPE_TLDRAW_DG_PREVIEW(79-79)
🔇 Additional comments (1)
apps/obsidian/src/index.ts (1)
28-76: Deferred canvas switching viapendingCanvasSwitcheslooks solid; confirm event orderingKeying
pendingCanvasSwitchesbyfile.pathand consuming it in the"active-leaf-change"handler (with theVIEW_TYPE_TLDRAW_DG_PREVIEWguard) is a clean way to avoid switching before the canvas view is ready and to prevent redundant switches on an already‑canvas leaf. One thing to verify manually is that in your target Obsidian version the"file-open"event fires before (or at least not strictly after) the corresponding"active-leaf-change"for a newly opened file, so that the pending entry is visible on that first leaf activation and the auto‑switch really happens “right when open” without requiring another leaf change.
aeb9285 to
6d2d1c4
Compare
https://www.loom.com/share/55f0fa6f11e047a6a638b06ad358ec10
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.