Compare commits
2 commits
e643bbebcf
...
1258674a1e
| Author | SHA1 | Date | |
|---|---|---|---|
| 1258674a1e | |||
| 666690ad48 |
1 changed files with 38 additions and 0 deletions
|
|
@ -182,6 +182,23 @@ local function apply_inline_row(bufnr, row, m, icons)
|
|||
end
|
||||
end
|
||||
|
||||
---@param line string
|
||||
---@return string?
|
||||
local function infer_status(line)
|
||||
local ch = line:match('^/%d+/- %[(.)%]') or line:match('^- %[(.)%]')
|
||||
if not ch then
|
||||
return nil
|
||||
end
|
||||
if ch == 'x' then
|
||||
return 'done'
|
||||
elseif ch == '>' then
|
||||
return 'wip'
|
||||
elseif ch == '=' then
|
||||
return 'blocked'
|
||||
end
|
||||
return 'pending'
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@return nil
|
||||
function M.reapply_dirty_inline(bufnr)
|
||||
|
|
@ -191,6 +208,10 @@ function M.reapply_dirty_inline(bufnr)
|
|||
local icons = config.get().icons
|
||||
for row in pairs(_dirty_rows) do
|
||||
local m = _meta[row]
|
||||
if m and m.type == 'task' then
|
||||
local line = vim.api.nvim_buf_get_lines(bufnr, row - 1, row, false)[1] or ''
|
||||
m.status = infer_status(line) or m.status
|
||||
end
|
||||
if m then
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, row - 1, row)
|
||||
apply_inline_row(bufnr, row - 1, m, icons)
|
||||
|
|
@ -345,8 +366,25 @@ function M.open_line(above)
|
|||
end
|
||||
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||
local insert_row = above and (row - 1) or row
|
||||
local meta_pos = insert_row + 1
|
||||
|
||||
_rendering = true
|
||||
vim.bo[bufnr].modifiable = true
|
||||
vim.api.nvim_buf_set_lines(bufnr, insert_row, insert_row, false, { '- [ ] ' })
|
||||
_rendering = false
|
||||
|
||||
table.insert(_meta, meta_pos, { type = 'task' })
|
||||
|
||||
local icons = config.get().icons
|
||||
local total = vim.api.nvim_buf_line_count(bufnr)
|
||||
for r = meta_pos, math.min(meta_pos + 1, total) do
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, r - 1, r)
|
||||
local m = _meta[r]
|
||||
if m then
|
||||
apply_inline_row(bufnr, r - 1, m, icons)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_win_set_cursor(0, { insert_row + 1, 6 })
|
||||
vim.cmd('startinsert!')
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue