Skip to content

Commit bbeed86

Browse files
authored
feat: add win_options to preview_win (#514)
1 parent c23fe08 commit bbeed86

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lua/oil/config.lua

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ local default_config = {
143143
update_on_cursor_moved = true,
144144
-- Maximum file size in megabytes to preview
145145
max_file_size_mb = 100,
146+
-- Window-local options to use for preview window buffers
147+
win_options = {},
146148
},
147149
-- Configuration for the floating action confirmation window
148150
confirmation = {
@@ -326,12 +328,14 @@ local M = {}
326328
---@class (exact) oil.PreviewWindowConfig
327329
---@field update_on_cursor_moved boolean
328330
---@field max_file_size_mb number
331+
---@field win_options table<string, any>
329332

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

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

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

lua/oil/init.lua

+3
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ M.open_preview = function(opts, callback)
551551
end
552552

553553
vim.api.nvim_set_option_value("previewwindow", true, { scope = "local", win = 0 })
554+
for k, v in pairs(config.preview_win.win_options) do
555+
vim.api.nvim_set_option_value(k, v, { scope = "local", win = preview_win })
556+
end
554557
vim.w.oil_entry_id = entry.id
555558
vim.w.oil_source_win = prev_win
556559
if is_visual_mode then

lua/oil/view.lua

+5
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ M.set_win_options = function()
182182
for k, v in pairs(config.win_options) do
183183
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid })
184184
end
185+
if vim.wo[winid].previewwindow then -- apply preview window options last
186+
for k, v in pairs(config.preview_win.win_options) do
187+
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid })
188+
end
189+
end
185190
end
186191

187192
---Get a list of visible oil buffers and a list of hidden oil buffers

0 commit comments

Comments
 (0)