Add FoldFunctionBodies editor action (#21504)
Related to #19424 This uses the new text object support, so will only work for languages that have `textobjects.scm`. It does not integrate with indentation-based folding for now, and the syntax-based folds don't have matching fold markers in the gutter (unless they are folded). Release Notes: - Add an editor action to fold all function bodies Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
parent
ce5f492404
commit
c5d15fd065
4 changed files with 27 additions and 0 deletions
|
@ -11097,6 +11097,23 @@ impl Editor {
|
|||
self.fold_creases(fold_ranges, true, cx);
|
||||
}
|
||||
|
||||
pub fn fold_function_bodies(
|
||||
&mut self,
|
||||
_: &actions::FoldFunctionBodies,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let snapshot = self.buffer.read(cx).snapshot(cx);
|
||||
let Some((_, _, buffer)) = snapshot.as_singleton() else {
|
||||
return;
|
||||
};
|
||||
let creases = buffer
|
||||
.function_body_fold_ranges(0..buffer.len())
|
||||
.map(|range| Crease::simple(range, self.display_map.read(cx).fold_placeholder.clone()))
|
||||
.collect();
|
||||
|
||||
self.fold_creases(creases, true, cx);
|
||||
}
|
||||
|
||||
pub fn fold_recursive(&mut self, _: &actions::FoldRecursive, cx: &mut ViewContext<Self>) {
|
||||
let mut to_fold = Vec::new();
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue