From 951fd1c80e9d8b39f16a8a86445263fb527d331d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Dzivjak?= Date: Fri, 25 Feb 2022 09:49:02 +0100 Subject: [PATCH] fix(commands): don't indent empty lines (#1653) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(commands): don't indent empty lines Fixes: https://github.com/helix-editor/helix/issues/1642 * Apply suggestions * Update helix-term/src/commands.rs * Update helix-term/src/commands.rs Co-authored-by: Blaž Hrastnik --- helix-term/src/commands.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index c4f25e888..3839cbe6a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4654,9 +4654,13 @@ fn indent(cx: &mut Context) { let transaction = Transaction::change( doc.text(), - lines.into_iter().map(|line| { + lines.into_iter().filter_map(|line| { + 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); - (pos, pos, Some(indent.clone())) + Some((pos, pos, Some(indent.clone()))) }), ); doc.apply(&transaction, view.id);