refactor: rename action preview window to 'confirmation' window

This commit is contained in:
Steven Arcangeli 2024-11-10 15:51:46 -08:00
parent 621f8ba4fa
commit 1f5b002270
7 changed files with 45 additions and 19 deletions

View file

@ -267,8 +267,13 @@ require("oil").setup({
return conf
end,
},
-- Configuration for the actions floating preview window
-- Configuration for the file preview window
preview = {
-- Whether the preview window is automatically updated when the cursor is moved
update_on_cursor_moved = true,
},
-- Configuration for the floating action confirmation window
confirmation = {
-- Width dimensions can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
-- min_width and max_width can be a single value or a list of mixed integer/float types.
-- max_width = {100, 0.8} means "the lesser of 100 columns or 80% of total"
@ -289,8 +294,6 @@ require("oil").setup({
win_options = {
winblend = 0,
},
-- Whether the preview window is automatically updated when the cursor is moved
update_on_cursor_moved = true,
},
-- Configuration for the floating progress window
progress = {

View file

@ -152,8 +152,13 @@ CONFIG *oil-confi
return conf
end,
},
-- Configuration for the actions floating preview window
-- Configuration for the file preview window
preview = {
-- Whether the preview window is automatically updated when the cursor is moved
update_on_cursor_moved = true,
},
-- Configuration for the floating action confirmation window
confirmation = {
-- Width dimensions can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
-- min_width and max_width can be a single value or a list of mixed integer/float types.
-- max_width = {100, 0.8} means "the lesser of 100 columns or 80% of total"
@ -174,8 +179,6 @@ CONFIG *oil-confi
win_options = {
winblend = 0,
},
-- Whether the preview window is automatically updated when the cursor is moved
update_on_cursor_moved = true,
},
-- Configuration for the floating progress window
progress = {

View file

@ -137,8 +137,13 @@ local default_config = {
return conf
end,
},
-- Configuration for the actions floating preview window
-- Configuration for the file preview window
preview = {
-- Whether the preview window is automatically updated when the cursor is moved
update_on_cursor_moved = true,
},
-- Configuration for the floating action confirmation window
confirmation = {
-- Width dimensions can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
-- min_width and max_width can be a single value or a list of mixed integer/float types.
-- max_width = {100, 0.8} means "the lesser of 100 columns or 80% of total"
@ -159,8 +164,6 @@ local default_config = {
win_options = {
winblend = 0,
},
-- Whether the preview window is automatically updated when the cursor is moved
update_on_cursor_moved = true,
},
-- Configuration for the floating progress window
progress = {
@ -219,6 +222,7 @@ default_config.adapter_aliases = {}
---@field git oil.GitOptions
---@field float oil.FloatWindowConfig
---@field preview oil.PreviewWindowConfig
---@field confirmation oil.ConfirmationWindowConfig
---@field progress oil.ProgressWindowConfig
---@field ssh oil.SimpleWindowConfig
---@field keymaps_help oil.SimpleWindowConfig
@ -245,7 +249,8 @@ local M = {}
---@field extra_scp_args? string[] Extra arguments to pass to SCP when moving/copying files over SSH
---@field git? oil.SetupGitOptions EXPERIMENTAL support for performing file operations with git
---@field float? oil.SetupFloatWindowConfig Configuration for the floating window in oil.open_float
---@field preview? oil.SetupPreviewWindowConfig Configuration for the actions floating preview window
---@field preview? oil.SetupPreviewWindowConfig Configuration for the file preview window
---@field confirmation? oil.SetupConfirmationWindowConfig Configuration for the floating action confirmation window
---@field progress? oil.SetupProgressWindowConfig Configuration for the floating progress window
---@field ssh? oil.SetupSimpleWindowConfig Configuration for the floating SSH window
---@field keymaps_help? oil.SetupSimpleWindowConfig Configuration for the floating keymaps help window
@ -316,12 +321,16 @@ local M = {}
---@field border? string|string[] Window border
---@field win_options? table<string, any>
---@class (exact) oil.PreviewWindowConfig : oil.WindowConfig
---@class (exact) oil.PreviewWindowConfig
---@field update_on_cursor_moved boolean
---@class (exact) oil.SetupPreviewWindowConfig : oil.SetupWindowConfig
---@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
---@class (exact) oil.SetupConfirmationWindowConfig : oil.SetupWindowConfig
---@class (exact) oil.ProgressWindowConfig : oil.WindowConfig
---@field minimized_border string|string[]
@ -356,6 +365,7 @@ local M = {}
M.setup = function(opts)
opts = opts or {}
local new_conf = vim.tbl_deep_extend("keep", opts, default_config)
if not new_conf.use_default_keymaps then
new_conf.keymaps = opts.keymaps or {}
@ -367,6 +377,11 @@ M.setup = function(opts)
end
end
-- Backwards compatibility. We renamed the 'preview' window config to be called 'confirmation'.
if opts.preview and not opts.confirmation then
new_conf.confirmation = vim.tbl_deep_extend("keep", opts.preview, default_config.confirmation)
end
if new_conf.lsp_rename_autosave ~= nil then
new_conf.lsp_file_methods.autosave_changes = new_conf.lsp_rename_autosave
new_conf.lsp_rename_autosave = nil

View file

@ -182,6 +182,11 @@ M.split_window = function(winid, direction, gap)
return dim_root, dim_new
end
---@param desired_width integer
---@param desired_height integer
---@param opts table
---@return integer width
---@return integer height
M.calculate_dims = function(desired_width, desired_height, opts)
local width = M.calculate_width(desired_width, opts)
local height = M.calculate_height(desired_height, opts)

View file

@ -91,7 +91,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
table.insert(lines, "")
-- Create the floating window
local width, height = layout.calculate_dims(max_line_width, #lines + 1, config.preview)
local width, height = layout.calculate_dims(max_line_width, #lines + 1, config.confirmation)
local ok, winid = pcall(vim.api.nvim_open_win, bufnr, true, {
relative = "editor",
width = width,
@ -100,7 +100,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
col = math.floor((layout.get_editor_width() - width) / 2),
zindex = 152, -- render on top of the floating window title
style = "minimal",
border = config.preview.border,
border = config.confirmation.border,
})
if not ok then
vim.notify(string.format("Error showing oil preview window: %s", winid), vim.log.levels.ERROR)
@ -108,7 +108,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
end
vim.bo[bufnr].filetype = "oil_preview"
vim.bo[bufnr].syntax = "oil_preview"
for k, v in pairs(config.preview.win_options) do
for k, v in pairs(config.confirmation.win_options) do
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid })
end
@ -155,7 +155,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
vim.api.nvim_create_autocmd("VimResized", {
callback = function()
if vim.api.nvim_win_is_valid(winid) then
width, height = layout.calculate_dims(max_line_width, #lines, config.preview)
width, height = layout.calculate_dims(max_line_width, #lines, config.confirmation)
vim.api.nvim_win_set_config(winid, {
relative = "editor",
width = width,

View file

@ -3,12 +3,12 @@ local Trie = require("oil.mutator.trie")
local cache = require("oil.cache")
local columns = require("oil.columns")
local config = require("oil.config")
local confirmation = require("oil.mutator.confirmation")
local constants = require("oil.constants")
local fs = require("oil.fs")
local lsp_helpers = require("oil.lsp.helpers")
local oil = require("oil")
local parser = require("oil.mutator.parser")
local preview = require("oil.mutator.preview")
local util = require("oil.util")
local view = require("oil.view")
local M = {}
@ -564,7 +564,7 @@ M.try_write_changes = function(confirm, cb)
end
local actions = M.create_actions_from_diffs(all_diffs)
preview.show(actions, confirm, function(proceed)
confirmation.show(actions, confirm, function(proceed)
if not proceed then
unlock()
cb("Canceled")

View file

@ -413,7 +413,7 @@ M.initialize = function(bufnr)
timer:again()
return
end
timer = vim.loop.new_timer()
timer = uv.new_timer()
if not timer then
return
end