Fix: Improve code folding functionality and gutter rendering
- Updated folding actions and engine for more consistent behavior. - Added helper function `is_fold_hidden()` to check fold visibility state. - Improved gutter renderer to handle collapsible code blocks more reliably. - Refined tag handling for invisible folds to prevent desync issues. - Removed code fold Fix related entry in `TODO.md`.
This commit is contained in:
@@ -7,25 +7,26 @@ from .fold_types import FOLD_NODES
|
||||
|
||||
|
||||
|
||||
def visit_node(fold_types, node, ranges):
|
||||
if node.type in fold_types:
|
||||
start_line = node.start_point[0]
|
||||
end_line = node.end_point[0]
|
||||
|
||||
if end_line > start_line:
|
||||
ranges.append({
|
||||
"start_line": start_line,
|
||||
"end_line": end_line,
|
||||
"id": (start_line, end_line, node.type),
|
||||
})
|
||||
|
||||
for child in node.children:
|
||||
visit_node(fold_types, child, ranges)
|
||||
|
||||
def get_folding_ranges(lang_name: str, ast):
|
||||
root = ast.root_node
|
||||
fold_types = FOLD_NODES.get(lang_name, set())
|
||||
ranges = []
|
||||
|
||||
def visit(node):
|
||||
if node.type in fold_types:
|
||||
start_line = node.start_point[0]
|
||||
end_line = node.end_point[0]
|
||||
|
||||
if end_line > start_line:
|
||||
ranges.append({
|
||||
"start_line": start_line,
|
||||
"end_line": end_line,
|
||||
"id": (start_line, end_line, node.type),
|
||||
})
|
||||
|
||||
for child in node.children:
|
||||
visit(child)
|
||||
|
||||
visit(root)
|
||||
visit_node(fold_types, root, ranges)
|
||||
return ranges
|
||||
|
||||
|
||||
Reference in New Issue
Block a user