aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTriton1712022-08-11 08:56:19 +0000
committerBlaž Hrastnik2022-10-11 07:48:04 +0000
commit05832f90cbff18a8d8f0ccb6680cd74e19c75378 (patch)
tree082f573c20f9ef90bebfeafbeb9dc81f0f015d90
parent1ceecbd06246efeb3d56f778bc786958bf3f90f7 (diff)
Fix a bug that caused the indent for the line below to also be added in rare cases at the beginning of a file.
-rw-r--r--helix-core/src/indent.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs
index df69eb73..97fe00cd 100644
--- a/helix-core/src/indent.rs
+++ b/helix-core/src/indent.rs
@@ -662,7 +662,13 @@ pub fn treesitter_indent_for_pos(
node = parent;
first_in_line.pop();
} else {
- result.add_line(&indent_for_line_below);
+ // Only add the indentation for the line below if that line
+ // is not after the line that the indentation is calculated for.
+ if (node.start_position().row < line)
+ || (new_line && node.start_position().row == line && node.start_byte() < byte_pos)
+ {
+ result.add_line(&indent_for_line_below);
+ }
result.add_line(&indent_for_line);
break;
}