refactor: rename action preview window to 'confirmation' window
This commit is contained in:
parent
621f8ba4fa
commit
1f5b002270
7 changed files with 45 additions and 19 deletions
|
|
@ -267,8 +267,13 @@ require("oil").setup({
|
||||||
return conf
|
return conf
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- Configuration for the actions floating preview window
|
-- Configuration for the file preview window
|
||||||
preview = {
|
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%)
|
-- 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.
|
-- 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"
|
-- max_width = {100, 0.8} means "the lesser of 100 columns or 80% of total"
|
||||||
|
|
@ -289,8 +294,6 @@ require("oil").setup({
|
||||||
win_options = {
|
win_options = {
|
||||||
winblend = 0,
|
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
|
-- Configuration for the floating progress window
|
||||||
progress = {
|
progress = {
|
||||||
|
|
|
||||||
|
|
@ -152,8 +152,13 @@ CONFIG *oil-confi
|
||||||
return conf
|
return conf
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- Configuration for the actions floating preview window
|
-- Configuration for the file preview window
|
||||||
preview = {
|
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%)
|
-- 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.
|
-- 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"
|
-- max_width = {100, 0.8} means "the lesser of 100 columns or 80% of total"
|
||||||
|
|
@ -174,8 +179,6 @@ CONFIG *oil-confi
|
||||||
win_options = {
|
win_options = {
|
||||||
winblend = 0,
|
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
|
-- Configuration for the floating progress window
|
||||||
progress = {
|
progress = {
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,13 @@ local default_config = {
|
||||||
return conf
|
return conf
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- Configuration for the actions floating preview window
|
-- Configuration for the file preview window
|
||||||
preview = {
|
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%)
|
-- 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.
|
-- 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"
|
-- max_width = {100, 0.8} means "the lesser of 100 columns or 80% of total"
|
||||||
|
|
@ -159,8 +164,6 @@ local default_config = {
|
||||||
win_options = {
|
win_options = {
|
||||||
winblend = 0,
|
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
|
-- Configuration for the floating progress window
|
||||||
progress = {
|
progress = {
|
||||||
|
|
@ -219,6 +222,7 @@ default_config.adapter_aliases = {}
|
||||||
---@field git oil.GitOptions
|
---@field git oil.GitOptions
|
||||||
---@field float oil.FloatWindowConfig
|
---@field float oil.FloatWindowConfig
|
||||||
---@field preview oil.PreviewWindowConfig
|
---@field preview oil.PreviewWindowConfig
|
||||||
|
---@field confirmation oil.ConfirmationWindowConfig
|
||||||
---@field progress oil.ProgressWindowConfig
|
---@field progress oil.ProgressWindowConfig
|
||||||
---@field ssh oil.SimpleWindowConfig
|
---@field ssh oil.SimpleWindowConfig
|
||||||
---@field keymaps_help 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 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 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 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 progress? oil.SetupProgressWindowConfig Configuration for the floating progress window
|
||||||
---@field ssh? oil.SetupSimpleWindowConfig Configuration for the floating SSH window
|
---@field ssh? oil.SetupSimpleWindowConfig Configuration for the floating SSH window
|
||||||
---@field keymaps_help? oil.SetupSimpleWindowConfig Configuration for the floating keymaps help 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 border? string|string[] Window border
|
||||||
---@field win_options? table<string, any>
|
---@field win_options? table<string, any>
|
||||||
|
|
||||||
---@class (exact) oil.PreviewWindowConfig : oil.WindowConfig
|
---@class (exact) oil.PreviewWindowConfig
|
||||||
---@field update_on_cursor_moved boolean
|
---@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
|
---@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
|
---@class (exact) oil.ProgressWindowConfig : oil.WindowConfig
|
||||||
---@field minimized_border string|string[]
|
---@field minimized_border string|string[]
|
||||||
|
|
||||||
|
|
@ -356,6 +365,7 @@ local M = {}
|
||||||
|
|
||||||
M.setup = function(opts)
|
M.setup = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
local new_conf = vim.tbl_deep_extend("keep", opts, default_config)
|
local new_conf = vim.tbl_deep_extend("keep", opts, default_config)
|
||||||
if not new_conf.use_default_keymaps then
|
if not new_conf.use_default_keymaps then
|
||||||
new_conf.keymaps = opts.keymaps or {}
|
new_conf.keymaps = opts.keymaps or {}
|
||||||
|
|
@ -367,6 +377,11 @@ M.setup = function(opts)
|
||||||
end
|
end
|
||||||
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
|
if new_conf.lsp_rename_autosave ~= nil then
|
||||||
new_conf.lsp_file_methods.autosave_changes = new_conf.lsp_rename_autosave
|
new_conf.lsp_file_methods.autosave_changes = new_conf.lsp_rename_autosave
|
||||||
new_conf.lsp_rename_autosave = nil
|
new_conf.lsp_rename_autosave = nil
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,11 @@ M.split_window = function(winid, direction, gap)
|
||||||
return dim_root, dim_new
|
return dim_root, dim_new
|
||||||
end
|
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)
|
M.calculate_dims = function(desired_width, desired_height, opts)
|
||||||
local width = M.calculate_width(desired_width, opts)
|
local width = M.calculate_width(desired_width, opts)
|
||||||
local height = M.calculate_height(desired_height, opts)
|
local height = M.calculate_height(desired_height, opts)
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
|
||||||
table.insert(lines, "")
|
table.insert(lines, "")
|
||||||
|
|
||||||
-- Create the floating window
|
-- 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, {
|
local ok, winid = pcall(vim.api.nvim_open_win, bufnr, true, {
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
width = width,
|
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),
|
col = math.floor((layout.get_editor_width() - width) / 2),
|
||||||
zindex = 152, -- render on top of the floating window title
|
zindex = 152, -- render on top of the floating window title
|
||||||
style = "minimal",
|
style = "minimal",
|
||||||
border = config.preview.border,
|
border = config.confirmation.border,
|
||||||
})
|
})
|
||||||
if not ok then
|
if not ok then
|
||||||
vim.notify(string.format("Error showing oil preview window: %s", winid), vim.log.levels.ERROR)
|
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
|
end
|
||||||
vim.bo[bufnr].filetype = "oil_preview"
|
vim.bo[bufnr].filetype = "oil_preview"
|
||||||
vim.bo[bufnr].syntax = "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 })
|
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -155,7 +155,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
|
||||||
vim.api.nvim_create_autocmd("VimResized", {
|
vim.api.nvim_create_autocmd("VimResized", {
|
||||||
callback = function()
|
callback = function()
|
||||||
if vim.api.nvim_win_is_valid(winid) then
|
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, {
|
vim.api.nvim_win_set_config(winid, {
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
width = width,
|
width = width,
|
||||||
|
|
@ -3,12 +3,12 @@ local Trie = require("oil.mutator.trie")
|
||||||
local cache = require("oil.cache")
|
local cache = require("oil.cache")
|
||||||
local columns = require("oil.columns")
|
local columns = require("oil.columns")
|
||||||
local config = require("oil.config")
|
local config = require("oil.config")
|
||||||
|
local confirmation = require("oil.mutator.confirmation")
|
||||||
local constants = require("oil.constants")
|
local constants = require("oil.constants")
|
||||||
local fs = require("oil.fs")
|
local fs = require("oil.fs")
|
||||||
local lsp_helpers = require("oil.lsp.helpers")
|
local lsp_helpers = require("oil.lsp.helpers")
|
||||||
local oil = require("oil")
|
local oil = require("oil")
|
||||||
local parser = require("oil.mutator.parser")
|
local parser = require("oil.mutator.parser")
|
||||||
local preview = require("oil.mutator.preview")
|
|
||||||
local util = require("oil.util")
|
local util = require("oil.util")
|
||||||
local view = require("oil.view")
|
local view = require("oil.view")
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
@ -564,7 +564,7 @@ M.try_write_changes = function(confirm, cb)
|
||||||
end
|
end
|
||||||
|
|
||||||
local actions = M.create_actions_from_diffs(all_diffs)
|
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
|
if not proceed then
|
||||||
unlock()
|
unlock()
|
||||||
cb("Canceled")
|
cb("Canceled")
|
||||||
|
|
|
||||||
|
|
@ -413,7 +413,7 @@ M.initialize = function(bufnr)
|
||||||
timer:again()
|
timer:again()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
timer = vim.loop.new_timer()
|
timer = uv.new_timer()
|
||||||
if not timer then
|
if not timer then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue