feat(project): add fzf-lua keymap descriptions (#3690)

![image](17f36737-8416-4612-a2bf-17a264ca5814)

Co-authored-by: 肖健正 <xiaojianzheng@qq.com>
This commit is contained in:
xiaojianzheng 2024-06-19 00:47:40 +08:00 committed by GitHub
parent 1a295c5ef8
commit 07ab681b1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,45 +9,71 @@ pick = function()
local history = require("project_nvim.utils.history") local history = require("project_nvim.utils.history")
local results = history.get_recent_projects() local results = history.get_recent_projects()
local actions = require("fzf-lua.actions") local actions = require("fzf-lua.actions")
local core = require("fzf-lua.core")
-- local path = require("fzf-lua.path")
local utils = require("fzf-lua.utils")
fzf_lua.fzf_exec(results, { local function hl_validate(hl)
actions = { return not utils.is_hl_cleared(hl) and hl or nil
["default"] = { end
function(selected)
fzf_lua.files({ cwd = selected[1] }) function actions.project_files(selected)
end, fzf_lua.files({ cwd = selected[1] })
}, end
["ctrl-t"] = actions.file_tabedit,
["ctrl-s"] = { function actions.project_live_grep(selected)
function(selected) fzf_lua.live_grep({ cwd = selected[1] })
fzf_lua.live_grep({ cwd = selected[1] }) end
end,
}, function actions.project_oldfiles(selected)
["ctrl-r"] = { fzf_lua.oldfiles({ cwd = selected[1] })
function(selected) end
fzf_lua.oldfiles({ cwd = selected[1] })
end, function actions.project_cd_cwd(selected)
}, local path = selected[1]
["ctrl-w"] = { local ok = project.set_pwd(path)
function(selected) if ok then
local path = selected[1] vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
local ok = project.set_pwd(path) LazyVim.info("Change project dir to " .. path)
if ok then end
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true) end
LazyVim.info("Change project dir to " .. path)
end function actions.project_delete(selected)
end, local path = selected[1]
}, local choice = vim.fn.confirm("Delete '" .. path .. "' project? ", "&Yes\n&No")
["ctrl-d"] = function(selected) if choice == 1 then
local path = selected[1] history.delete_project({ value = path })
local choice = vim.fn.confirm("Delete '" .. path .. "' project? ", "&Yes\n&No") end
if choice == 1 then pick()
history.delete_project({ value = path }) end
end
pick() -- core.ACTION_DEFINITIONS[actions.project_files] = { "find project files" }
end, core.ACTION_DEFINITIONS[actions.file_tabedit] = { "tabedit" }
core.ACTION_DEFINITIONS[actions.project_live_grep] = { "live_grep" }
core.ACTION_DEFINITIONS[actions.project_oldfiles] = { "oldfiles" }
core.ACTION_DEFINITIONS[actions.project_cd_cwd] = { "change dir" }
core.ACTION_DEFINITIONS[actions.project_delete] = { "delete" }
local opts = {
fzf_opts = {},
hls = {
header_bind = hl_validate("FzfLuaHeaderBind"),
header_text = hl_validate("FzfLuaHeaderText"),
}, },
}) fzf_colors = true,
header_separator = " | ",
actions = {
["default"] = actions.project_files,
["ctrl-t"] = actions.file_tabedit,
["ctrl-s"] = actions.project_live_grep,
["ctrl-r"] = actions.project_oldfiles,
["ctrl-w"] = actions.project_cd_cwd,
["ctrl-d"] = actions.project_delete,
},
}
opts = core.set_header(opts, { "actions" })
fzf_lua.fzf_exec(results, opts)
end end
end end