# Persistent folding: how to use space-style to hide a particular attribute?

**URL:** <https://community.silverbullet.md/t/persistent-folding-how-to-use-space-style-to-hide-a-particular-attribute/3663>\
**Category:** General\
**Created:** [December 25, 2025, 4:50am UTC](https://community.silverbullet.md/t/persistent-folding-how-to-use-space-style-to-hide-a-particular-attribute/3663 "2025-12-25T04:50:50Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Platinum](https://community.silverbullet.md/user_avatar/community.silverbullet.md/platinum/32/2510_2.png) [@Platinum](https://community.silverbullet.md/u/Platinum)\
**Post date:** [December 28, 2025, 10:47am UTC](https://community.silverbullet.md/t/persistent-folding-how-to-use-space-style-to-hide-a-particular-attribute/3663/10 "2025-12-28T10:47:31Z")

</div>

So I tried this to fold on page loads. Works well, except `editor.getCursor()` returns `nil`. So after the page loads, the cursor is not set by SB to its correct position, but remains at the last line that was folded. I don’t understand when and how SB sets the cursor position (to what it was when this page was last visited). Help appreciated.

```lua
event.listen{
  name = "editor:pageLoaded",
  run = function()
    local text = editor.getText()
    if not text then
      return
    end
  
    -- Save cursor position
    local originalCursor = editor.getCursor()
  
    local lineNum = 0
    for line in (text .. "\n"):gmatch("(.-)\n") do
      lineNum = lineNum + 1
  
      -- Simple substring match
      if line:find("[folded: true]", 1, true) then
        -- Move cursor to the line so the folding can be done
        editor.moveCursorToLine(lineNum, 1, false)
        
        -- Fold the block at cursor
        editor.fold()
      end
    end

    -- Restore cursor
    if originalCursor then
      editor.setCursor(originalCursor)
    end
  end
}

```

---

_[View the full topic](https://community.silverbullet.md/t/persistent-folding-how-to-use-space-style-to-hide-a-particular-attribute/3663)._
