de-jcup / eclipse-yaml-editor

Eclipse YAML editor
https://marketplace.eclipse.org/content/yaml-editor
Apache License 2.0
35 stars 10 forks source link

Folding feature #31

Closed PyvesB closed 6 years ago

PyvesB commented 6 years ago

Hello @de-jcup,

Nice plugin! Just a quick suggestion: it would be great if the plugin could allow folding of indented blocks and lists. 😉

Thanks,

Pyves

de-jcup commented 6 years ago

Hello @PyvesB

normally I do not like code folding at all, but I often did not get all necessary information at one glance, but for yaml files It could be worthful because mostly there is too much information on screen.

So I will give it a try...

de-jcup commented 6 years ago

Hmm... a good Howto article found at https://www.eclipse.org/articles/Article-Folding-in-Eclipse-Text-Editors/folding.html

de-jcup commented 6 years ago

After long time having problems with nested foldings (I thought it would not be supported by standard behaviour) it turned out that it can work.

Example snippet from feature-branch try out:

Dummy text:

a23456789:
b23456789:
c23456789:
d23456789:
e23456789:
f23456789:
g23456789:

with folding positions defined as

SortedSet<FoldingPosition> positions = model.getFoldingPositions();
positions.add(new FoldingPosition(10,60-10));
positions.add(new FoldingPosition(30,50-30));

turns out as image

image

image

So

  1. folding icon starts at line of given position (here 10)
  2. to avoid both foldings shown when first folding is collapsed, the inner folding must be defined in a way thats start and end lines of folding are separated from outer lines, otherwise both folding icons are shown but inner one is not handling actions because inactive - not clear for users. So a folding position entry should only be created when there are at least 3 lines (one start, n to hide one end line).
de-jcup commented 6 years ago

Yaml entry folding should work then when the "3 line must" strategy is used: Example

a:
 b1:
   c1:
   c2:
   c3:
 b2:
   c4:
   c5:
d:
  e:

folding of a must contain line of d: to prevent double icons for b2: or c5

PyvesB commented 6 years ago

Thanks for documenting and sharing your findings!

de-jcup commented 6 years ago

Hmm.. I should give this attention again - but currently I am very busy...

de-jcup commented 6 years ago

Here an example:

image

PyvesB commented 6 years ago

Nice! Looking forward to testing this in the next release. 👍

de-jcup commented 6 years ago

Your are welcome :-)

de-jcup commented 6 years ago

Just released 1.0.0 on marketplace containing folding...

PyvesB commented 6 years ago

Just installed the update, everything seems to work as expected. Awesome job!