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:
2026-03-29 14:33:40 -05:00
parent 62a866d9bb
commit d90415bffc
5 changed files with 44 additions and 49 deletions

View File

@@ -13,6 +13,7 @@ from libs.event_factory import Event_Factory, Code_Event_Types
from plugins.plugin_types import PluginCode
from .fold_types import FOLD_NODES
from .folding_actions import collapse_range
from .folding_engine import get_folding_ranges
from .gutter_renderer import setup_gutter
@@ -34,6 +35,11 @@ class Plugin(PluginCode):
if file.ftype not in FOLD_NODES: return
if not hasattr(file, "ast"): return
buffer = file.buffer
if not buffer.get_tag_table().lookup("invisible"):
tag = buffer.create_tag("invisible")
tag.set_property("invisible", True)
self.update_gutter(file, self.view)
elif isinstance(event, Code_Event_Types.TextChangedEvent):
if event.file.ftype not in FOLD_NODES: return
@@ -78,21 +84,7 @@ class Plugin(PluginCode):
view.fold_update_source = GLib.timeout_add(delay, callback)
def update_gutter(self, file, view):
old_states = getattr(view, "fold_states", {})
view.fold_starts = get_folding_ranges(file.ftype, file.ast)
view.fold_starts = get_folding_ranges(file.ftype, file.ast)
view.fold_start_set = {
fold["start_line"] for fold in view.fold_starts
}
buffer = view.get_buffer()
if not buffer.get_tag_table().lookup("invisible"):
tag = buffer.create_tag("invisible")
tag.set_property("invisible", True)
new_states = {}
for fold in view.fold_starts:
if not fold["id"] in old_states: continue
new_states[fold["id"]] = old_states[fold["id"]]
view.fold_states = new_states