Configurable location for OpenCode: sidebar or main window

This commit is contained in:
Mateusz Tymek
2026-01-10 16:00:13 +01:00
parent b8081e70fa
commit 30953b3176
8 changed files with 157 additions and 18 deletions

View File

@@ -0,0 +1,14 @@
# Change: Add Default View Location Setting
## Why
Users may prefer to have the OpenCode panel open in the main editor area instead of the sidebar, depending on their workflow and screen size. Currently, the view always opens in the right sidebar with no option to change this behavior.
## What Changes
- Add a new `defaultViewLocation` setting with options: `"sidebar"` or `"main"`
- Update view activation logic to respect this setting when opening the panel
- Sidebar opens in the right leaf (current behavior)
- Main opens in a new tab in the main editor area
## Impact
- Affected specs: `001-mvp-opencode-embed` (Settings Configuration, Sidebar View Registration, Ribbon Icon)
- Affected code: `src/types.ts`, `src/main.ts`, `src/SettingsTab.ts`

View File

@@ -0,0 +1,36 @@
## MODIFIED Requirements
### Requirement: Settings Configuration
The plugin SHALL provide configurable settings for server port, hostname, executable path, project directory, auto-start behavior, and default view location.
#### Scenario: Settings persistence
- **WHEN** the user modifies settings
- **THEN** changes are persisted to plugin data
- **AND** the process manager is updated with new settings
#### Scenario: Default view location options
- **WHEN** the user configures default view location
- **THEN** the options available are "sidebar" and "main"
- **AND** the default value is "sidebar"
### Requirement: Sidebar View Registration
The plugin SHALL register an ItemView that displays in either the Obsidian sidebar or main editor area based on user settings.
#### Scenario: View activation in sidebar
- **WHEN** the user clicks the ribbon icon or runs the toggle command
- **AND** the default view location is set to "sidebar"
- **THEN** the OpenCode view opens in the right sidebar
- **AND** if the view already exists, it is revealed
#### Scenario: View activation in main area
- **WHEN** the user clicks the ribbon icon or runs the toggle command
- **AND** the default view location is set to "main"
- **THEN** the OpenCode view opens as a new tab in the main editor area
- **AND** if the view already exists in any location, it is revealed
### Requirement: Ribbon Icon
The plugin SHALL add a ribbon icon that activates the OpenCode view in the configured default location.
#### Scenario: Ribbon icon click
- **WHEN** the user clicks the OpenCode ribbon icon
- **THEN** the OpenCode view is activated in the location specified by the default view location setting

View File

@@ -0,0 +1,23 @@
## 1. Implementation
- [ ] 1.1 Add `defaultViewLocation` type and setting to `src/types.ts`
- Add type: `"sidebar" | "main"`
- Add to `OpenCodeSettings` interface
- Add default value `"sidebar"` to `DEFAULT_SETTINGS`
- [ ] 1.2 Update `src/main.ts` view activation logic
- Modify `activateView()` method to check `defaultViewLocation` setting
- For "sidebar": use `getLeaf("right")` (existing behavior)
- For "main": use `getLeaf("tab")` to open in main editor area
- Ensure existing view detection works for both locations
- [ ] 1.3 Add setting UI to `src/SettingsTab.ts`
- Add dropdown setting for "Default view location"
- Options: "Sidebar" and "Main window"
- Description explaining the behavior difference
- [ ] 1.4 Test the feature
- Verify sidebar mode opens in right sidebar
- Verify main mode opens as a tab in editor area
- Verify toggling reveals existing view regardless of location
- Verify setting persists across plugin reload

View File

@@ -45,13 +45,20 @@ The plugin SHALL maintain a state machine with states: stopped, starting, runnin
- **THEN** the state transitions to `error`
### Requirement: Sidebar View Registration
The plugin SHALL register an ItemView that displays in the Obsidian sidebar.
The plugin SHALL register an ItemView that displays in either the Obsidian sidebar or main editor area based on user settings.
#### Scenario: View activation
#### Scenario: View activation in sidebar
- **WHEN** the user clicks the ribbon icon or runs the toggle command
- **AND** the default view location is set to "sidebar"
- **THEN** the OpenCode view opens in the right sidebar
- **AND** if the view already exists, it is revealed
#### Scenario: View activation in main area
- **WHEN** the user clicks the ribbon icon or runs the toggle command
- **AND** the default view location is set to "main"
- **THEN** the OpenCode view opens as a new tab in the main editor area
- **AND** if the view already exists in any location, it is revealed
### Requirement: View State Rendering
The plugin SHALL render different UI content based on the current process state.
@@ -89,13 +96,18 @@ The plugin SHALL start the server automatically when the view is opened if not a
- **THEN** the plugin initiates server start
### Requirement: Settings Configuration
The plugin SHALL provide configurable settings for server port, hostname, executable path, project directory, and auto-start behavior.
The plugin SHALL provide configurable settings for server port, hostname, executable path, project directory, auto-start behavior, and default view location.
#### Scenario: Settings persistence
- **WHEN** the user modifies settings
- **THEN** changes are persisted to plugin data
- **AND** the process manager is updated with new settings
#### Scenario: Default view location options
- **WHEN** the user configures default view location
- **THEN** the options available are "sidebar" and "main"
- **AND** the default value is "sidebar"
### Requirement: Project Directory Validation
The plugin SHALL validate the project directory setting and support tilde expansion.
@@ -131,8 +143,8 @@ The plugin SHALL register commands for toggling the view and controlling the ser
- **THEN** the server stops
### Requirement: Ribbon Icon
The plugin SHALL add a ribbon icon that activates the OpenCode view.
The plugin SHALL add a ribbon icon that activates the OpenCode view in the configured default location.
#### Scenario: Ribbon icon click
- **WHEN** the user clicks the OpenCode ribbon icon
- **THEN** the OpenCode view is activated in the right sidebar
- **THEN** the OpenCode view is activated in the location specified by the default view location setting