Fix annotation editing to use denotate+annotate instead of modifying in plac
This commit is contained in:
@@ -30,11 +30,15 @@ pub(super) struct AnnotationView {
|
|||||||
pub(super) origin: AnnotationOrigin,
|
pub(super) origin: AnnotationOrigin,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub(super) enum AnnotationOrigin {
|
pub(super) enum AnnotationOrigin {
|
||||||
Original,
|
Original,
|
||||||
Added,
|
Added,
|
||||||
Deleted,
|
Deleted,
|
||||||
|
Modified {
|
||||||
|
original_entry: DateTime<Utc>,
|
||||||
|
original_text: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn annotation_id(entry: DateTime<Utc>, text: &str, index: usize) -> AnnotationId {
|
fn annotation_id(entry: DateTime<Utc>, text: &str, index: usize) -> AnnotationId {
|
||||||
@@ -96,4 +100,21 @@ impl AnnotationState {
|
|||||||
item.origin = AnnotationOrigin::Deleted;
|
item.origin = AnnotationOrigin::Deleted;
|
||||||
Some(item.created_at)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,6 +226,13 @@ pub(super) fn build_task_update(
|
|||||||
update.annotations_delete.push(annotation.created_at);
|
update.annotations_delete.push(annotation.created_at);
|
||||||
}
|
}
|
||||||
AnnotationOrigin::Original => {}
|
AnnotationOrigin::Original => {}
|
||||||
|
AnnotationOrigin::Modified {
|
||||||
|
original_entry,
|
||||||
|
original_text: _,
|
||||||
|
} => {
|
||||||
|
update.annotations_delete.push(original_entry);
|
||||||
|
update.annotations_add.push(annotation.text.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1708,24 +1708,50 @@ impl TaskDetailModal {
|
|||||||
if i < visible.len() {
|
if i < visible.len() {
|
||||||
let (actual_index, ann) = visible[i];
|
let (actual_index, ann) = visible[i];
|
||||||
|
|
||||||
if ann.origin == AnnotationOrigin::Added {
|
match ann.origin {
|
||||||
self.state.inline_edit =
|
AnnotationOrigin::Added => {
|
||||||
Some(InlineEditTarget::Annotation(actual_index));
|
self.state.inline_edit =
|
||||||
|
Some(InlineEditTarget::Annotation(actual_index));
|
||||||
|
|
||||||
let ann_value = ann.text.to_string();
|
let ann_value = ann.text.to_string();
|
||||||
self.entities.annotation_input.update(cx, |input, cx| {
|
self.entities.annotation_input.update(cx, |input, cx| {
|
||||||
input.set_value(ann_value, cx);
|
input.set_value(ann_value, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.enter_edit_field(window, cx);
|
self.enter_edit_field(window, cx);
|
||||||
|
|
||||||
return CommandResult::Handled;
|
return CommandResult::Handled;
|
||||||
} else {
|
}
|
||||||
let toast_host = cx.global::<ToastGlobal>().host.clone();
|
AnnotationOrigin::Original => {
|
||||||
cx.update_entity(&toast_host, |host, cx| {
|
let ann_id = ann.id;
|
||||||
host.push(ToastKind::Error, "Cannot edit original annotations", cx);
|
let ann_value = ann.text.to_string();
|
||||||
});
|
self.state.annotations.mark_modified(ann_id);
|
||||||
return CommandResult::Handled;
|
|
||||||
|
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 => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user