feat: resolve local review comments manually
This commit is contained in:
+50
-2
@@ -306,6 +306,8 @@ impl Editor {
|
||||
action,
|
||||
Action::ReviewEdit
|
||||
| Action::ReviewDelete
|
||||
| Action::ReviewResolve
|
||||
| Action::ReviewUnresolve
|
||||
| Action::ReviewVerdict
|
||||
| Action::ReviewSave
|
||||
| Action::ReviewOpen
|
||||
@@ -371,6 +373,40 @@ impl Editor {
|
||||
let id = self.review_comment_id(args)?;
|
||||
self.show_review_comment(id)?;
|
||||
}
|
||||
Action::ReviewResolve | Action::ReviewUnresolve => {
|
||||
let id = self.review_comment_id(args)?;
|
||||
let resolved = action == Action::ReviewResolve;
|
||||
let state = &mut self.review_diff_mut().unwrap().local_review;
|
||||
let comment = state
|
||||
.document
|
||||
.comments
|
||||
.iter_mut()
|
||||
.find(|comment| comment.id == id)
|
||||
.unwrap();
|
||||
if comment.resolved != resolved {
|
||||
comment.resolved = resolved;
|
||||
state.dirty = true;
|
||||
}
|
||||
let status = if resolved { "resolved" } else { "unresolved" };
|
||||
for buffer in std::iter::once(&mut self.active).chain(self.parked.values_mut()) {
|
||||
if let Some(binding) = buffer.review_buffer.as_mut()
|
||||
&& binding.owner == self.tab_id
|
||||
&& binding.kind == ReviewText::Comment(id)
|
||||
{
|
||||
binding.title = binding.title.replacen(
|
||||
if resolved {
|
||||
" · unresolved · "
|
||||
} else {
|
||||
" · resolved · "
|
||||
},
|
||||
&format!(" · {status} · "),
|
||||
1,
|
||||
);
|
||||
}
|
||||
}
|
||||
self.autosave_local_review()?;
|
||||
self.open_review_overview()?;
|
||||
}
|
||||
Action::ReviewDelete => {
|
||||
let id = self.review_comment_id(args)?;
|
||||
let state = &mut self.review_diff_mut().unwrap().local_review;
|
||||
@@ -562,6 +598,7 @@ impl Editor {
|
||||
id,
|
||||
anchor,
|
||||
body: String::new(),
|
||||
resolved: false,
|
||||
});
|
||||
state.dirty = true;
|
||||
self.show_review_comment(id)
|
||||
@@ -578,8 +615,13 @@ impl Editor {
|
||||
.ok_or("Comment no longer exists")?;
|
||||
let text = comment.body.clone();
|
||||
let anchor = &comment.anchor;
|
||||
let status = if comment.resolved {
|
||||
"resolved"
|
||||
} else {
|
||||
"unresolved"
|
||||
};
|
||||
let title = format!(
|
||||
"Comment #{id} · {}:{}:{}–{}:{} · {:?} · :w saves review",
|
||||
"Comment #{id} · {status} · {}:{}:{}–{}:{} · {:?} · :w saves review",
|
||||
anchor.path.display(),
|
||||
anchor.start.row + 1,
|
||||
anchor.start.column + 1,
|
||||
@@ -714,10 +756,15 @@ impl Editor {
|
||||
} else {
|
||||
"stale"
|
||||
};
|
||||
let resolution = if comment.resolved {
|
||||
"resolved"
|
||||
} else {
|
||||
"unresolved"
|
||||
};
|
||||
use std::fmt::Write as _;
|
||||
write!(
|
||||
text,
|
||||
"\n## Comment #{} · {status}\n{}:{}:{}–{}:{} · {:?}\nRevision: {}\n{}\n",
|
||||
"\n## Comment #{} · {resolution} · {status}\n{}:{}:{}–{}:{} · {:?}\nRevision: {}\n{}\n",
|
||||
comment.id,
|
||||
anchor.path.display(),
|
||||
anchor.start.row + 1,
|
||||
@@ -774,6 +821,7 @@ impl Editor {
|
||||
self.select_pane(panel);
|
||||
if let Some(id) = existing {
|
||||
self.switch_buffer(id);
|
||||
self.active.review_buffer.as_mut().unwrap().title = title;
|
||||
if matches!(kind, ReviewText::Overview | ReviewText::Reviews) {
|
||||
self.active.lines = split_lines(text);
|
||||
self.active.saved_lines.clone_from(&self.active.lines);
|
||||
|
||||
Reference in New Issue
Block a user