mirror of https://github.com/helix-editor/helix
fix: incorrect order of index additions
parent
76b3e6778d
commit
bbd7cb7bfb
|
@ -251,6 +251,7 @@ pub fn create_block_comment_transaction(
|
||||||
changes.push((from + start_pos, keep_from, None));
|
changes.push((from + start_pos, keep_from, None));
|
||||||
let keep_until = from + end_pos - end_token.len() - end_margin as usize + 1;
|
let keep_until = from + end_pos - end_token.len() - end_margin as usize + 1;
|
||||||
changes.push((keep_until, from + end_pos + 1, None));
|
changes.push((keep_until, from + end_pos + 1, None));
|
||||||
|
// The range of characters keep_from..keep_until remain in the document
|
||||||
ranges.push(Range::new(keep_from, keep_until).with_direction(range.direction()));
|
ranges.push(Range::new(keep_from, keep_until).with_direction(range.direction()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -311,12 +312,12 @@ pub fn toggle_block_comments(
|
||||||
// to 1 element in `new_ranges`
|
// to 1 element in `new_ranges`
|
||||||
let (from, to, _) = changes[i * 2];
|
let (from, to, _) = changes[i * 2];
|
||||||
let (from2, to2, _) = changes[i * 2 + 1];
|
let (from2, to2, _) = changes[i * 2 + 1];
|
||||||
*added_chars -= to2 as isize - from2 as isize;
|
*added_chars -= to as isize - from as isize;
|
||||||
selections.push(Range::new(
|
selections.push(Range::new(
|
||||||
(range.anchor as isize + *added_chars).try_into().unwrap(),
|
(range.anchor as isize + *added_chars).try_into().unwrap(),
|
||||||
(range.head as isize + *added_chars).try_into().unwrap(),
|
(range.head as isize + *added_chars).try_into().unwrap(),
|
||||||
));
|
));
|
||||||
*added_chars -= to as isize - from as isize;
|
*added_chars -= to2 as isize - from2 as isize;
|
||||||
}
|
}
|
||||||
|
|
||||||
changes
|
changes
|
||||||
|
|
|
@ -852,6 +852,64 @@ async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// Many selections on the same line
|
||||||
|
test((
|
||||||
|
indoc! {r#"\
|
||||||
|
<p>C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(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>C#[|<!-- o -->]#mment t#(|<!-- o -->)#ggle #(|<!-- o -->)#n this line sh#(|<!-- o -->)#uld use the HTML c#(|<!-- o -->)#mment t#(|<!-- o -->)#ken(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>C#[|<!-- o -->]#mment t#(|<!-- o -->)#ggle #(|<!-- o -->)#n this line sh#(|<!-- o -->)#uld use the HTML c#(|<!-- o -->)#mment t#(|<!-- o -->)#ken(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>C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(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?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
lol.html
4
lol.html
|
@ -1,10 +1,10 @@
|
||||||
<!-- <p>Comment toggle on this line should use the HTML comment token(s).</p> -->
|
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// Comment toggle on this line should use the javascript comment token(s).
|
// Comment toggle on this line should use the javascript comment token(s).
|
||||||
foo();
|
foo();
|
||||||
css`
|
css`
|
||||||
html {
|
html {
|
||||||
background-color: #red;
|
background-color: red;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue