feat: anchor review comments to precise text ranges

This commit is contained in:
Valdemar Lorenzen
2026-10-16 14:45:43 +02:00
parent 9a24302b4e
commit 2259d61633
11 changed files with 687 additions and 74 deletions
+78 -1
View File
@@ -15990,6 +15990,82 @@ mod tests {
);
}
#[test]
fn precise_review_ranges_capture_graphemes_and_navigate_to_their_start() {
for focus in [Focus::Before, Focus::After] {
for keys in ["lvl", "llvh", "llvj"] {
let directory = Directory::new();
let root = directory.0.canonicalize().unwrap();
let mut editor = editor();
historical_diff(
&mut editor,
&root,
vec!["p界e\u{301}z".into(), "before".into()],
vec!["q界e\u{301}z".into(), "after!".into()],
);
editor.diff.as_mut().unwrap().focus = focus;
editor.bind_diff_buffer();
let owner = editor.pane_id();
type_text(&mut editor, keys);
type_text(&mut editor, ":diff.comment");
editor.handle(Input::Enter);
let diff = editor.workspace_diff().unwrap();
let anchor = &diff.local_review.document.comments[0].anchor;
let (start, end) = if keys == "llvj" {
(
TextPosition { row: 0, column: 2 },
TextPosition { row: 1, column: 3 },
)
} else {
(
TextPosition { row: 0, column: 1 },
TextPosition { row: 0, column: 3 },
)
};
assert_eq!(anchor.start, start);
assert_eq!(anchor.end, end);
assert!(diff.review_anchor_current(anchor));
editor.handle(Input::Escape);
assert_eq!(editor.pane_id(), owner);
assert_eq!(
editor.cursor(),
Cursor {
row: start.row,
column: start.column
}
);
}
}
for text in ["last", "one\nlast", "one\n", ""] {
let directory = Directory::new();
let root = directory.0.canonicalize().unwrap();
let mut editor = editor();
historical_diff(&mut editor, &root, vec!["before".into()], split_lines(text));
editor.diff.as_mut().unwrap().focus = Focus::After;
editor.bind_diff_buffer();
editor.execute("diff.comment");
let anchor = &editor
.workspace_diff()
.unwrap()
.local_review
.document
.comments[0]
.anchor;
assert_eq!(anchor.start, TextPosition { row: 0, column: 0 });
assert_eq!(
anchor.end,
if text.contains('\n') {
TextPosition { row: 1, column: 0 }
} else {
TextPosition {
row: 0,
column: grapheme_count(text),
}
}
);
}
}
#[test]
fn visual_commands_preserve_directed_ranges_on_cancel_and_plugin_dispatch() {
for shape in ["vll", "vhh", "Vj"] {
@@ -16059,7 +16135,8 @@ mod tests {
editor.handle(Input::Enter);
let diff = editor.workspace_diff().unwrap();
let anchor = diff.local_review.document.comments[0].anchor.clone();
assert_eq!((anchor.start_line, anchor.end_line), (1, 2));
assert_eq!(anchor.start, TextPosition { row: 0, column: 0 });
assert_eq!(anchor.end, TextPosition { row: 2, column: 0 });
assert_eq!(
anchor.side,
if focus == Focus::Before {