mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 03:08:13 +00:00
fix(picker.git): --follow
only works for git_log_file
. Closes #666
This commit is contained in:
parent
f65a2c82f3
commit
23a8668ef0
2 changed files with 11 additions and 7 deletions
|
@ -8,6 +8,7 @@
|
|||
---@field paths {path:string, want:boolean}[]
|
||||
---@field opts snacks.picker.filter.Config
|
||||
---@field current_buf number
|
||||
---@field current_win number
|
||||
local M = {}
|
||||
M.__index = M
|
||||
|
||||
|
@ -18,6 +19,7 @@ function M.new(picker)
|
|||
local opts = picker.opts ---@type snacks.picker.Config|{filter?:snacks.picker.filter.Config}
|
||||
local self = setmetatable({}, M)
|
||||
self.current_buf = vim.api.nvim_get_current_buf()
|
||||
self.current_win = vim.api.nvim_get_current_win()
|
||||
self.opts = opts.filter or {}
|
||||
local function gets(v)
|
||||
return type(v) == "function" and v(picker) or v or "" --[[@as string]]
|
||||
|
|
|
@ -33,7 +33,7 @@ end
|
|||
|
||||
---@param opts snacks.picker.git.log.Config
|
||||
---@type snacks.picker.finder
|
||||
function M.log(opts)
|
||||
function M.log(opts, filter)
|
||||
local args = {
|
||||
"log",
|
||||
"--pretty=format:%h %s (%ch)",
|
||||
|
@ -44,20 +44,22 @@ function M.log(opts)
|
|||
"--no-show-signature",
|
||||
"--no-patch",
|
||||
}
|
||||
|
||||
if opts.follow and not opts.current_line then
|
||||
args[#args + 1] = "--follow"
|
||||
if opts.follow and not opts.current_file then
|
||||
opts.follow = nil
|
||||
end
|
||||
|
||||
local file ---@type string?
|
||||
if opts.current_line then
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
file = vim.api.nvim_buf_get_name(0)
|
||||
local cursor = vim.api.nvim_win_get_cursor(filter.current_win)
|
||||
file = vim.api.nvim_buf_get_name(filter.current_buf)
|
||||
local line = cursor[1]
|
||||
args[#args + 1] = "-L"
|
||||
args[#args + 1] = line .. ",+1:" .. file
|
||||
elseif opts.current_file then
|
||||
file = vim.api.nvim_buf_get_name(0)
|
||||
file = vim.api.nvim_buf_get_name(filter.current_buf)
|
||||
if opts.follow then
|
||||
args[#args + 1] = "--follow"
|
||||
end
|
||||
args[#args + 1] = "--"
|
||||
args[#args + 1] = file
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue