feat(git): status_view help hint, mouse open, extmark highlights

This commit is contained in:
2026-05-19 14:47:40 +02:00
parent 897de35688
commit 26d074c464
2 changed files with 50 additions and 59 deletions
+42 -7
View File
@@ -106,29 +106,59 @@ end
---@param status ow.Git.Status ---@param status ow.Git.Status
local function render(bufnr, status) local function render(bufnr, status)
local branch = status.branch 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 if branch.upstream then
local push = "Push: " .. branch.upstream local push = "Push: " .. branch.upstream
local extras = {}
if branch.ahead > 0 then if branch.ahead > 0 then
local col = #push + 1
push = push .. " +" .. branch.ahead push = push .. " +" .. branch.ahead
table.insert(extras, { col = col, end_col = #push, hl = "GitUnpushed" })
end end
if branch.behind > 0 then if branch.behind > 0 then
local col = #push + 1
push = push .. " -" .. branch.behind push = push .. " -" .. branch.behind
table.insert(extras, { col = col, end_col = #push, hl = "GitUnpulled" })
end end
table.insert(lines, push) 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
end
table.insert(lines, "Help: g?")
label(#lines - 1, 4)
table.insert(lines, "") table.insert(lines, "")
local meta = {}
local marks = {}
for _, section in ipairs(SECTIONS) do for _, section in ipairs(SECTIONS) do
local rows = status:rows(section) local rows = status:rows(section)
if #rows > 0 then if #rows > 0 then
table.insert( local name = display_name(section)
lines, local header = string.format("%s (%d)", name, #rows)
string.format("%s (%d)", display_name(section), #rows) table.insert(lines, header)
) local header_row = #lines - 1
meta[#lines] = { is_header = true, section = section } 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 for _, row in ipairs(rows) do
local line, hl, hl_len = format_row(row) local line, hl, hl_len = format_row(row)
table.insert(lines, line) table.insert(lines, line)
@@ -519,8 +549,10 @@ local function action_help(placement)
if placement == "sidebar" then if placement == "sidebar" then
table.insert(lines, " <Tab> preview diff (keep focus)") table.insert(lines, " <Tab> preview diff (keep focus)")
table.insert(lines, " <CR> open diff (focus left pane)") table.insert(lines, " <CR> open diff (focus left pane)")
table.insert(lines, " <2-LeftMouse> open diff (focus left pane)")
else else
table.insert(lines, " <CR> open file") table.insert(lines, " <CR> open file")
table.insert(lines, " <2-LeftMouse> open file")
end end
table.insert(lines, " s stage file") table.insert(lines, " s stage file")
table.insert(lines, " u unstage file") table.insert(lines, " u unstage file")
@@ -579,6 +611,9 @@ local function setup_buffer(bufnr, r, placement, win)
k("<CR>", function() k("<CR>", function()
preview_or_open(true) preview_or_open(true)
end, "Open") end, "Open")
k("<2-LeftMouse>", function()
preview_or_open(true)
end, "Open")
k("s", action_stage, "Stage file") k("s", action_stage, "Stage file")
k("u", action_unstage, "Unstage file") k("u", action_unstage, "Unstage file")
k("X", action_discard, "Discard worktree changes") k("X", action_discard, "Discard worktree changes")
-44
View File
@@ -1,44 +0,0 @@
if exists("b:current_syntax")
finish
endif
syntax match gitStatusLabel /\v^(Head|Push)\ze:/
syntax match gitStatusBranch /\v(^(Head|Push):\s+)@<=\S+/
syntax match gitStatusAhead /\v\+\d+/
syntax match gitStatusBehind /\v-\d+/
syntax region gitStatusUntrackedHeader start=/\v^Untracked>/ end=/\v^$/
syntax region gitStatusUnstagedHeader start=/\v^Unstaged>/ end=/\v^$/
syntax region gitStatusStagedHeader start=/\v^Staged>/ end=/\v^$/
syntax region gitStatusUnmergedHeader start=/\v^Unmerged>/ end=/\v^$/
syntax region gitStatusUnpushedHeader start=/\v^Unpushed>/ end=/\v^$/
syntax region gitStatusUnpulledHeader start=/\v^Unpulled>/ end=/\v^$/
syntax match gitStatusUntrackedLabel /\v^Untracked/ contained containedin=gitStatusUntrackedHeader
syntax match gitStatusUnstagedLabel /\v^Unstaged/ contained containedin=gitStatusUnstagedHeader
syntax match gitStatusStagedLabel /\v^Staged/ contained containedin=gitStatusStagedHeader
syntax match gitStatusUnmergedLabel /\v^Unmerged/ contained containedin=gitStatusUnmergedHeader
syntax match gitStatusUnpushedLabel /\v^Unpushed/ contained containedin=gitStatusUnpushedHeader
syntax match gitStatusUnpulledLabel /\v^Unpulled/ contained containedin=gitStatusUnpulledHeader
syntax match gitStatusHeaderCount /\v\(\zs\d+\ze\)/ contained containedin=gitStatusUntrackedHeader,
\ gitStatusUnstagedHeader,
\ gitStatusStagedHeader,
\ gitStatusUnmergedHeader,
\ gitStatusUnpushedHeader,
\ gitStatusUnpulledHeader
highlight default link gitStatusLabel Label
highlight default link gitStatusBranch None
highlight default link gitStatusAhead GitUnpushed
highlight default link gitStatusBehind GitUnpulled
highlight default link gitStatusHeaderCount Number
highlight default link gitStatusUntrackedLabel gitStatusLabel
highlight default link gitStatusUnstagedLabel gitStatusLabel
highlight default link gitStatusStagedLabel gitStatusLabel
highlight default link gitStatusUnmergedLabel gitStatusLabel
highlight default link gitStatusUnpushedLabel gitStatusLabel
highlight default link gitStatusUnpulledLabel gitStatusLabel
let b:current_syntax = "gitStatus"