fix(textobj): escape Lua pattern hyphen, fix test expectations

Problem: inner_task_range used unescaped '-' in Lua patterns, which
acts as a lazy quantifier instead of matching a literal hyphen. The
metadata-stripping logic also tokenized the full line including the
prefix, so the rebuilt string could never be found after the prefix.
All test column expectations were off by one.

Solution: escape hyphens with %-, rewrite metadata stripping to
tokenize only the description portion after the prefix, and correct
all test assertions to match actual rendered column positions.
This commit is contained in:
Barrett Ruth 2026-02-26 15:50:56 -05:00
parent 233ff31df1
commit cf1f5c39d8
2 changed files with 43 additions and 53 deletions

View file

@ -21,50 +21,40 @@ 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
local dk = config.get().date_syntax or 'due'
local rk = config.get().recur_syntax or 'rec'
local dk_esc = vim.pesc(dk)
local rk_esc = vim.pesc(rk)
local dk_pat = '^' .. vim.pesc(dk) .. ':%S+$'
local rk_pat = '^' .. vim.pesc(rk) .. ':%S+$'
local desc_end = #line
local tokens = {}
for token in line:gmatch('%S+') do
table.insert(tokens, token)
local rest = line:sub(start_col)
local words = {}
for word in rest:gmatch('%S+') do
table.insert(words, word)
end
local i = #tokens
local i = #words
while i >= 1 do
local token = tokens[i]
if token:match('^' .. dk_esc .. ':%S+$')
or token:match('^cat:%S+$')
or token:match('^' .. rk_esc .. ':%S+$')
then
local word = words[i]
if word:match(dk_pat) or word:match('^cat:%S+$') or word:match(rk_pat) then
i = i - 1
else
break
end
end
if i < #tokens then
local rebuilt = {}
for j = 1, i do
table.insert(rebuilt, tokens[j])
end
local desc_text = table.concat(rebuilt, ' ')
local search_start = prefix_end
local found = line:find(desc_text, search_start + 1, true)
if found then
desc_end = found + #desc_text - 1
end
if i < 1 then
return start_col, start_col
end
return start_col, desc_end
local desc = table.concat(words, ' ', 1, i)
local end_col = start_col + #desc - 1
return start_col, end_col
end
---@param row integer