From 2d694ee0163f89b453166a3c23ce28fcb9d477d1 Mon Sep 17 00:00:00 2001 From: Ignacio Perez Date: Sun, 4 Jan 2026 16:48:06 -0300 Subject: [PATCH] Fix annotation editing to use denotate+annotate instead of modifying in plac --- src/view/task_detail_modal/annotations.rs | 23 +++++++++- src/view/task_detail_modal/form.rs | 7 +++ src/view/task_detail_modal/mod.rs | 56 +++++++++++++++++------ 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/src/view/task_detail_modal/annotations.rs b/src/view/task_detail_modal/annotations.rs index aa9bad5..0526fe6 100644 --- a/src/view/task_detail_modal/annotations.rs +++ b/src/view/task_detail_modal/annotations.rs @@ -30,11 +30,15 @@ pub(super) struct AnnotationView { pub(super) origin: AnnotationOrigin, } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub(super) enum AnnotationOrigin { Original, Added, Deleted, + Modified { + original_entry: DateTime, + original_text: String, + }, } fn annotation_id(entry: DateTime, text: &str, index: usize) -> AnnotationId { @@ -96,4 +100,21 @@ impl AnnotationState { item.origin = AnnotationOrigin::Deleted; Some(item.created_at) } + + pub(super) fn mark_modified(&mut self, id: AnnotationId) -> bool { + if let Some(index) = self.items.iter().position(|item| item.id == id) { + let item = &mut self.items[index]; + match item.origin { + AnnotationOrigin::Original => { + item.origin = AnnotationOrigin::Modified { + original_entry: item.created_at, + original_text: item.text.to_string(), + }; + return true; + } + _ => return false, + } + } + false + } } diff --git a/src/view/task_detail_modal/form.rs b/src/view/task_detail_modal/form.rs index 3f38c0c..0f90a20 100644 --- a/src/view/task_detail_modal/form.rs +++ b/src/view/task_detail_modal/form.rs @@ -226,6 +226,13 @@ pub(super) fn build_task_update( update.annotations_delete.push(annotation.created_at); } AnnotationOrigin::Original => {} + AnnotationOrigin::Modified { + original_entry, + original_text: _, + } => { + update.annotations_delete.push(original_entry); + update.annotations_add.push(annotation.text.to_string()); + } } } diff --git a/src/view/task_detail_modal/mod.rs b/src/view/task_detail_modal/mod.rs index 4dcc9c7..b82c81b 100644 --- a/src/view/task_detail_modal/mod.rs +++ b/src/view/task_detail_modal/mod.rs @@ -1708,24 +1708,50 @@ impl TaskDetailModal { if i < visible.len() { let (actual_index, ann) = visible[i]; - if ann.origin == AnnotationOrigin::Added { - self.state.inline_edit = - Some(InlineEditTarget::Annotation(actual_index)); + match ann.origin { + AnnotationOrigin::Added => { + self.state.inline_edit = + Some(InlineEditTarget::Annotation(actual_index)); - let ann_value = ann.text.to_string(); - self.entities.annotation_input.update(cx, |input, cx| { - input.set_value(ann_value, cx); - }); + let ann_value = ann.text.to_string(); + self.entities.annotation_input.update(cx, |input, cx| { + input.set_value(ann_value, cx); + }); - self.enter_edit_field(window, cx); + self.enter_edit_field(window, cx); - return CommandResult::Handled; - } else { - let toast_host = cx.global::().host.clone(); - cx.update_entity(&toast_host, |host, cx| { - host.push(ToastKind::Error, "Cannot edit original annotations", cx); - }); - return CommandResult::Handled; + return CommandResult::Handled; + } + AnnotationOrigin::Original => { + let ann_id = ann.id; + let ann_value = ann.text.to_string(); + self.state.annotations.mark_modified(ann_id); + + self.state.inline_edit = + Some(InlineEditTarget::Annotation(actual_index)); + + self.entities.annotation_input.update(cx, |input, cx| { + input.set_value(ann_value, cx); + }); + + self.enter_edit_field(window, cx); + + return CommandResult::Handled; + } + AnnotationOrigin::Modified { .. } => { + self.state.inline_edit = + Some(InlineEditTarget::Annotation(actual_index)); + + let ann_value = ann.text.to_string(); + self.entities.annotation_input.update(cx, |input, cx| { + input.set_value(ann_value, cx); + }); + + self.enter_edit_field(window, cx); + + return CommandResult::Handled; + } + AnnotationOrigin::Deleted => {} } } }