predragnikolic / InlineFold

A Sublime Text plugin that is useful to fold regions into a single line.
MIT License
7 stars 2 forks source link

Allow specifying a number of context lines per entry that should not be folded #4

Open FichteFoll opened 1 year ago

FichteFoll commented 1 year ago

With the changes to the Python default package, it is now possible to fold the non-summary parts of a docstring, i.e. everything but the first line. However, when the summary line is on the second line, it means that we have folded regions on both sides of a line that include newlines, which makes for a somewhat whacky experience when navigating the caret within the docstring. See the apng in the following PR for an example:

https://github.com/deathaxe/sublime-packages/pull/2#issuecomment-1446600538

gif

You can reproduce this by using the Python package from the Package's master branch and the following config:

    "inline_fold.rules":
    [
        {
            "fold_selector": "comment.block.documentation.python - punctuation.definition.comment",
        }
    ],

My proposal for this situation would be to add a configuration for context line where folding would not be applied for regions that are within n lines of the caret instead of on the same line as the caret.

Another idea related to this would be to unfold any regions that share a line with the currently active region (i.e. a region that would be folded if the caret wasn't inside it) and/or consider the additional config option here.

predragnikolic commented 1 year ago

closed with https://github.com/predragnikolic/InlineFold/commit/e3e007628391306e728446828fef7045c9b4495c

Regions that contain just strings will not be folded.(I try to avoid adding new settings)

predragnikolic commented 1 year ago

one additional thing, I did a breaking change 2 days ago https://github.com/predragnikolic/InlineFold/commit/8d47a4ecf15a2b6f1749896f3f674f7bcb353dc1

this plugin has no longer build in rules for tailwind classes to fold, users would have to explicitly add the rules themself in sublime preferences files.

FichteFoll commented 1 year ago

Regions that contain just strings will not be folded.

Hm, I don't really like this, unfortunately. The whitespace between the beginning of the string and the summary text on the second line leads to one unnecessary line being displayed.

I don't really see a way to go about this other than introducing a new setting, but instead of setting an arbitrary number of context lines (that will work for some cases but won't for others), perhaps it is possible to split the rules in a way that a user can select a region that should be considered for folding in general (here: source.python comment.block.documentation) but then only fold a sub-selector of this region (comment.block.documentation.python - punctuation.definition.comment or - comment.block.documentation.summary - punctuation.definition.comment). Once the caret is within the general region, i.e. the first selector, folding would be completely disabled for this region.

Just a quick idea off my head, though, as the code probably would probably become less elegant that way.

Another alternative would be a separate "disable for expanded selection" setting or similar that utilizes view.expand_to_scope to disable folding any region that intersects with it. That would definitely be simpler in code and potentially also easier to understand.