mirror of https://github.com/helix-editor/helix
fix: trim whitespace up to the last selection on insert_newline (#13673)
parent
1ea9050a5e
commit
6c43dc4962
|
@ -4206,6 +4206,7 @@ pub mod insert {
|
|||
None
|
||||
};
|
||||
|
||||
let mut last_pos = 0;
|
||||
let mut transaction = Transaction::change_by_selection(contents, selection, |range| {
|
||||
// Tracks the number of trailing whitespace characters deleted by this selection.
|
||||
let mut chars_deleted = 0;
|
||||
|
@ -4227,7 +4228,8 @@ pub mod insert {
|
|||
let (from, to, local_offs) = if let Some(idx) =
|
||||
text.slice(line_start..pos).last_non_whitespace_char()
|
||||
{
|
||||
let first_trailing_whitespace_char = (line_start + idx + 1).min(pos);
|
||||
let first_trailing_whitespace_char = (line_start + idx + 1).clamp(last_pos, pos);
|
||||
last_pos = pos;
|
||||
let line = text.line(current_line);
|
||||
|
||||
let indent = match line.first_non_whitespace_char() {
|
||||
|
|
|
@ -172,6 +172,18 @@ async fn insert_newline_trim_trailing_whitespace() -> anyhow::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn insert_newline_trim_whitespace_to_previous_selection() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {"\"#[a|]# #(a|)# #(a|)#\""},
|
||||
"c<ret>",
|
||||
indoc! {"\"\n#[\n|]##(\n|)##(\"|)#"},
|
||||
))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn insert_newline_continue_line_comment() -> anyhow::Result<()> {
|
||||
// `insert_newline` continues a single line comment
|
||||
|
|
Loading…
Reference in New Issue