refactor(tasks): drop dead markdown branch from checklist reset

This commit is contained in:
kolaente 2026-06-19 16:34:44 +02:00
parent 409747eca0
commit 0e96074b84
2 changed files with 5 additions and 22 deletions

View File

@ -1748,18 +1748,16 @@ func setTaskDatesFromCurrentDateRepeat(oldTask, newTask *Task) {
}
var (
checklistTiptapCheckedRegex = regexp.MustCompile(`(data-checked=")true(")`)
checklistInputCheckedRegex = regexp.MustCompile(`(<input[^>]*type=["']checkbox["'][^>]*?)\s+checked(?:=["'][^"']*["'])?`)
checklistMarkdownCheckedRegex = regexp.MustCompile(`(?m)^(\s*[-*]\s+\[)[xX](\])`)
checklistTiptapCheckedRegex = regexp.MustCompile(`(data-checked=")true(")`)
checklistInputCheckedRegex = regexp.MustCompile(`(<input[^>]*type=["']checkbox["'][^>]*?)\s+checked(?:=["'][^"']*["'])?`)
)
// resetDescriptionChecklist unchecks every checklist item in a description without
// touching any other content. A recurring task carries its description verbatim into
// the next occurrence, so checked checklist items would otherwise stay checked.
// resetDescriptionChecklist unchecks every checklist item in a TipTap HTML description
// (descriptions are always stored as HTML, never markdown) without touching other content,
// so a recurring task's next occurrence does not inherit checked items.
func resetDescriptionChecklist(description string) string {
description = checklistTiptapCheckedRegex.ReplaceAllString(description, "${1}false${2}")
description = checklistInputCheckedRegex.ReplaceAllString(description, "$1")
description = checklistMarkdownCheckedRegex.ReplaceAllString(description, "$1 $2")
return description
}

View File

@ -1006,21 +1006,6 @@ func TestUpdateDone(t *testing.T) {
assert.True(t, newTask.DueDate.After(oldTask.DueDate))
assert.Equal(t, unchecked, newTask.Description)
})
t.Run("reset markdown checklist on recurrence", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
DueDate: time.Unix(1550000000, 0),
}
newTask := &Task{
Done: true,
Description: "- [x] one\n- [X] two\n- [ ] three\nnot a [x] checklist",
}
updateDone(oldTask, newTask)
assert.Equal(t, "- [ ] one\n- [ ] two\n- [ ] three\nnot a [x] checklist", newTask.Description)
})
t.Run("non-recurring description untouched", func(t *testing.T) {
const checked = `before<ul data-type="taskList"><li data-checked="true" data-type="taskItem"><label><input type="checkbox" checked="checked"><span></span></label><div><p>Item</p></li></ul>after`