From 5ad261f1d55936467355a7ea67f278ba6795fe8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Dzivjak?= Date: Fri, 11 Feb 2022 15:15:30 +0100 Subject: [PATCH 1/4] fix(commands): don't indent empty lines Fixes: https://github.com/helix-editor/helix/issues/1642 --- helix-term/src/commands.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4cded7ef8cbd..308e869a8967 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4648,9 +4648,12 @@ fn indent(cx: &mut Context) { let transaction = Transaction::change( doc.text(), - lines.into_iter().map(|line| { + lines.into_iter().filter_map(|line| { + if doc.text().get_line(line).unwrap().as_str().unwrap().trim() == "" { + return None; + } let pos = doc.text().line_to_char(line); - (pos, pos, Some(indent.clone())) + Some((pos, pos, Some(indent.clone()))) }), ); doc.apply(&transaction, view.id); From 94cf7f64ba7d2a52fecda98d1aa692860f2996c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Dzivjak?= Date: Mon, 21 Feb 2022 22:53:32 +0100 Subject: [PATCH 2/4] Apply suggestions --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 308e869a8967..ee7868a60dce 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4649,7 +4649,7 @@ fn indent(cx: &mut Context) { let transaction = Transaction::change( doc.text(), lines.into_iter().filter_map(|line| { - if doc.text().get_line(line).unwrap().as_str().unwrap().trim() == "" { + if Cow::from(doc.text().line(line)).trim().is_empty() { return None; } let pos = doc.text().line_to_char(line); From 9e6c2181610eef4be0a7f914e6546383bbbf0d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Thu, 24 Feb 2022 11:15:15 +0900 Subject: [PATCH 3/4] Update helix-term/src/commands.rs --- helix-term/src/commands.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index ee7868a60dce..20f12e346d57 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4649,7 +4649,8 @@ fn indent(cx: &mut Context) { let transaction = Transaction::change( doc.text(), lines.into_iter().filter_map(|line| { - if Cow::from(doc.text().line(line)).trim().is_empty() { + let is_blank = doc.text().line(line).chunks().all(|s| s.trim().is_empty(); + if is_blank { return None; } let pos = doc.text().line_to_char(line); From 952dfa9b250f5f8075b5254369c2964206a0ebf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Thu, 24 Feb 2022 11:18:58 +0900 Subject: [PATCH 4/4] Update helix-term/src/commands.rs --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 20f12e346d57..a1fe9cef69a3 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4649,7 +4649,7 @@ fn indent(cx: &mut Context) { let transaction = Transaction::change( doc.text(), lines.into_iter().filter_map(|line| { - let is_blank = doc.text().line(line).chunks().all(|s| s.trim().is_empty(); + let is_blank = doc.text().line(line).chunks().all(|s| s.trim().is_empty()); if is_blank { return None; }