Skip to content

Commit 51f5393

Browse files
fix: indent command with spaces
Adjust the number of spaces to align indentation on columns.
1 parent 4c288a4 commit 51f5393

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

helix-term/src/commands.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4875,7 +4875,16 @@ fn indent(cx: &mut Context) {
48754875
return None;
48764876
}
48774877
let pos = doc.text().line_to_char(line);
4878-
Some((pos, pos, Some(indent.clone())))
4878+
4879+
let indent = if let IndentStyle::Spaces(indent_width) = doc.indent_style {
4880+
let line = doc.text().line(line);
4881+
let offset = line.first_non_whitespace_char().unwrap_or(0) % indent_width as usize;
4882+
indent.clone().split_off(offset)
4883+
} else {
4884+
indent.clone()
4885+
};
4886+
4887+
Some((pos, pos, Some(indent)))
48794888
}),
48804889
);
48814890
doc.apply(&transaction, view.id);

helix-term/tests/test/commands/insert.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ async fn test_jump_undo_redo() -> anyhow::Result<()> {
585585
}
586586

587587
#[tokio::test(flavor = "multi_thread")]
588-
async fn test_spaces_alignment_on_insert_tab() -> anyhow::Result<()> {
588+
async fn test_indent_with_spaces() -> anyhow::Result<()> {
589589
let tests = vec![
590590
// at start of line
591591
(
@@ -615,6 +615,22 @@ async fn test_spaces_alignment_on_insert_tab() -> anyhow::Result<()> {
615615
WHERE #(|condition)#
616616
"},
617617
),
618+
// indentation in normal mode
619+
(
620+
indoc! {"\
621+
-- comment
622+
#[|SELECT *
623+
FROM table
624+
WHERE condition]#
625+
"},
626+
"<gt>",
627+
indoc! {"\
628+
-- comment
629+
#[|SELECT *
630+
FROM table
631+
WHERE condition]#
632+
"},
633+
),
618634
];
619635

620636
for test in tests {

0 commit comments

Comments
 (0)