mirror of
https://github.com/zed-industries/zed.git
synced 2024-10-27 00:41:37 +00:00
Toggle comments for empty single line selections
This commit is contained in:
parent
6304897abc
commit
a8d43c6d71
2 changed files with 52 additions and 1 deletions
|
@ -5480,7 +5480,7 @@ impl Editor {
|
|||
let mut all_selection_lines_are_comments = true;
|
||||
|
||||
for row in start_row..=end_row {
|
||||
if snapshot.is_line_blank(row) {
|
||||
if snapshot.is_line_blank(row) && start_row < end_row {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -4999,6 +4999,57 @@ async fn test_toggle_comment(cx: &mut gpui::TestAppContext) {
|
|||
"
|
||||
.unindent()
|
||||
);
|
||||
|
||||
// If a selection span a single line and is empty, the line is toggled.
|
||||
editor.set_text(
|
||||
"
|
||||
|
||||
fn a() { }
|
||||
|
||||
"
|
||||
.unindent(),
|
||||
cx,
|
||||
);
|
||||
editor.change_selections(None, cx, |s| {
|
||||
s.select_display_ranges([
|
||||
DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0),
|
||||
DisplayPoint::new(2, 0)..DisplayPoint::new(2, 0),
|
||||
])
|
||||
});
|
||||
editor.toggle_comments(&ToggleComments::default(), cx);
|
||||
assert_eq!(
|
||||
editor.text(cx),
|
||||
"
|
||||
//\x20
|
||||
fn a() { }
|
||||
//\x20
|
||||
"
|
||||
.unindent()
|
||||
);
|
||||
|
||||
// If a selection span multiple lines, empty lines are not toggled.
|
||||
editor.set_text(
|
||||
"
|
||||
|
||||
fn a() { }
|
||||
|
||||
"
|
||||
.unindent(),
|
||||
cx,
|
||||
);
|
||||
editor.change_selections(None, cx, |s| {
|
||||
s.select_display_ranges([DisplayPoint::new(0, 0)..DisplayPoint::new(2, 0)])
|
||||
});
|
||||
editor.toggle_comments(&ToggleComments::default(), cx);
|
||||
assert_eq!(
|
||||
editor.text(cx),
|
||||
"
|
||||
|
||||
// fn a() { }
|
||||
|
||||
"
|
||||
.unindent()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue