MingaEditor.InlineOverlay.Store (Minga v0.1.0)

Copy Markdown View Source

Shared per-buffer store for inline overlays (ask and edit).

Both variants key their ephemeral overlays by buffer_pid and track an optional session_pid. The lookup/insert/dismiss/session plumbing only touches those two fields, so it lives here once and is reused by both MingaEditor.State.InlineAsk and MingaEditor.State.InlineEdit rather than being copied per variant.

An overlay is any struct carrying :buffer_pid and :session_pid. The variant struct modules own their own fields and transitions; this module owns only the store mechanics.

Summary

Types

An overlay struct carrying :buffer_pid and :session_pid.

A per-buffer overlay store.

Functions

Returns the active overlay for a buffer, or nil.

Dismisses the overlay for a buffer.

Opens or replaces an overlay for its buffer.

Returns true when the given session pid belongs to an overlay in this store.

Types

overlay()

@type overlay() :: %{
  :__struct__ => module(),
  :buffer_pid => pid(),
  :session_pid => pid() | nil,
  optional(atom()) => term()
}

An overlay struct carrying :buffer_pid and :session_pid.

store()

@type store() :: %{required(pid()) => overlay()}

A per-buffer overlay store.

Functions

active(store, buffer_pid)

@spec active(store(), pid() | nil) :: overlay() | nil

Returns the active overlay for a buffer, or nil.

dismiss(store, buffer_pid)

@spec dismiss(store(), pid() | nil) :: {store(), pid() | nil}

Dismisses the overlay for a buffer.

Returns {store, session_pid} where session_pid is the dismissed overlay's session pid (or nil when there was no overlay), so callers can stop the session.

put(store, overlay)

@spec put(store(), overlay()) :: store()

Opens or replaces an overlay for its buffer.

session?(store, session_pid)

@spec session?(store(), pid()) :: boolean()

Returns true when the given session pid belongs to an overlay in this store.