Skip to content

Commit

Permalink
fix #9
Browse files Browse the repository at this point in the history
Although I believe that this solution is not optimal,
I specified fold regions in a large package-lock json file,
and I didn't see any performance issues.
  • Loading branch information
predragnikolic committed Dec 12, 2023
1 parent 70dedd4 commit 1368fc2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,27 @@ def fold(view: sublime.View, fold_r: sublime.Region, preceding_text: Optional[st
view.fold(fold_r)


class FixFoldsWhenFormattingListener(sublime_plugin.TextChangeListener):
# Attempt to fix https://github.com/predragnikolic/InlineFold/issues/9
# This code here will try to detect if multiple lines were formatted
# and if so, it will retrigger the inline_fold_all.
def on_text_changed(self, changes: List[sublime.TextChange]):
if not self.buffer:
return
view = self.buffer.primary_view()
if not view:
return
for c in changes:
is_editing_multiple_lines = '\n' in c.str
if is_editing_multiple_lines:
def retrigger_fold():
# first unfold all - this might lead to unwanted behavoir
[view.unfold(r) for r in view.folded_regions()]
view.run_command('inline_fold_all')
sublime.set_timeout(retrigger_fold, 0)
break


def first_selection_region(view: sublime.View) -> Optional[sublime.Region]:
try:
return view.sel()[0]
Expand Down

0 comments on commit 1368fc2

Please sign in to comment.