Skip to content

Commit

Permalink
fix(commands): don't indent empty lines (#1653)
Browse files Browse the repository at this point in the history
* fix(commands): don't indent empty lines

Fixes: #1642

* Apply suggestions

* Update helix-term/src/commands.rs

* Update helix-term/src/commands.rs

Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
  • Loading branch information
matoous and archseer authored Feb 25, 2022
1 parent 93ec42d commit 951fd1c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 951fd1c

Please # to comment.