Static editor-only helper that stores per-sidebar state for the architecture editor. It keeps transient in-memory search and scroll values and persists expanded state and height via EditorCookie using keys namespaced by a provided key (and Scope helper for owner-scoped keys).
using System.Collections.Generic;
using Editor;
namespace Sunless.Architecture;
// Refresh() clears the whole sidebar, so what the author was aimed at - an open disclosure, a search, a
// browser height - has to outlive the widgets that showed it. Keys are scoped by subtool, or every tool's
// "Placement" would share one entry.
public static class ArchSidebarState
{
static readonly Dictionary<string, string> searches = new();
static readonly Dictionary<string, float> scrolls = new();
public static string Scope( object owner, string key ) => $"{owner.GetType().Name}.{key}";
public static bool Expanded( string key, bool fallback ) => EditorCookie.Get( $"ArchSidebar.Open.{key}", fallback );
public static void Expand( string key, bool value ) => EditorCookie.Set( $"ArchSidebar.Open.{key}", value );
public static float Height( string key, float fallback ) => EditorCookie.Get( $"ArchSidebar.Height.{key}", fallback );
public static void Resize( string key, float value ) => EditorCookie.Set( $"ArchSidebar.Height.{key}", value );
public static string Search( string key ) => searches.TryGetValue( key, out var text ) ? text : "";
public static void Searched( string key, string value ) => searches[key] = value ?? "";
public static float Scroll( string key ) => scrolls.TryGetValue( key, out var offset ) ? offset : 0f;
public static void Scrolled( string key, float value ) => scrolls[key] = value;
}