Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ require('opencode').setup({
},
},
ui = {
enable_treesitter_markdown = true, -- Use Treesitter for markdown rendering in the output window (default: true).
position = 'right', -- 'right' (default), 'left' or 'current'. Position of the UI split. 'current' uses the current window for the output.
input_position = 'bottom', -- 'bottom' (default) or 'top'. Position of the input window
window_width = 0.40, -- Width as percentage of editor width
Expand Down Expand Up @@ -636,6 +637,7 @@ The plugin provides the following actions that can be triggered via keymaps, com
- `open_input` (boolean, default: `true`): Whether to open the input window after adding the selection. Set to `false` to add selection silently without changing focus.

Example keymap for silent add:

```lua
['<leader>oY'] = { 'add_visual_selection', { open_input = false }, mode = {'v'} }
```
Expand Down
1 change: 1 addition & 0 deletions lua/opencode/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ M.defaults = {
},
},
ui = {
enable_treesitter_markdown = true,
position = 'right',
input_position = 'bottom',
window_width = 0.40,
Expand Down
1 change: 1 addition & 0 deletions lua/opencode/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
---@field frames string[]

---@class OpencodeUIConfig
---@field enable_treesitter_markdown boolean
---@field position 'right'|'left'|'current' # Position of the UI (default: 'right')
---@field input_position 'bottom'|'top' # Position of the input window (default: 'bottom')
---@field window_width number
Expand Down
25 changes: 17 additions & 8 deletions lua/opencode/ui/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ local function capture_hidden_snapshot(windows)
output_view = ok and type(view) == 'table' and view or nil,
focused_window = focused,
position = config.ui.position,
owner_tab = state.are_windows_in_current_tab()
and vim.api.nvim_get_current_tabpage() or nil,
owner_tab = state.are_windows_in_current_tab() and vim.api.nvim_get_current_tabpage() or nil,
}
end

Expand All @@ -92,8 +91,12 @@ function M.close_windows(windows, persist)
end

local function prepare_window_close()
if M.is_opencode_focused() then M.return_to_last_code_win() end
if state.display_route then state.display_route = nil end
if M.is_opencode_focused() then
M.return_to_last_code_win()
end
if state.display_route then
state.display_route = nil
end

pcall(vim.api.nvim_del_augroup_by_name, 'OpencodeResize')
pcall(vim.api.nvim_del_augroup_by_name, 'OpencodeWindows')
Expand Down Expand Up @@ -145,7 +148,9 @@ function M.hide_visible_windows(windows)
end
if windows.input_buf and vim.api.nvim_buf_is_valid(windows.input_buf) then
local ok, lines = pcall(vim.api.nvim_buf_get_lines, windows.input_buf, 0, -1, false)
if ok then state.input_content = lines end
if ok then
state.input_content = lines
end
end
state.stash_hidden_buffers(snapshot)
if state.windows == windows then
Expand Down Expand Up @@ -242,7 +247,9 @@ function M.restore_hidden_windows()

vim.schedule(function()
local w = state.windows
if not w then return end
if not w then
return
end

if hidden.output_was_at_bottom then
renderer.scroll_to_bottom(true)
Expand Down Expand Up @@ -323,8 +330,10 @@ function M.create_split_windows(input_buf, output_buf)
end

function M.create_windows()
vim.treesitter.language.register('markdown', 'opencode_output')
vim.treesitter.language.register('markdown', 'opencode')
if config.ui.enable_treesitter_markdown then
vim.treesitter.language.register('markdown', 'opencode_output')
vim.treesitter.language.register('markdown', 'opencode')
end

local autocmds = require('opencode.ui.autocmds')

Expand Down