From 1f5b002270addb9010740e34824244e777de7c9e Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Sun, 10 Nov 2024 15:51:46 -0800 Subject: [PATCH] refactor: rename action preview window to 'confirmation' window --- README.md | 9 ++++--- doc/oil.txt | 9 ++++--- lua/oil/config.lua | 27 ++++++++++++++----- lua/oil/layout.lua | 5 ++++ .../mutator/{preview.lua => confirmation.lua} | 8 +++--- lua/oil/mutator/init.lua | 4 +-- lua/oil/view.lua | 2 +- 7 files changed, 45 insertions(+), 19 deletions(-) rename lua/oil/mutator/{preview.lua => confirmation.lua} (97%) diff --git a/README.md b/README.md index 46063b2..4d91f1d 100644 --- a/README.md +++ b/README.md @@ -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 = { diff --git a/doc/oil.txt b/doc/oil.txt index 70c589d..cafd61e 100644 --- a/doc/oil.txt +++ b/doc/oil.txt @@ -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 = { diff --git a/lua/oil/config.lua b/lua/oil/config.lua index 0c4f130..bcb7225 100644 --- a/lua/oil/config.lua +++ b/lua/oil/config.lua @@ -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 ----@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 diff --git a/lua/oil/layout.lua b/lua/oil/layout.lua index f22d26a..8ed7b4e 100644 --- a/lua/oil/layout.lua +++ b/lua/oil/layout.lua @@ -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) diff --git a/lua/oil/mutator/preview.lua b/lua/oil/mutator/confirmation.lua similarity index 97% rename from lua/oil/mutator/preview.lua rename to lua/oil/mutator/confirmation.lua index 3f8d87d..4e86abc 100644 --- a/lua/oil/mutator/preview.lua +++ b/lua/oil/mutator/confirmation.lua @@ -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, diff --git a/lua/oil/mutator/init.lua b/lua/oil/mutator/init.lua index 8dfd4b0..f15c069 100644 --- a/lua/oil/mutator/init.lua +++ b/lua/oil/mutator/init.lua @@ -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") diff --git a/lua/oil/view.lua b/lua/oil/view.lua index 89e4b8f..bf34e8b 100644 --- a/lua/oil/view.lua +++ b/lua/oil/view.lua @@ -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