feat(git): status_view help hint, mouse open, extmark highlights
This commit is contained in:
+50
-15
@@ -106,29 +106,59 @@ end
|
||||
---@param status ow.Git.Status
|
||||
local function render(bufnr, status)
|
||||
local branch = status.branch
|
||||
local lines = { "Head: " .. (branch.head or "?") }
|
||||
local lines = {}
|
||||
local marks = {}
|
||||
local meta = {}
|
||||
|
||||
local function label(row, len)
|
||||
table.insert(marks, { row = row, col = 0, end_col = len, hl = "Label" })
|
||||
end
|
||||
|
||||
table.insert(lines, "Head: " .. (branch.head or "?"))
|
||||
label(#lines - 1, 4)
|
||||
|
||||
if branch.upstream then
|
||||
local push = "Push: " .. branch.upstream
|
||||
local extras = {}
|
||||
if branch.ahead > 0 then
|
||||
local col = #push + 1
|
||||
push = push .. " +" .. branch.ahead
|
||||
table.insert(extras, { col = col, end_col = #push, hl = "GitUnpushed" })
|
||||
end
|
||||
if branch.behind > 0 then
|
||||
local col = #push + 1
|
||||
push = push .. " -" .. branch.behind
|
||||
table.insert(extras, { col = col, end_col = #push, hl = "GitUnpulled" })
|
||||
end
|
||||
table.insert(lines, push)
|
||||
local row = #lines - 1
|
||||
label(row, 4)
|
||||
for _, e in ipairs(extras) do
|
||||
e.row = row
|
||||
table.insert(marks, e)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(lines, "Help: g?")
|
||||
label(#lines - 1, 4)
|
||||
|
||||
table.insert(lines, "")
|
||||
|
||||
local meta = {}
|
||||
local marks = {}
|
||||
for _, section in ipairs(SECTIONS) do
|
||||
local rows = status:rows(section)
|
||||
if #rows > 0 then
|
||||
table.insert(
|
||||
lines,
|
||||
string.format("%s (%d)", display_name(section), #rows)
|
||||
)
|
||||
local name = display_name(section)
|
||||
local header = string.format("%s (%d)", name, #rows)
|
||||
table.insert(lines, header)
|
||||
local header_row = #lines - 1
|
||||
meta[#lines] = { is_header = true, section = section }
|
||||
label(header_row, #name)
|
||||
table.insert(marks, {
|
||||
row = header_row,
|
||||
col = #name + 2,
|
||||
end_col = #header - 1,
|
||||
hl = "Number",
|
||||
})
|
||||
for _, row in ipairs(rows) do
|
||||
local line, hl, hl_len = format_row(row)
|
||||
table.insert(lines, line)
|
||||
@@ -517,19 +547,21 @@ end
|
||||
local function action_help(placement)
|
||||
local lines = { "git status view" }
|
||||
if placement == "sidebar" then
|
||||
table.insert(lines, " <Tab> preview diff (keep focus)")
|
||||
table.insert(lines, " <CR> open diff (focus left pane)")
|
||||
table.insert(lines, " <Tab> preview diff (keep focus)")
|
||||
table.insert(lines, " <CR> open diff (focus left pane)")
|
||||
table.insert(lines, " <2-LeftMouse> open diff (focus left pane)")
|
||||
else
|
||||
table.insert(lines, " <CR> open file")
|
||||
table.insert(lines, " <CR> open file")
|
||||
table.insert(lines, " <2-LeftMouse> open file")
|
||||
end
|
||||
table.insert(lines, " s stage file")
|
||||
table.insert(lines, " u unstage file")
|
||||
table.insert(lines, " s stage file")
|
||||
table.insert(lines, " u unstage file")
|
||||
table.insert(
|
||||
lines,
|
||||
" X discard worktree changes (untracked: delete file)"
|
||||
" X discard worktree changes (untracked: delete file)"
|
||||
)
|
||||
table.insert(lines, " R refresh")
|
||||
table.insert(lines, " g? show this help")
|
||||
table.insert(lines, " R refresh")
|
||||
table.insert(lines, " g? show this help")
|
||||
print(table.concat(lines, "\n"))
|
||||
end
|
||||
|
||||
@@ -579,6 +611,9 @@ local function setup_buffer(bufnr, r, placement, win)
|
||||
k("<CR>", function()
|
||||
preview_or_open(true)
|
||||
end, "Open")
|
||||
k("<2-LeftMouse>", function()
|
||||
preview_or_open(true)
|
||||
end, "Open")
|
||||
k("s", action_stage, "Stage file")
|
||||
k("u", action_unstage, "Unstage file")
|
||||
k("X", action_discard, "Discard worktree changes")
|
||||
|
||||
Reference in New Issue
Block a user