claude-memory/graph/code-patterns/foundry-vtt-actorsheetv2-scroll-position-preservation-200593.md
Cal Corum b140d4d82a migrate: 313 memories from MemoryGraph
- 313 new markdown files created
- 30 relationships embedded
- 313 entries indexed
- State initialized with usage data
2026-02-13 11:11:48 -06:00

27 lines
1.2 KiB
Markdown

---
id: 20059335-a27d-4d43-a37c-1bb561c1deaf
type: code_pattern
title: "Foundry VTT ActorSheetV2 scroll position preservation"
tags: [foundryvtt, applicationv2, actorsheetv2, scroll, pattern, javascript]
importance: 0.8
confidence: 0.8
created: "2025-12-14T19:12:40.421111+00:00"
updated: "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:
1. Add this._scrollPositions = {} in constructor
2. In _preRender(): call this._saveScrollPositions()
3. 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.