Unnamed repository; edit this file 'description' to name the repository.
fix: trim whitespace up to the last selection on insert_newline (#13673)
Ryan Mehri 9 months ago
parent 1ea9050 · commit 6c43dc4
-rw-r--r--helix-term/src/commands.rs4
-rw-r--r--helix-term/tests/test/commands/insert.rs12
2 files changed, 15 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 604d6924..44633741 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -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() {
diff --git a/helix-term/tests/test/commands/insert.rs b/helix-term/tests/test/commands/insert.rs
index edec192c..9499868e 100644
--- a/helix-term/tests/test/commands/insert.rs
+++ b/helix-term/tests/test/commands/insert.rs
@@ -173,6 +173,18 @@ async fn insert_newline_trim_trailing_whitespace() -> anyhow::Result<()> {
}
#[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
test((