From 98e4abffc7887c427e7242ee4cd76e4baab9667a Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Sun, 15 Mar 2026 13:22:01 -0400 Subject: [PATCH] fix(buffer): conceal in all modes, forge EOL labels, remove dash prefix (#167) * fix(buffer): keep conceal active in all modes and add `%l` EOL forge labels Problem: `concealcursor` was missing `i` and `v`, so concealed text (task IDs, forge tokens) leaked in insert and visual modes. Forge labels only rendered for the first span when multiple refs existed. Solution: set `concealcursor = 'nicv'` to keep conceal in all modes. Add `%l` EOL format specifier that renders all forge spans with independent highlights. Update default `eol_format` to include `%l`. * refactor: remove `- ` prefix from task line rendering Problem: task lines rendered as `- [ ] description` with a redundant markdown list marker prefix that added visual noise. Solution: render task lines as `[ ] description` instead. Update all line generation in `views.lua`, parsing patterns in `buffer.lua`, `diff.lua`, `textobj.lua`, syntax rules, and corresponding specs. --- doc/pending.txt | 10 ++--- lua/pending/buffer.lua | 39 ++++++++++++------ lua/pending/config.lua | 2 +- lua/pending/diff.lua | 8 ++-- lua/pending/textobj.lua | 4 +- lua/pending/views.lua | 8 ++-- spec/complete_spec.lua | 46 ++++++++++----------- spec/diff_spec.lua | 66 +++++++++++++++---------------- spec/filter_spec.lua | 8 ++-- spec/forge_spec.lua | 8 ++-- spec/textobj_spec.lua | 88 ++++++++++++++++++++--------------------- spec/views_spec.lua | 10 ++--- 12 files changed, 156 insertions(+), 141 deletions(-) diff --git a/doc/pending.txt b/doc/pending.txt index 752f6f1..29f4e9f 100644 --- a/doc/pending.txt +++ b/doc/pending.txt @@ -901,12 +901,13 @@ Fields: ~ The view to use when the buffer is opened for the first time in a session. - {eol_format} (string, default: '%c %r %d') + {eol_format} (string, default: '%c %r %d %l') Format string for end-of-line virtual text. Specifiers: `%c` category icon + name (`PendingHeader`) `%r` recurrence icon + pattern (`PendingRecur`) `%d` due icon + date (`PendingDue`/`PendingOverdue`) + `%l` forge link label (`PendingForge`/`PendingForgeClosed`) Literal text between specifiers acts as a separator. Absent fields and surrounding literals are collapsed automatically. `%c` @@ -1572,10 +1573,9 @@ Example: > < On `:w`, the forge reference stays in the description and is also stored in -the task's `_extra._forge_ref` field. The raw token is visually replaced -inline with a formatted label using overlay extmarks (same technique as -checkbox icons). Multiple forge references in one line are each overlaid -independently. +the task's `_extra._forge_ref` field. The raw token is concealed in the +buffer and a formatted label appears at the end of the line via the `%l` +EOL format specifier. Format string: ~ *pending-forge-format* diff --git a/lua/pending/buffer.lua b/lua/pending/buffer.lua index 04bebd9..474dca9 100644 --- a/lua/pending/buffer.lua +++ b/lua/pending/buffer.lua @@ -183,14 +183,10 @@ local function apply_inline_row(bufnr, row, m, icons) invalidate = true, }) if m.forge_spans then - local forge = require('pending.forge') for _, span in ipairs(m.forge_spans) do - local label_text, hl_group = forge.format_label(span.ref, span.cache) vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, span.col_start, { end_col = span.col_end, conceal = '', - virt_text = { { label_text, hl_group } }, - virt_text_pos = 'inline', priority = 90, invalidate = true, }) @@ -215,7 +211,7 @@ end ---@param line string ---@return string? local function infer_status(line) - local ch = line:match('^/%d+/%- %[(.)%]') or line:match('^%- %[(.)%]') + local ch = line:match('^/%d+/%[(.)%]') or line:match('^%[(.)%]') if not ch then return nil end @@ -399,7 +395,7 @@ end ---@param winid integer local function set_win_options(winid) vim.wo[winid].conceallevel = 3 - vim.wo[winid].concealcursor = 'nc' + vim.wo[winid].concealcursor = 'nicv' vim.wo[winid].winfixheight = true end @@ -411,7 +407,7 @@ local function setup_syntax(bufnr) syntax match taskId /^\/\d\+\// conceal syntax match taskHeader /^# .*$/ contains=taskId syntax match taskCheckbox /\[!\]/ contained containedin=taskLine - syntax match taskLine /^\/\d\+\/- \[.\] .*$/ contains=taskId,taskCheckbox + syntax match taskLine /^\/\d\+\/\[.\] .*$/ contains=taskId,taskCheckbox ]]) end) end @@ -429,7 +425,7 @@ function M.open_line(above) _rendering = true vim.bo[bufnr].modifiable = true - vim.api.nvim_buf_set_lines(bufnr, insert_row, insert_row, false, { '- [ ] ' }) + vim.api.nvim_buf_set_lines(bufnr, insert_row, insert_row, false, { '[ ] ' }) _rendering = false table.insert(_meta, meta_pos, { type = 'task' }) @@ -444,7 +440,7 @@ function M.open_line(above) end end - vim.api.nvim_win_set_cursor(0, { insert_row + 1, 6 }) + vim.api.nvim_win_set_cursor(0, { insert_row + 1, 4 }) vim.cmd('startinsert!') end @@ -478,7 +474,7 @@ local function parse_eol_format(fmt) while pos <= len do if fmt:sub(pos, pos) == '%' and pos + 1 <= len then local key = fmt:sub(pos + 1, pos + 1) - if key == 'c' or key == 'r' or key == 'd' then + if key == 'c' or key == 'r' or key == 'd' or key == 'l' then table.insert(segments, { type = 'specifier', key = key }) pos = pos + 2 else @@ -514,8 +510,21 @@ local function build_eol_virt(segments, m, icons) elseif seg.key == 'd' and m.due then text = icons.due .. ' ' .. m.due hl = due_hl + elseif seg.key == 'l' and m.forge_spans and #m.forge_spans > 0 then + local forge = require('pending.forge') + local parts = {} + for j, span in ipairs(m.forge_spans) do + local lt, lh = forge.format_label(span.ref, span.cache) + if j > 1 then + table.insert(parts, { text = ' ', hl = 'Normal' }) + end + table.insert(parts, { text = lt, hl = lh }) + end + resolved[i] = { multi = parts, present = true } + end + if not resolved[i] then + resolved[i] = text and { text = text, hl = hl, present = true } or { present = false } end - resolved[i] = text and { text = text, hl = hl, present = true } or { present = false } else resolved[i] = { text = seg.text, hl = 'Normal', literal = true } end @@ -533,7 +542,13 @@ local function build_eol_virt(segments, m, icons) table.insert(virt_parts, pending_sep) pending_sep = nil end - table.insert(virt_parts, { r.text, r.hl }) + if r.multi then + for _, part in ipairs(r.multi) do + table.insert(virt_parts, { part.text, part.hl }) + end + else + table.insert(virt_parts, { r.text, r.hl }) + end else pending_sep = nil end diff --git a/lua/pending/config.lua b/lua/pending/config.lua index 9351b75..a8fb181 100644 --- a/lua/pending/config.lua +++ b/lua/pending/config.lua @@ -131,7 +131,7 @@ local defaults = { max_priority = 3, view = { default = 'category', - eol_format = '%c %r %d', + eol_format = '%c %r %d %l', category = { order = {}, folding = true, diff --git a/lua/pending/diff.lua b/lua/pending/diff.lua index fd00c0e..d4d2223 100644 --- a/lua/pending/diff.lua +++ b/lua/pending/diff.lua @@ -35,16 +35,16 @@ function M.parse_buffer(lines) for i = start, #lines do local line = lines[i] - local id, body = line:match('^/(%d+)/(- %[.?%] .*)$') + local id, body = line:match('^/(%d+)/(%[.?%] .*)$') if not id then - body = line:match('^(- %[.?%] .*)$') + body = line:match('^(%[.?%] .*)$') end if line == '' then table.insert(result, { type = 'blank', lnum = i }) elseif id or body then - local stripped = body:match('^- %[.?%] (.*)$') or body + local stripped = body:match('^%[.?%] (.*)$') or body local icons = config.get().icons - local state_char = body:match('^- %[(.-)%]') or icons.pending + local state_char = body:match('^%[(.-)%]') or icons.pending local priority = state_char == icons.priority and 1 or 0 local status if state_char == icons.done then diff --git a/lua/pending/textobj.lua b/lua/pending/textobj.lua index 887ef8f..d175141 100644 --- a/lua/pending/textobj.lua +++ b/lua/pending/textobj.lua @@ -28,9 +28,9 @@ end ---@return integer start_col ---@return integer end_col function M.inner_task_range(line) - local prefix_end = line:find('/') and select(2, line:find('^/%d+/%- %[.%] ')) + local prefix_end = line:find('/') and select(2, line:find('^/%d+/%[.%] ')) if not prefix_end then - prefix_end = select(2, line:find('^%- %[.%] ')) or 0 + prefix_end = select(2, line:find('^%[.%] ')) or 0 end local start_col = prefix_end + 1 diff --git a/lua/pending/views.lua b/lua/pending/views.lua index 3dbd06f..1f40ace 100644 --- a/lua/pending/views.lua +++ b/lua/pending/views.lua @@ -263,8 +263,8 @@ function M.category_view(tasks) for _, task in ipairs(all) do local prefix = '/' .. task.id .. '/' local state = state_char(task) - local line = prefix .. '- [' .. state .. '] ' .. task.description - local prefix_len = #prefix + #('- [' .. state .. '] ') + local line = prefix .. '[' .. state .. '] ' .. task.description + local prefix_len = #prefix + #('[' .. state .. '] ') table.insert(lines, line) table.insert(meta, { type = 'task', @@ -320,8 +320,8 @@ function M.priority_view(tasks) for _, task in ipairs(all) do local prefix = '/' .. task.id .. '/' local state = state_char(task) - local line = prefix .. '- [' .. state .. '] ' .. task.description - local prefix_len = #prefix + #('- [' .. state .. '] ') + local line = prefix .. '[' .. state .. '] ' .. task.description + local prefix_len = #prefix + #('[' .. state .. '] ') table.insert(lines, line) table.insert(meta, { type = 'task', diff --git a/spec/complete_spec.lua b/spec/complete_spec.lua index 98547e8..023e7cc 100644 --- a/spec/complete_spec.lua +++ b/spec/complete_spec.lua @@ -27,39 +27,39 @@ describe('complete', function() describe('findstart', function() it('returns column after colon for cat: prefix', function() local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '- [ ] task cat:Wo' }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '[ ] task cat:Wo' }) vim.api.nvim_set_current_buf(bufnr) - vim.api.nvim_win_set_cursor(0, { 1, 16 }) + vim.api.nvim_win_set_cursor(0, { 1, 14 }) local result = complete.omnifunc(1, '') - assert.are.equal(15, result) + assert.are.equal(13, result) vim.api.nvim_buf_delete(bufnr, { force = true }) end) it('returns column after colon for due: prefix', function() local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '- [ ] task due:to' }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '[ ] task due:to' }) vim.api.nvim_set_current_buf(bufnr) - vim.api.nvim_win_set_cursor(0, { 1, 16 }) + vim.api.nvim_win_set_cursor(0, { 1, 14 }) local result = complete.omnifunc(1, '') - assert.are.equal(15, result) + assert.are.equal(13, result) vim.api.nvim_buf_delete(bufnr, { force = true }) end) it('returns column after colon for rec: prefix', function() local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '- [ ] task rec:we' }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '[ ] task rec:we' }) vim.api.nvim_set_current_buf(bufnr) - vim.api.nvim_win_set_cursor(0, { 1, 16 }) + vim.api.nvim_win_set_cursor(0, { 1, 14 }) local result = complete.omnifunc(1, '') - assert.are.equal(15, result) + assert.are.equal(13, result) vim.api.nvim_buf_delete(bufnr, { force = true }) end) it('returns -1 for non-token position', function() local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '- [ ] some task ' }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '[ ] some task ' }) vim.api.nvim_set_current_buf(bufnr) - vim.api.nvim_win_set_cursor(0, { 1, 14 }) + vim.api.nvim_win_set_cursor(0, { 1, 12 }) local result = complete.omnifunc(1, '') assert.are.equal(-1, result) vim.api.nvim_buf_delete(bufnr, { force = true }) @@ -72,9 +72,9 @@ describe('complete', function() s:add({ description = 'B', category = 'Home' }) s:add({ description = 'C', category = 'Work' }) local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '- [ ] task cat: x' }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '[ ] task cat: x' }) vim.api.nvim_set_current_buf(bufnr) - vim.api.nvim_win_set_cursor(0, { 1, 15 }) + vim.api.nvim_win_set_cursor(0, { 1, 13 }) complete.omnifunc(1, '') local result = complete.omnifunc(0, '') local words = {} @@ -90,9 +90,9 @@ describe('complete', function() s:add({ description = 'A', category = 'Work' }) s:add({ description = 'B', category = 'Home' }) local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '- [ ] task cat:W' }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '[ ] task cat:W' }) vim.api.nvim_set_current_buf(bufnr) - vim.api.nvim_win_set_cursor(0, { 1, 15 }) + vim.api.nvim_win_set_cursor(0, { 1, 13 }) complete.omnifunc(1, '') local result = complete.omnifunc(0, 'W') assert.are.equal(1, #result) @@ -102,9 +102,9 @@ describe('complete', function() it('returns named dates for due:', function() local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '- [ ] task due: x' }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '[ ] task due: x' }) vim.api.nvim_set_current_buf(bufnr) - vim.api.nvim_win_set_cursor(0, { 1, 15 }) + vim.api.nvim_win_set_cursor(0, { 1, 13 }) complete.omnifunc(1, '') local result = complete.omnifunc(0, '') assert.is_true(#result > 0) @@ -120,9 +120,9 @@ describe('complete', function() it('filters dates by base prefix', function() local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '- [ ] task due:to' }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '[ ] task due:to' }) vim.api.nvim_set_current_buf(bufnr) - vim.api.nvim_win_set_cursor(0, { 1, 16 }) + vim.api.nvim_win_set_cursor(0, { 1, 14 }) complete.omnifunc(1, '') local result = complete.omnifunc(0, 'to') local words = {} @@ -137,9 +137,9 @@ describe('complete', function() it('returns recurrence shorthands for rec:', function() local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '- [ ] task rec: x' }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '[ ] task rec: x' }) vim.api.nvim_set_current_buf(bufnr) - vim.api.nvim_win_set_cursor(0, { 1, 15 }) + vim.api.nvim_win_set_cursor(0, { 1, 13 }) complete.omnifunc(1, '') local result = complete.omnifunc(0, '') assert.is_true(#result > 0) @@ -155,9 +155,9 @@ describe('complete', function() it('filters recurrence by base prefix', function() local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '- [ ] task rec:we' }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '[ ] task rec:we' }) vim.api.nvim_set_current_buf(bufnr) - vim.api.nvim_win_set_cursor(0, { 1, 16 }) + vim.api.nvim_win_set_cursor(0, { 1, 14 }) complete.omnifunc(1, '') local result = complete.omnifunc(0, 'we') local words = {} diff --git a/spec/diff_spec.lua b/spec/diff_spec.lua index b69bd5a..56a97d0 100644 --- a/spec/diff_spec.lua +++ b/spec/diff_spec.lua @@ -22,11 +22,11 @@ describe('diff', function() it('parses headers and tasks', function() local lines = { '# School', - '/1/- [ ] Do homework', - '/2/- [!] Read chapter 5', + '/1/[ ] Do homework', + '/2/[!] Read chapter 5', '', '# Errands', - '/3/- [ ] Buy groceries', + '/3/[ ] Buy groceries', } local result = diff.parse_buffer(lines) assert.are.equal(6, #result) @@ -45,7 +45,7 @@ describe('diff', function() it('handles new tasks without ids', function() local lines = { '# Inbox', - '- [ ] New task here', + '[ ] New task here', } local result = diff.parse_buffer(lines) assert.are.equal(2, #result) @@ -57,7 +57,7 @@ describe('diff', function() it('inline cat: token overrides header category', function() local lines = { '# Inbox', - '/1/- [ ] Buy milk cat:Work', + '/1/[ ] Buy milk cat:Work', } local result = diff.parse_buffer(lines) assert.are.equal(2, #result) @@ -68,7 +68,7 @@ describe('diff', function() it('extracts rec: token from buffer line', function() local lines = { '# Inbox', - '/1/- [ ] Take trash out rec:weekly', + '/1/[ ] Take trash out rec:weekly', } local result = diff.parse_buffer(lines) assert.are.equal('weekly', result[2].recur) @@ -77,7 +77,7 @@ describe('diff', function() it('extracts rec: with completion mode', function() local lines = { '# Inbox', - '/1/- [ ] Water plants rec:!daily', + '/1/[ ] Water plants rec:!daily', } local result = diff.parse_buffer(lines) assert.are.equal('daily', result[2].recur) @@ -87,7 +87,7 @@ describe('diff', function() it('inline due: token is parsed', function() local lines = { '# Inbox', - '/1/- [ ] Buy milk due:2026-03-15', + '/1/[ ] Buy milk due:2026-03-15', } local result = diff.parse_buffer(lines) assert.are.equal(2, #result) @@ -100,8 +100,8 @@ describe('diff', function() it('creates new tasks from buffer lines', function() local lines = { '# Inbox', - '- [ ] First task', - '- [ ] Second task', + '[ ] First task', + '[ ] Second task', } diff.apply(lines, s) s:load() @@ -117,7 +117,7 @@ describe('diff', function() s:save() local lines = { '# Inbox', - '/1/- [ ] Keep me', + '/1/[ ] Keep me', } diff.apply(lines, s) s:load() @@ -133,7 +133,7 @@ describe('diff', function() s:save() local lines = { '# Inbox', - '/1/- [ ] Renamed', + '/1/[ ] Renamed', } diff.apply(lines, s) s:load() @@ -147,7 +147,7 @@ describe('diff', function() s:save() local lines = { '# Inbox', - '/1/- [ ] Renamed', + '/1/[ ] Renamed', } diff.apply(lines, s) s:load() @@ -161,8 +161,8 @@ describe('diff', function() s:save() local lines = { '# Inbox', - '/1/- [ ] Original', - '/1/- [ ] Copy of original', + '/1/[ ] Original', + '/1/[ ] Copy of original', } diff.apply(lines, s) s:load() @@ -175,7 +175,7 @@ describe('diff', function() s:save() local lines = { '# Work', - '/1/- [ ] Moving task', + '/1/[ ] Moving task', } diff.apply(lines, s) s:load() @@ -188,7 +188,7 @@ describe('diff', function() s:save() local lines = { '# Inbox', - '/1/- [ ] Stable task', + '/1/[ ] Stable task', } diff.apply(lines, s) s:load() @@ -204,7 +204,7 @@ describe('diff', function() s:save() local lines = { '# Inbox', - '/1/- [ ] Pay bill', + '/1/[ ] Pay bill', } diff.apply(lines, s) s:load() @@ -217,7 +217,7 @@ describe('diff', function() s:save() local lines = { '# Inbox', - '/1/- [ ] Pay bill due:2026-04-01', + '/1/[ ] Pay bill due:2026-04-01', } diff.apply(lines, s) s:load() @@ -228,7 +228,7 @@ describe('diff', function() it('stores recur field on new tasks from buffer', function() local lines = { '# Inbox', - '- [ ] Take out trash rec:weekly', + '[ ] Take out trash rec:weekly', } diff.apply(lines, s) s:load() @@ -242,7 +242,7 @@ describe('diff', function() s:save() local lines = { '# Todo', - '/1/- [ ] Task rec:weekly', + '/1/[ ] Task rec:weekly', } diff.apply(lines, s) s:load() @@ -255,7 +255,7 @@ describe('diff', function() s:save() local lines = { '# Todo', - '/1/- [ ] Task', + '/1/[ ] Task', } diff.apply(lines, s) s:load() @@ -266,7 +266,7 @@ describe('diff', function() it('parses rec: with completion mode prefix', function() local lines = { '# Inbox', - '- [ ] Water plants rec:!weekly', + '[ ] Water plants rec:!weekly', } diff.apply(lines, s) s:load() @@ -278,7 +278,7 @@ describe('diff', function() it('returns forge refs for new tasks', function() local lines = { '# Inbox', - '- [ ] Fix bug gh:user/repo#42', + '[ ] Fix bug gh:user/repo#42', } local refs = diff.apply(lines, s) assert.are.equal(1, #refs) @@ -303,7 +303,7 @@ describe('diff', function() s:save() local lines = { '# Todo', - '/1/- [ ] Fix bug gh:user/repo#99', + '/1/[ ] Fix bug gh:user/repo#99', } local refs = diff.apply(lines, s) assert.are.equal(1, #refs) @@ -327,7 +327,7 @@ describe('diff', function() s:save() local lines = { '# Todo', - '/1/- [ ] Fix bug gh:user/repo#42', + '/1/[ ] Fix bug gh:user/repo#42', } local refs = diff.apply(lines, s) assert.are.equal(0, #refs) @@ -336,7 +336,7 @@ describe('diff', function() it('returns empty for tasks without forge refs', function() local lines = { '# Inbox', - '- [ ] Plain task', + '[ ] Plain task', } local refs = diff.apply(lines, s) assert.are.equal(0, #refs) @@ -359,8 +359,8 @@ describe('diff', function() s:save() local lines = { '# Todo', - '/1/- [ ] Fix bug gh:user/repo#42', - '/1/- [ ] Fix bug gh:user/repo#42', + '/1/[ ] Fix bug gh:user/repo#42', + '/1/[ ] Fix bug gh:user/repo#42', } local refs = diff.apply(lines, s) assert.are.equal(1, #refs) @@ -372,7 +372,7 @@ describe('diff', function() s:save() local lines = { '# Inbox', - '/1/- [ ] Task name', + '/1/[ ] Task name', } diff.apply(lines, s) s:load() @@ -383,7 +383,7 @@ describe('diff', function() it('sets priority from +!! token', function() local lines = { '# Inbox', - '- [ ] Pay bills +!!', + '[ ] Pay bills +!!', } diff.apply(lines, s) s:load() @@ -396,7 +396,7 @@ describe('diff', function() s:save() local lines = { '# Inbox', - '/1/- [!] Task name', + '/1/[!] Task name', } diff.apply(lines, s) s:load() @@ -407,7 +407,7 @@ describe('diff', function() it('parses metadata with forge ref on same line', function() local lines = { '# Inbox', - '- [ ] Fix bug due:2026-03-15 gh:user/repo#42', + '[ ] Fix bug due:2026-03-15 gh:user/repo#42', } diff.apply(lines, s) s:load() diff --git a/spec/filter_spec.lua b/spec/filter_spec.lua index 5e00b60..b226249 100644 --- a/spec/filter_spec.lua +++ b/spec/filter_spec.lua @@ -230,7 +230,7 @@ describe('filter', function() end local hidden_ids = { [hidden_task.id] = true } local lines = { - '/1/- [ ] Visible task', + '/1/[ ] Visible task', } diff.apply(lines, s, hidden_ids) s:load() @@ -254,7 +254,7 @@ describe('filter', function() end end local lines = { - '/' .. keep_task.id .. '/- [ ] Keep task', + '/' .. keep_task.id .. '/[ ] Keep task', } diff.apply(lines, s, {}) s:load() @@ -270,7 +270,7 @@ describe('filter', function() local task = tasks[1] local lines = { 'FILTER: cat:Work', - '/' .. task.id .. '/- [ ] My task', + '/' .. task.id .. '/[ ] My task', } diff.apply(lines, s, {}) s:load() @@ -281,7 +281,7 @@ describe('filter', function() it('parse_buffer skips FILTER: header line', function() local lines = { 'FILTER: overdue', - '/1/- [ ] A task', + '/1/[ ] A task', } local result = diff.parse_buffer(lines) assert.are.equal(1, #result) diff --git a/spec/forge_spec.lua b/spec/forge_spec.lua index ab8d5c4..d249857 100644 --- a/spec/forge_spec.lua +++ b/spec/forge_spec.lua @@ -590,7 +590,7 @@ describe('forge diff integration', function() local tmp = os.tmpname() local s = store.new(tmp) s:load() - diff.apply({ '- [ ] Fix bug gh:user/repo#42' }, s) + diff.apply({ '[ ] Fix bug gh:user/repo#42' }, s) local tasks = s:active_tasks() assert.equals(1, #tasks) assert.equals('Fix bug gh:user/repo#42', tasks[1].description) @@ -607,7 +607,7 @@ describe('forge diff integration', function() s:load() local task = s:add({ description = 'Fix bug' }) s:save() - diff.apply({ '/' .. task.id .. '/- [ ] Fix bug gh:user/repo#10' }, s) + diff.apply({ '/' .. task.id .. '/[ ] Fix bug gh:user/repo#10' }, s) local updated = s:get(task.id) assert.equals('Fix bug gh:user/repo#10', updated.description) assert.is_not_nil(updated._extra) @@ -634,7 +634,7 @@ describe('forge diff integration', function() }, }) s:save() - diff.apply({ '/' .. task.id .. '/- [ ] Fix bug' }, s) + diff.apply({ '/' .. task.id .. '/[ ] Fix bug' }, s) local updated = s:get(task.id) assert.is_not_nil(updated._extra._forge_ref) assert.equals(1, updated._extra._forge_ref.number) @@ -645,7 +645,7 @@ describe('forge diff integration', function() local tmp = os.tmpname() local s = store.new(tmp) s:load() - diff.apply({ '- [ ] Check out gh:user/repo' }, s) + diff.apply({ '[ ] Check out gh:user/repo' }, s) local tasks = s:active_tasks() assert.equals(1, #tasks) assert.is_not_nil(tasks[1]._extra) diff --git a/spec/textobj_spec.lua b/spec/textobj_spec.lua index 1253f58..5ec3e8a 100644 --- a/spec/textobj_spec.lua +++ b/spec/textobj_spec.lua @@ -17,92 +17,92 @@ describe('textobj', function() describe('inner_task_range', function() it('returns description range for task with id prefix', function() - local s, e = textobj.inner_task_range('/1/- [ ] Buy groceries') - assert.are.equal(10, s) - assert.are.equal(22, e) + local s, e = textobj.inner_task_range('/1/[ ] Buy groceries') + assert.are.equal(8, s) + assert.are.equal(20, e) end) it('returns description range for task without id prefix', function() - local s, e = textobj.inner_task_range('- [ ] Buy groceries') - assert.are.equal(7, s) - assert.are.equal(19, e) + local s, e = textobj.inner_task_range('[ ] Buy groceries') + assert.are.equal(5, s) + assert.are.equal(17, e) end) it('excludes trailing due: token', function() - local s, e = textobj.inner_task_range('/1/- [ ] Buy groceries due:2026-03-15') - assert.are.equal(10, s) - assert.are.equal(22, e) + local s, e = textobj.inner_task_range('/1/[ ] Buy groceries due:2026-03-15') + assert.are.equal(8, s) + assert.are.equal(20, e) end) it('excludes trailing cat: token', function() - local s, e = textobj.inner_task_range('/1/- [ ] Buy groceries cat:Errands') - assert.are.equal(10, s) - assert.are.equal(22, e) + local s, e = textobj.inner_task_range('/1/[ ] Buy groceries cat:Errands') + assert.are.equal(8, s) + assert.are.equal(20, e) end) it('excludes trailing rec: token', function() - local s, e = textobj.inner_task_range('/1/- [ ] Take out trash rec:weekly') - assert.are.equal(10, s) - assert.are.equal(23, e) + local s, e = textobj.inner_task_range('/1/[ ] Take out trash rec:weekly') + assert.are.equal(8, s) + assert.are.equal(21, e) end) it('excludes multiple trailing metadata tokens', function() local s, e = - textobj.inner_task_range('/1/- [ ] Buy milk due:2026-03-15 cat:Errands rec:weekly') - assert.are.equal(10, s) - assert.are.equal(17, e) + textobj.inner_task_range('/1/[ ] Buy milk due:2026-03-15 cat:Errands rec:weekly') + assert.are.equal(8, s) + assert.are.equal(15, e) end) it('handles priority checkbox', function() - local s, e = textobj.inner_task_range('/1/- [!] Important task') - assert.are.equal(10, s) - assert.are.equal(23, e) + local s, e = textobj.inner_task_range('/1/[!] Important task') + assert.are.equal(8, s) + assert.are.equal(21, e) end) it('handles done checkbox', function() - local s, e = textobj.inner_task_range('/1/- [x] Finished task') - assert.are.equal(10, s) - assert.are.equal(22, e) - end) - - it('handles multi-digit task ids', function() - local s, e = textobj.inner_task_range('/123/- [ ] Some task') - assert.are.equal(12, s) + local s, e = textobj.inner_task_range('/1/[x] Finished task') + assert.are.equal(8, s) assert.are.equal(20, e) end) - it('does not strip non-metadata tokens', function() - local s, e = textobj.inner_task_range('/1/- [ ] Buy groceries for dinner') + it('handles multi-digit task ids', function() + local s, e = textobj.inner_task_range('/123/[ ] Some task') assert.are.equal(10, s) - assert.are.equal(33, e) + assert.are.equal(18, e) + end) + + it('does not strip non-metadata tokens', function() + local s, e = textobj.inner_task_range('/1/[ ] Buy groceries for dinner') + assert.are.equal(8, s) + assert.are.equal(31, e) end) it('stops stripping at first non-metadata token from right', function() - local s, e = textobj.inner_task_range('/1/- [ ] Buy groceries for dinner due:2026-03-15') - assert.are.equal(10, s) - assert.are.equal(33, e) + local s, e = textobj.inner_task_range('/1/[ ] Buy groceries for dinner due:2026-03-15') + assert.are.equal(8, s) + assert.are.equal(31, e) end) it('respects custom date_syntax', function() vim.g.pending = { date_syntax = 'by' } config.reset() - local s, e = textobj.inner_task_range('/1/- [ ] Buy groceries by:2026-03-15') - assert.are.equal(10, s) - assert.are.equal(22, e) + local s, e = textobj.inner_task_range('/1/[ ] Buy groceries by:2026-03-15') + assert.are.equal(8, s) + assert.are.equal(20, e) end) it('respects custom recur_syntax', function() vim.g.pending = { recur_syntax = 'repeat' } config.reset() - local s, e = textobj.inner_task_range('/1/- [ ] Take trash repeat:weekly') - assert.are.equal(10, s) - assert.are.equal(19, e) + local s, e = textobj.inner_task_range('/1/[ ] Take trash repeat:weekly') + assert.are.equal(8, s) + assert.are.equal(17, e) end) it('handles task with only metadata after description', function() - local s, e = textobj.inner_task_range('/1/- [ ] X due:tomorrow') - assert.are.equal(10, s) - assert.are.equal(10, e) + local s, e = textobj.inner_task_range('/1/[ ] X due:tomorrow') + assert.are.equal(8, s) + assert.are.equal(8, e) end) end) diff --git a/spec/views_spec.lua b/spec/views_spec.lua index e841deb..e84cc1e 100644 --- a/spec/views_spec.lua +++ b/spec/views_spec.lua @@ -112,10 +112,10 @@ describe('views', function() task_line = lines[i] end end - assert.are.equal('/1/- [ ] My task', task_line) + assert.are.equal('/1/[ ] My task', task_line) end) - it('formats priority task lines as /ID/- [!] description', function() + it('formats priority task lines as /ID/[!] description', function() s:add({ description = 'Important', category = 'Inbox', priority = 1 }) local lines, meta = views.category_view(s:active_tasks()) local task_line @@ -124,7 +124,7 @@ describe('views', function() task_line = lines[i] end end - assert.are.equal('/1/- [!] Important', task_line) + assert.are.equal('/1/[!] Important', task_line) end) it('sets LineMeta type=header for header lines with correct category', function() @@ -352,10 +352,10 @@ describe('views', function() assert.is_true(earlier_row < later_row) end) - it('formats task lines as /ID/- [ ] description', function() + it('formats task lines as /ID/[ ] description', function() s:add({ description = 'My task', category = 'Inbox' }) local lines, _ = views.priority_view(s:active_tasks()) - assert.are.equal('/1/- [ ] My task', lines[1]) + assert.are.equal('/1/[ ] My task', lines[1]) end) it('sets show_category=true for all task meta entries', function()