Skip to content

Fix view location setting not being respected#53

Open
growlf wants to merge 2 commits into
mtymek:mainfrom
growlf:fix/view-location-setting
Open

Fix view location setting not being respected#53
growlf wants to merge 2 commits into
mtymek:mainfrom
growlf:fix/view-location-setting

Conversation

@growlf
Copy link
Copy Markdown

@growlf growlf commented May 4, 2026

Summary

Fixes issue where the `defaultViewLocation` setting (sidebar vs main window) is not respected when:

  • Clicking the ribbon icon or using the toggle command
  • Obsidian restores the workspace from `workspace.json`

Changes Made

1. `src/ui/ViewManager.ts`

  • Modified `activateView()` to check if existing view is in the correct location
  • If view exists but in wrong location (e.g., sidebar when "main" is set), detach and recreate in correct location

2. `src/main.ts`

  • Added `fixViewLocation()` method that runs after workspace layout is restored
  • Checks if restored view is in correct location per settings
  • If not, detaches the view and recreates it in the correct location (sidebar vs main tab)
  • Added 100ms delay to ensure workspace is fully restored before checking

How to Test

  1. Set "Default view location" to "Main window" in settings
  2. Restart Obsidian
  3. Click the OpenCode icon - should open in new tab, not sidebar
  4. Toggle with Ctrl+Shift+O - should open/close in main area

Related Issue

Fixes behavior where `workspace.json` restores view to sidebar regardless of settings.


Note: This PR is a draft for review. Changes are from a fork at `growlf/opencode-obsidian`.

- Check if existing view is in correct location before revealing
- Add fixViewLocation() method to correct workspace restoration
- Detach and recreate view if in wrong location (sidebar vs main)
- Fixes issue where workspace.json restores view to wrong location
@growlf
Copy link
Copy Markdown
Author

growlf commented May 4, 2026

Side note: this PR was generated (with opencode) while using the plugin with Obsidian as the tool to both test and resolve the issue.

@growlf growlf marked this pull request as ready for review May 4, 2026 19:30
- Added comments to fixViewLocation() explaining the workspace.json bug
- Added comments to activateView() explaining why we check location before reveal
- Added comments to onLayoutReady() explaining the 100ms delay
- Documents the problem: Obsidian ignores user settings when restoring workspace
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.

1 participant