Fold/toggle header

Hi!

I come from Notion, and one of the features that i most use is the toggle header (aka folding), in which i can insert content with a title (header) and toggle it at will for more readability.

image

Is there anything like this on SB? I noticed that there’s an “outline: fold” command, but it’s not really readable and not clickable…
I can probably invest some time in developing this, but wanted to be sure that i didn’t missed it.

Thank you!

5 Likes

I initially thought meh but then immediately wanted this feature. Useful to set default for the page in frontmatter?

2 Likes

I think there are two ingredients in here, that SB is missing:

My huge vote on persistent folding. This, plus keyboard shortcuts would get us 99% there in terms of usability.

Let’s see how the issue unfolds :smile:

@nickb on the front matter case, there is a partial solve, hiding it with space-style, see here

4 Likes

This is a huge point for me too. I’m currently splitting my knowledgebase where I need one to be self hosted / private. I really want to use silverbullet. But for the life of me I can’t get used to non outliners (this is no silberbullet critique). Folding headers would help a lot with the transition.

(I think there is also a bug that you can’t collapse images with the current shortcut implementation)

1 Like

Could something like an auto-fold for frontmatter be done via a plugin technically?

I think so, you can listen to the editor:pageLoaded event, retrieve the current cursor position with editor.getCursor() move the cursor to position 0 with editor.moveCursor and then run the editor.fold() syscall, and then move the cursor back to the original position. that should do it. You can even do this in Space Script, no need for a plug.

```space-script
silverbullet.registerEventListener({name: "editor:pageLoaded"}, async () => {
  const text = await editor.getText();
  if(!text.startsWith("---")) {
    console.log("No frontmatter, skipping folding");
    return;
  }
  const pos = await editor.getCursor();
  await editor.moveCursor(0);
  await editor.fold();
  await editor.moveCursor(pos);
  console.log("Folded frontmatter.")
});
```

Seems to do it. It may have a side effect of always scrolling the page a bit, depending on the cursor position, but perhaps that’s acceptable.

4 Likes

Oh my god how crazy is Silverbullet? Incredible! This totally works. I am so happy that Silverbullet is that scriptable. Also thank you for already writing this script. When I got the mail notification I already was happy to read in the preview that it’s possible. Now I found time looking into the forum and you already wrote the script and made it public here. Thank you so much for your help and your time! (=

Edit: Besides: I see no scroll jumping or so. At least on my system here the site loads and the frontmatter is folded already. It does not even flicker or similar. Wonderful!

2 Likes