Skip to content

Commit

Permalink
feat: add win_options to preview_win (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter authored Nov 12, 2024
1 parent c23fe08 commit bbeed86
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ local default_config = {
update_on_cursor_moved = true,
-- Maximum file size in megabytes to preview
max_file_size_mb = 100,
-- Window-local options to use for preview window buffers
win_options = {},
},
-- Configuration for the floating action confirmation window
confirmation = {
Expand Down Expand Up @@ -326,12 +328,14 @@ local M = {}
---@class (exact) oil.PreviewWindowConfig
---@field update_on_cursor_moved boolean
---@field max_file_size_mb number
---@field win_options table<string, any>

---@class (exact) oil.ConfirmationWindowConfig : oil.WindowConfig

---@class (exact) oil.SetupPreviewWindowConfig
---@field update_on_cursor_moved? boolean Whether the preview window is automatically updated when the cursor is moved
---@field max_file_size_mb? number Maximum file size in megabytes to preview
---@field win_options? table<string, any> Window-local options to use for preview window buffers

---@class (exact) oil.SetupConfirmationWindowConfig : oil.SetupWindowConfig

Expand Down
3 changes: 3 additions & 0 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ M.open_preview = function(opts, callback)
end

vim.api.nvim_set_option_value("previewwindow", true, { scope = "local", win = 0 })
for k, v in pairs(config.preview_win.win_options) do
vim.api.nvim_set_option_value(k, v, { scope = "local", win = preview_win })
end
vim.w.oil_entry_id = entry.id
vim.w.oil_source_win = prev_win
if is_visual_mode then
Expand Down
5 changes: 5 additions & 0 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ M.set_win_options = function()
for k, v in pairs(config.win_options) do
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid })
end
if vim.wo[winid].previewwindow then -- apply preview window options last
for k, v in pairs(config.preview_win.win_options) do
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid })
end
end
end

---Get a list of visible oil buffers and a list of hidden oil buffers
Expand Down

0 comments on commit bbeed86

Please sign in to comment.