Revert "feat(diff): disallow editing done tasks by default (#132)"
This reverts commit 24e8741ae1.
This commit is contained in:
parent
8e1795a1f2
commit
013bb198ae
3 changed files with 76 additions and 148 deletions
|
|
@ -1,6 +1,5 @@
|
|||
local config = require('pending.config')
|
||||
local forge = require('pending.forge')
|
||||
local log = require('pending.log')
|
||||
local parse = require('pending.parse')
|
||||
|
||||
---@class pending.ParsedEntry
|
||||
|
|
@ -103,91 +102,14 @@ function M.apply(lines, s, hidden_ids)
|
|||
local order_counter = 0
|
||||
|
||||
for _, entry in ipairs(parsed) do
|
||||
if entry.type == 'task' then
|
||||
order_counter = order_counter + 1
|
||||
if entry.type ~= 'task' then
|
||||
goto continue
|
||||
end
|
||||
|
||||
if entry.id and old_by_id[entry.id] then
|
||||
if seen_ids[entry.id] then
|
||||
s:add({
|
||||
description = entry.description,
|
||||
category = entry.category,
|
||||
priority = entry.priority,
|
||||
due = entry.due,
|
||||
recur = entry.rec,
|
||||
recur_mode = entry.rec_mode,
|
||||
order = order_counter,
|
||||
_extra = entry.forge_ref and { _forge_ref = entry.forge_ref } or nil,
|
||||
})
|
||||
else
|
||||
seen_ids[entry.id] = true
|
||||
local task = old_by_id[entry.id]
|
||||
if
|
||||
config.get().lock_done
|
||||
and task.status == 'done'
|
||||
and entry.status == 'done'
|
||||
then
|
||||
if task.order ~= order_counter then
|
||||
task.order = order_counter
|
||||
task.modified = now
|
||||
end
|
||||
log.warn('cannot edit done task — toggle status first')
|
||||
else
|
||||
local changed = false
|
||||
if task.description ~= entry.description then
|
||||
task.description = entry.description
|
||||
changed = true
|
||||
end
|
||||
if task.category ~= entry.category then
|
||||
task.category = entry.category
|
||||
changed = true
|
||||
end
|
||||
if entry.priority == 0 and task.priority > 0 then
|
||||
task.priority = 0
|
||||
changed = true
|
||||
elseif entry.priority > 0 and task.priority == 0 then
|
||||
task.priority = entry.priority
|
||||
changed = true
|
||||
end
|
||||
if entry.due ~= nil and task.due ~= entry.due then
|
||||
task.due = entry.due
|
||||
changed = true
|
||||
end
|
||||
if entry.rec ~= nil then
|
||||
if task.recur ~= entry.rec then
|
||||
task.recur = entry.rec
|
||||
changed = true
|
||||
end
|
||||
if task.recur_mode ~= entry.rec_mode then
|
||||
task.recur_mode = entry.rec_mode
|
||||
changed = true
|
||||
end
|
||||
end
|
||||
if entry.forge_ref ~= nil then
|
||||
if not task._extra then
|
||||
task._extra = {}
|
||||
end
|
||||
task._extra._forge_ref = entry.forge_ref
|
||||
changed = true
|
||||
end
|
||||
if entry.status and task.status ~= entry.status then
|
||||
task.status = entry.status
|
||||
if entry.status == 'done' then
|
||||
task['end'] = now
|
||||
else
|
||||
task['end'] = nil
|
||||
end
|
||||
changed = true
|
||||
end
|
||||
if task.order ~= order_counter then
|
||||
task.order = order_counter
|
||||
changed = true
|
||||
end
|
||||
if changed then
|
||||
task.modified = now
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
order_counter = order_counter + 1
|
||||
|
||||
if entry.id and old_by_id[entry.id] then
|
||||
if seen_ids[entry.id] then
|
||||
s:add({
|
||||
description = entry.description,
|
||||
category = entry.category,
|
||||
|
|
@ -198,8 +120,77 @@ function M.apply(lines, s, hidden_ids)
|
|||
order = order_counter,
|
||||
_extra = entry.forge_ref and { _forge_ref = entry.forge_ref } or nil,
|
||||
})
|
||||
else
|
||||
seen_ids[entry.id] = true
|
||||
local task = old_by_id[entry.id]
|
||||
local changed = false
|
||||
if task.description ~= entry.description then
|
||||
task.description = entry.description
|
||||
changed = true
|
||||
end
|
||||
if task.category ~= entry.category then
|
||||
task.category = entry.category
|
||||
changed = true
|
||||
end
|
||||
if entry.priority == 0 and task.priority > 0 then
|
||||
task.priority = 0
|
||||
changed = true
|
||||
elseif entry.priority > 0 and task.priority == 0 then
|
||||
task.priority = entry.priority
|
||||
changed = true
|
||||
end
|
||||
if entry.due ~= nil and task.due ~= entry.due then
|
||||
task.due = entry.due
|
||||
changed = true
|
||||
end
|
||||
if entry.rec ~= nil then
|
||||
if task.recur ~= entry.rec then
|
||||
task.recur = entry.rec
|
||||
changed = true
|
||||
end
|
||||
if task.recur_mode ~= entry.rec_mode then
|
||||
task.recur_mode = entry.rec_mode
|
||||
changed = true
|
||||
end
|
||||
end
|
||||
if entry.forge_ref ~= nil then
|
||||
if not task._extra then
|
||||
task._extra = {}
|
||||
end
|
||||
task._extra._forge_ref = entry.forge_ref
|
||||
changed = true
|
||||
end
|
||||
if entry.status and task.status ~= entry.status then
|
||||
task.status = entry.status
|
||||
if entry.status == 'done' then
|
||||
task['end'] = now
|
||||
else
|
||||
task['end'] = nil
|
||||
end
|
||||
changed = true
|
||||
end
|
||||
if task.order ~= order_counter then
|
||||
task.order = order_counter
|
||||
changed = true
|
||||
end
|
||||
if changed then
|
||||
task.modified = now
|
||||
end
|
||||
end
|
||||
else
|
||||
s:add({
|
||||
description = entry.description,
|
||||
category = entry.category,
|
||||
priority = entry.priority,
|
||||
due = entry.due,
|
||||
recur = entry.rec,
|
||||
recur_mode = entry.rec_mode,
|
||||
order = order_counter,
|
||||
_extra = entry.forge_ref and { _forge_ref = entry.forge_ref } or nil,
|
||||
})
|
||||
end
|
||||
|
||||
::continue::
|
||||
end
|
||||
|
||||
for id, task in pairs(old_by_id) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue