mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
fix(gitbrowse): use line_start and line_end directly in patterns. Closes #186
This commit is contained in:
parent
67894ee778
commit
adf0433e8f
1 changed files with 9 additions and 7 deletions
|
@ -46,17 +46,17 @@ local defaults = {
|
|||
url_patterns = {
|
||||
["github%.com"] = {
|
||||
branch = "/tree/{branch}",
|
||||
file = "/blob/{branch}/{file}#L{line}",
|
||||
file = "/blob/{branch}/{file}#L{line_start}-L{line_end}",
|
||||
commit = "/commit/{commit}",
|
||||
},
|
||||
["gitlab%.com"] = {
|
||||
branch = "/-/tree/{branch}",
|
||||
file = "/-/blob/{branch}/{file}#L{line}",
|
||||
file = "/-/blob/{branch}/{file}#L{line_start}-L{line_end}",
|
||||
commit = "/-/commit/{commit}",
|
||||
},
|
||||
["bitbucket%.org"] = {
|
||||
branch = "/src/{branch}",
|
||||
file = "/src/{branch}/{file}#lines-{line}",
|
||||
file = "/src/{branch}/{file}#lines-{line_start}-L{line_end}",
|
||||
commit = "/commits/{commit}",
|
||||
},
|
||||
},
|
||||
|
@ -125,7 +125,8 @@ function M._open(opts)
|
|||
branch = opts.branch
|
||||
or system({ "git", "-C", cwd, "rev-parse", "--abbrev-ref", "HEAD" }, "Failed to get current branch")[1],
|
||||
file = file and system({ "git", "-C", cwd, "ls-files", "--full-name", file }, "Failed to get git file path")[1],
|
||||
line = nil,
|
||||
line_start = opts.line_start,
|
||||
line_end = opts.line_end,
|
||||
commit = is_commit and word,
|
||||
}
|
||||
|
||||
|
@ -139,10 +140,11 @@ function M._open(opts)
|
|||
if line_start > line_end then
|
||||
line_start, line_end = line_end, line_start
|
||||
end
|
||||
fields.line = file and line_start .. "-L" .. line_end
|
||||
fields.line_start = line_start
|
||||
fields.line_end = line_end
|
||||
else
|
||||
fields.line = file
|
||||
and (opts.line_start and opts.line_end and opts.line_start .. "-L" .. opts.line_end or vim.fn.line("."))
|
||||
fields.line_start = fields.line_start or vim.fn.line(".")
|
||||
fields.line_end = fields.line_end or fields.line_start
|
||||
end
|
||||
|
||||
opts.what = is_commit and "commit" or opts.what == "commit" and not fields.commit and "file" or opts.what
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue