Improve code folding to exclude folding line breaks in whitespace-sensitive languages (#13108)
<img width="1219" alt="Screenshot 2024-06-16 at 15 43 31" src="https://github.com/zed-industries/zed/assets/87859239/dd05de16-7f20-4c88-9e95-021555b8b78b"> <img width="1219" alt="Screenshot 2024-06-16 at 15 45 10" src="https://github.com/zed-industries/zed/assets/87859239/b1b78cdd-f34d-4ea3-9728-4741727a9643"> Updated the foldable_range method to exclude folding line breaks during code folding in whitespace-sensitive languages like Python and YAML. This adjustment ensures that folding behaves as expected, similar to other code editors. Ref #11614 Release Notes: - Improved code folds to ignore trailing newlines
This commit is contained in:
parent
3076567f6b
commit
fefc91c6ad
2 changed files with 186 additions and 2 deletions
|
@ -983,8 +983,23 @@ impl DisplaySnapshot {
|
|||
break;
|
||||
}
|
||||
}
|
||||
let end = end.unwrap_or(max_point);
|
||||
Some((start..end, self.fold_placeholder.clone()))
|
||||
|
||||
let mut row_before_line_breaks = end.unwrap_or(max_point);
|
||||
while row_before_line_breaks.row > start.row
|
||||
&& self
|
||||
.buffer_snapshot
|
||||
.is_line_blank(MultiBufferRow(row_before_line_breaks.row))
|
||||
{
|
||||
row_before_line_breaks.row -= 1;
|
||||
}
|
||||
|
||||
row_before_line_breaks = Point::new(
|
||||
row_before_line_breaks.row,
|
||||
self.buffer_snapshot
|
||||
.line_len(MultiBufferRow(row_before_line_breaks.row)),
|
||||
);
|
||||
|
||||
Some((start..row_before_line_breaks, self.fold_placeholder.clone()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue