fix: commenting full lines

pull/12759/head
Nikita Revenco 2025-02-03 13:03:28 +00:00 committed by Nik Revenco
parent 7d53290dd2
commit 99d16170dc
2 changed files with 62 additions and 4 deletions

View File

@ -137,10 +137,10 @@ pub fn toggle_line_comments(doc: &Rope, range: &Range, token: Option<&str>) -> V
let comment = Tendril::from(format!("{} ", token));
let start = text.char_to_line(range.from());
let end = text.char_to_line(range.to());
let start = start.clamp(0, text.len_lines());
let end = (end + 1).min(text.len_lines());
let end = text.char_to_line(range.to().saturating_sub(1));
let line_count = text.len_lines();
let start = start.clamp(0, line_count);
let end = (end + 1).min(line_count);
let mut lines = vec![];
lines.extend(start..end);

View File

@ -179,6 +179,64 @@ async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()
))
.await?;
// Full-line selection commenting
test((
indoc! {r#"\
<p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript">
// Comment toggle on this line should use the javascript comment token(s).
#[ foo();
css`
|]# html {
background-color: red;
}
`;
</script>
"#},
":lang html<ret> c",
indoc! {r#"\
<p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript">
// Comment toggle on this line should use the javascript comment token(s).
#[ // foo();
// css`
|]# html {
background-color: red;
}
`;
</script>
"#},
))
.await?;
test((
indoc! {r#"\
<p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript">
// Comment toggle on this line should use the javascript comment token(s).
#[ // foo();
// css`
|]# html {
background-color: red;
}
`;
</script>
"#},
":lang html<ret> c",
indoc! {r#"\
<p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript">
// Comment toggle on this line should use the javascript comment token(s).
#[ foo();
css`
|]# html {
background-color: red;
}
`;
</script>
"#},
))
.await?;
// Works with block comment toggle across different layers
test((
indoc! {r#"\