- 313 new markdown files created - 30 relationships embedded - 313 entries indexed - State initialized with usage data
1.2 KiB
1.2 KiB
| id | type | title | tags | importance | confidence | created | updated | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 20059335-a27d-4d43-a37c-1bb561c1deaf | code_pattern | Foundry VTT ActorSheetV2 scroll position preservation |
|
0.8 | 0.8 | 2025-12-14T19:12:40.421111+00:00 | 2025-12-14T19:12:40.421111+00:00 |
When using ApplicationV2/ActorSheetV2 in Foundry VTT v13, sheet re-renders (triggered by data updates like toggling a boolean) reset scroll position to top. Solution: Override _preRender() to save scroll positions and _onRender() to restore them.
Implementation in base sheet class:
- Add this._scrollPositions = {} in constructor
- In _preRender(): call this._saveScrollPositions()
- In _onRender(): call this._restoreScrollPositions()
_saveScrollPositions() queries scrollable elements (.window-content, .tab-content) and saves their scrollTop values. _restoreScrollPositions() restores those values after render.
Key selectors to save:
- .window-content (main Foundry window scroll)
- .tab-content (tab body scroll if using tabbed layout)
This pattern works for any ApplicationV2 subclass, not just actor sheets. File: module/sheets/base-actor-sheet.mjs in vagabond-rpg-foundryvtt project.