fix: preserve review comments across unrelated edits
This commit is contained in:
+34
-27
@@ -2160,38 +2160,45 @@ impl DiffState {
|
||||
lines
|
||||
}
|
||||
|
||||
pub fn review_anchor_current(&self, anchor: &crate::review::Anchor) -> bool {
|
||||
pub fn review_anchor_range(
|
||||
&self,
|
||||
anchor: &crate::review::Anchor,
|
||||
) -> Option<std::ops::Range<crate::plugin::TextPosition>> {
|
||||
use crate::review::Side;
|
||||
let Some(comparison) = &self.comparison else {
|
||||
return false;
|
||||
return None;
|
||||
};
|
||||
if self.local_review.document.root != comparison.root {
|
||||
return false;
|
||||
return None;
|
||||
}
|
||||
comparison.files.iter().enumerate().any(|(index, file)| {
|
||||
if !file.loaded || file.notice.is_some() {
|
||||
return false;
|
||||
}
|
||||
let (path, lines, eof) = match anchor.side {
|
||||
Side::Before => (
|
||||
file.old_path.as_deref().unwrap_or(&file.path),
|
||||
&file.before,
|
||||
file.before_eof,
|
||||
),
|
||||
Side::After => (
|
||||
file.path.as_path(),
|
||||
&file.after,
|
||||
file.after_eof && !self.live_files.contains(&index),
|
||||
),
|
||||
};
|
||||
anchor.matches_lines(
|
||||
&comparison.revisions[anchor.side.index()],
|
||||
path,
|
||||
anchor.side,
|
||||
lines,
|
||||
eof,
|
||||
)
|
||||
})
|
||||
comparison
|
||||
.files
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find_map(|(index, file)| {
|
||||
if !file.loaded || file.notice.is_some() {
|
||||
return None;
|
||||
}
|
||||
let (path, lines, eof) = match anchor.side {
|
||||
Side::Before => (
|
||||
file.old_path.as_deref().unwrap_or(&file.path),
|
||||
&file.before,
|
||||
file.before_eof,
|
||||
),
|
||||
Side::After => (
|
||||
file.path.as_path(),
|
||||
&file.after,
|
||||
file.after_eof && !self.live_files.contains(&index),
|
||||
),
|
||||
};
|
||||
anchor.mapped_range(
|
||||
&comparison.revisions[anchor.side.index()],
|
||||
path,
|
||||
anchor.side,
|
||||
lines,
|
||||
eof,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn corresponding_row(&self, from: Focus, to: Focus, row: usize) -> Option<usize> {
|
||||
|
||||
Reference in New Issue
Block a user