Fix due date not updating correctly when removing it

This commit is contained in:
Vyn 2025-07-04 10:29:26 +02:00
parent 048d835bd6
commit 6acb97df79
Signed by: vyn
GPG key ID: E1B2BE34E7A971E7
3 changed files with 33 additions and 26 deletions

View file

@ -110,18 +110,20 @@ std::string markdown_data_provider::to_markdown()
int next_task_index = 0;
int next_event_index = 0;
std::sort(_data.tasks.begin(), _data.tasks.end(), [](const task_data &t1, const task_data &t2) {
if (!t1.due_date.has_value() && !t2.due_date.has_value()) {
return false;
std::stable_sort(
_data.tasks.begin(), _data.tasks.end(), [](const task_data &t1, const task_data &t2) {
if (!t1.due_date.has_value() && !t2.due_date.has_value()) {
return false;
}
if (t1.due_date.has_value() && !t2.due_date.has_value()) {
return true;
}
if (!t1.due_date.has_value() && t2.due_date.has_value()) {
return false;
}
return t1.due_date < t2.due_date;
}
if (t1.due_date.has_value() && !t2.due_date.has_value()) {
return true;
}
if (!t1.due_date.has_value() && t2.due_date.has_value()) {
return false;
}
return t1.due_date < t2.due_date;
});
);
while (next_event_index < _data.events.size() || next_task_index < _data.tasks.size()) {
std::optional<class date> current_date = std::nullopt;

View file

@ -58,14 +58,13 @@ void task::set_title(const std::string &newTitle)
void task::set_date(const date &date)
{
auto emptyEventId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
data_->update_task(id(), {.due_date = date});
}
void task::unschedule()
{
auto emptyId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
data_->update_task(id(), {.due_date = std::nullopt});
const std::optional<date> new_date = std::nullopt;
data_->update_task(id(), {.due_date = new_date});
}
void task::set_checked(bool checked)