feat: add backdrop to modals
parent
c4abaad214
commit
f1e824e163
|
|
@ -39,7 +39,6 @@ Lightweight and quick file operations without being a full-blown file manager.
|
||||||
{
|
{
|
||||||
"chrisgrieser/nvim-genghis",
|
"chrisgrieser/nvim-genghis",
|
||||||
dependencies = "stevearc/dressing.nvim"
|
dependencies = "stevearc/dressing.nvim"
|
||||||
cmd = "Genghis",
|
|
||||||
},
|
},
|
||||||
|
|
||||||
-- packer
|
-- packer
|
||||||
|
|
@ -55,6 +54,10 @@ The `setup` call is optional.
|
||||||
```lua
|
```lua
|
||||||
-- default config
|
-- default config
|
||||||
require("genghis").setup {
|
require("genghis").setup {
|
||||||
|
backdrop = {
|
||||||
|
enabled = true,
|
||||||
|
blend = 50,
|
||||||
|
},
|
||||||
-- cli name, default is `trash` on Mac and Windows, and `gio trash` on Linux
|
-- cli name, default is `trash` on Mac and Windows, and `gio trash` on Linux
|
||||||
trashCmd = "trash",
|
trashCmd = "trash",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,11 @@ local M = {}
|
||||||
|
|
||||||
---@class Genghis.config
|
---@class Genghis.config
|
||||||
local defaultConfig = {
|
local defaultConfig = {
|
||||||
|
backdrop = {
|
||||||
|
enabled = true,
|
||||||
|
blend = 50,
|
||||||
|
},
|
||||||
|
-- cli name, default is `trash` on Mac and Windows, and `gio trash` on Linux
|
||||||
trashCmd = nil,
|
trashCmd = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local backdrop = require("genghis.support.backdrop")
|
||||||
local rename = require("genghis.support.lsp-rename")
|
local rename = require("genghis.support.lsp-rename")
|
||||||
local u = require("genghis.support.utils")
|
local u = require("genghis.support.utils")
|
||||||
local osPathSep = package.config:sub(1, 1)
|
local osPathSep = package.config:sub(1, 1)
|
||||||
|
|
@ -38,6 +39,13 @@ local function fileOp(op)
|
||||||
prefill = ""
|
prefill = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- backdrop
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
group = vim.api.nvim_create_augroup("InputGenghisBackdrop", {}),
|
||||||
|
pattern = "DressingInput",
|
||||||
|
callback = function(ctx) backdrop.new(ctx.buf) end,
|
||||||
|
})
|
||||||
|
|
||||||
vim.ui.input({
|
vim.ui.input({
|
||||||
prompt = promptStr,
|
prompt = promptStr,
|
||||||
default = prefill,
|
default = prefill,
|
||||||
|
|
@ -119,6 +127,8 @@ function M.duplicateFile() fileOp("duplicate") end
|
||||||
function M.createNewFile() fileOp("new") end
|
function M.createNewFile() fileOp("new") end
|
||||||
function M.moveSelectionToNewFile() fileOp("new-from-selection") end
|
function M.moveSelectionToNewFile() fileOp("new-from-selection") end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
function M.moveToFolderInCwd()
|
function M.moveToFolderInCwd()
|
||||||
local curFilePath = vim.api.nvim_buf_get_name(0)
|
local curFilePath = vim.api.nvim_buf_get_name(0)
|
||||||
local parentOfCurFile = vim.fs.dirname(curFilePath) .. osPathSep
|
local parentOfCurFile = vim.fs.dirname(curFilePath) .. osPathSep
|
||||||
|
|
@ -148,6 +158,12 @@ function M.moveToFolderInCwd()
|
||||||
-- insert cwd at bottom, since modification of is likely due to subfolders
|
-- insert cwd at bottom, since modification of is likely due to subfolders
|
||||||
if cwd ~= parentOfCurFile then table.insert(foldersInCwd, cwd) end
|
if cwd ~= parentOfCurFile then table.insert(foldersInCwd, cwd) end
|
||||||
|
|
||||||
|
local autocmd = vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
group = vim.api.nvim_create_augroup("SelectorGenghisBackdrop", {}),
|
||||||
|
pattern = { "DressingSelect", "TelescopePrompt" },
|
||||||
|
callback = function(ctx) backdrop.new(ctx.buf) end,
|
||||||
|
})
|
||||||
|
|
||||||
-- prompt user and move
|
-- prompt user and move
|
||||||
local promptStr = "Choose Destination Folder"
|
local promptStr = "Choose Destination Folder"
|
||||||
if lspSupportsRenaming then promptStr = promptStr .. " (with updated imports)" end
|
if lspSupportsRenaming then promptStr = promptStr .. " (with updated imports)" end
|
||||||
|
|
@ -156,6 +172,9 @@ function M.moveToFolderInCwd()
|
||||||
kind = "genghis.moveToFolderInCwd",
|
kind = "genghis.moveToFolderInCwd",
|
||||||
format_item = function(path) return path:sub(#cwd) end, -- only relative path
|
format_item = function(path) return path:sub(#cwd) end, -- only relative path
|
||||||
}, function(destination)
|
}, function(destination)
|
||||||
|
-- in case neither dressing nor telescope was used as selector-backend
|
||||||
|
vim.api.nvim_del_autocmd(autocmd)
|
||||||
|
|
||||||
if not destination then return end
|
if not destination then return end
|
||||||
local newFilePath = destination .. osPathSep .. filename
|
local newFilePath = destination .. osPathSep .. filename
|
||||||
|
|
||||||
|
|
@ -178,7 +197,5 @@ function M.moveToFolderInCwd()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
local M = {}
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local backdropName = "GenghisBackdrop"
|
||||||
|
|
||||||
|
---@param referenceBuf number Reference buffer, when that buffer is closed, the backdrop will be closed too
|
||||||
|
---@param referenceZindex? number zindex of the reference window, where the backdrop should be placed below
|
||||||
|
function M.new(referenceBuf, referenceZindex)
|
||||||
|
local config = require("genghis.config").config
|
||||||
|
if not config.backdrop.enabled then return end
|
||||||
|
local blend = config.backdrop.blend
|
||||||
|
if not referenceZindex then referenceZindex = 10 end
|
||||||
|
|
||||||
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
local winnr = vim.api.nvim_open_win(bufnr, false, {
|
||||||
|
relative = "editor",
|
||||||
|
row = 0,
|
||||||
|
col = 0,
|
||||||
|
width = vim.o.columns,
|
||||||
|
height = vim.o.lines,
|
||||||
|
focusable = false,
|
||||||
|
style = "minimal",
|
||||||
|
zindex = referenceZindex - 1, -- ensure it's below the reference window
|
||||||
|
})
|
||||||
|
vim.api.nvim_set_hl(0, backdropName, { bg = "#000000", default = true })
|
||||||
|
vim.wo[winnr].winhighlight = "Normal:" .. backdropName
|
||||||
|
vim.wo[winnr].winblend = blend
|
||||||
|
vim.bo[bufnr].buftype = "nofile"
|
||||||
|
vim.bo[bufnr].filetype = backdropName
|
||||||
|
|
||||||
|
-- close backdrop when the reference buffer is closed
|
||||||
|
vim.api.nvim_create_autocmd({ "WinClosed", "BufLeave" }, {
|
||||||
|
group = vim.api.nvim_create_augroup(backdropName, { clear = true }),
|
||||||
|
once = true,
|
||||||
|
buffer = referenceBuf,
|
||||||
|
callback = function()
|
||||||
|
if vim.api.nvim_win_is_valid(winnr) then vim.api.nvim_win_close(winnr, true) end
|
||||||
|
if vim.api.nvim_buf_is_valid(bufnr) then
|
||||||
|
vim.api.nvim_buf_delete(bufnr, { force = true })
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
return M
|
||||||
Loading…
Reference in New Issue