Skip to main content

Module session

Module session 

Source
Expand description

SN.2: the live snippet-expansion session, relocated off the host Editor so the mode-owned placeholder-navigation handlers can reach it.

While a snippet is expanding, exactly one ActiveSnippet is live (the tabstop groups + the focused index). Before SN.2 this lived as Editor.active_snippet: Option<ActiveSnippet> and the <Tab> / <S-Tab> handlers were Editor::do_snippet_* methods. Per feedback_mode_owns_its_surface, the handler bodies belong to the mode that owns the chords (SnippetActiveMode). The ActionHandlerRegistry seam hands a handler only an ActionContext (no &mut Editor), so the session it mutates must live somewhere both the host (which still creates the session on expand — SN.3 moves that too) and the mode handler can reach: this service, registered in the ServiceRegistry under SnippetSessionHandle.

SN.3e: the session is keyed by buffer (HashMap<BufferId, ActiveSnippet>), not a single global slot. Before SN.3e a snippet started in buffer A then switching to B lit active-snippet-mode on B and routed <Tab> to A’s tabstops against B’s cursor (the predicate + slot were buffer-agnostic). Snippet state is buffer-local (everything-is-a-buffer ⇒ per-buffer, not a singleton), so every operation names its buffer: handlers use core_buffer_id(ctx.buffer_id), host paths use the document buffer.

One Mutex guards the map. Snippet operations are rare (per <Tab>, never per render), so the lock is uncontended and off any hot path.

Structs§

SnippetSession
The live snippet sessions, keyed by the buffer each is expanding in (a buffer is absent from the map when no snippet is live there).

Functions§

snippet_active_predicate
Predicate for the host’s generic session-backed-minor reconciler: active-snippet-mode should be active on the active buffer exactly while a snippet session is live. The host pairs this with SnippetActiveMode::mode_id() at boot and reconciles it each overlay-sync cycle — so the host’s generic sync carries no snippet_session.is_active() literal. Keeps the “when is my mode active?” policy in this crate per feedback_mode_owns_its_surface.

Type Aliases§

SnippetSessionHandle
Shared handle, registered in ServiceRegistry and held by the host. Per feedback_servicesregistry_arc_typeid: register and look up under this exact alias so the TypeId matches.