From b5b7da5214fd25d88d12614a4d74064046cdb813 Mon Sep 17 00:00:00 2001 From: Ben Trinh <6076614+huantrinh1802@users.noreply.github.com> Date: Mon, 22 Apr 2024 22:10:03 +1000 Subject: [PATCH] fix: corrected logic in apply_context_data function - Updated matching pattern for 'query' to replace single quotes with double - Added logic to extract UUID from the next line and add to 'tasks' - Modified the while loop condition and blocktermination check to handle edge cases - Optimized execution of 'taskwarrior' command by correcting string concatenation - Refactored variable increment and assignment process for improved readability --- lua/m_taskwarrior_d/utils.lua | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lua/m_taskwarrior_d/utils.lua b/lua/m_taskwarrior_d/utils.lua index 8881c38..8ae0a4a 100644 --- a/lua/m_taskwarrior_d/utils.lua +++ b/lua/m_taskwarrior_d/utils.lua @@ -379,29 +379,33 @@ end function M.apply_context_data(line, line_number) local _, query = string.match(line, M["task_query_pattern"].lua) - query = query.gsub(query, 'status:.*%s', ' ') + query = query.gsub(query, "status:.*%s", " ") local count = 1 local uuid = nil local tasks = {} - local next_line, next_line_number = M.get_line(line_number+count) + local next_line, next_line_number = M.get_line(line_number + count) + _, uuid = M.extract_uuid(next_line) + if uuid then + table.insert(tasks, uuid) + end local block_ended = true - if #next_line == 0 or next_line == ' ' then + if #next_line == 0 or next_line == " " then block_ended = false end local no_of_lines = vim.api.nvim_buf_line_count(0) while not block_ended and next_line_number <= no_of_lines do + count = count + 1 + next_line, next_line_number = M.get_line(line_number + count) + if next_line_number == no_of_lines or #next_line == 0 or next_line == " " then + block_ended = true + end _, uuid = M.extract_uuid(next_line) if uuid then table.insert(tasks, uuid) end - count = count + 1 - next_line, next_line_number = M.get_line(line_number+count) - if next_line == ' ' then - block_ended = true - end end for _, task_uuid in ipairs(tasks) do - require("m_taskwarrior_d.task").execute_taskwarrior_command("task "..task_uuid.." mod "..query) + require("m_taskwarrior_d.task").execute_taskwarrior_command("task " .. task_uuid .. " mod " .. query) end end