# `MingaEditor.State.Tab.Context`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_editor/state/tab/context.ex#L1)

Typed per-tab workspace snapshot stored on `MingaEditor.State.Tab`.

Contexts replace the old free-form map while still accepting legacy maps at API boundaries. `present_fields` records which workspace fields were actually present in a legacy map so partial migration inputs do not overwrite live workspace state with nil defaults.

# `document_highlight`

```elixir
@type document_highlight() :: Minga.LSP.DocumentHighlight.t()
```

A document highlight range from the LSP server.

# `field_name`

```elixir
@type field_name() ::
  :keymap_scope
  | :buffers
  | :windows
  | :dired
  | :file_tree
  | :viewport
  | :mouse
  | :highlight
  | :lsp_pending
  | :injection_ranges
  | :search
  | :editing
  | :feature_state
  | :document_highlights
  | :agent_ui
```

Workspace fields carried by a tab context.

# `legacy`

```elixir
@type legacy() :: map()
```

Legacy map persisted or built before tab contexts became typed structs.

# `t`

```elixir
@type t() :: %MingaEditor.State.Tab.Context{
  agent_ui: MingaEditor.Agent.UIState.t() | nil,
  buffers: MingaEditor.State.Buffers.t() | nil,
  dired: MingaEditor.State.Dired.t() | nil,
  document_highlights: [document_highlight()] | nil,
  editing: MingaEditor.VimState.t() | nil,
  feature_state: MingaEditor.FeatureState.t() | nil,
  file_tree: MingaEditor.State.FileTree.t() | nil,
  highlight: MingaEditor.State.Highlighting.t() | nil,
  injection_ranges:
    %{required(pid()) =&gt; [Minga.Language.Highlight.InjectionRange.t()]} | nil,
  keymap_scope: Minga.Keymap.Scope.scope_name() | nil,
  lsp_pending: %{required(reference()) =&gt; atom() | tuple()} | nil,
  mouse: MingaEditor.State.Mouse.t() | nil,
  present_fields: [field_name()],
  search: MingaEditor.State.Search.t() | nil,
  version: pos_integer(),
  viewport: MingaEditor.Viewport.t() | nil,
  windows: MingaEditor.State.Windows.t() | nil
}
```

# `empty`

```elixir
@spec empty() :: t()
```

Returns an empty context for a brand-new tab with no saved workspace yet.

# `empty?`

```elixir
@spec empty?(t() | legacy()) :: boolean()
```

Returns true when the context has no workspace fields to restore.

# `field_names`

```elixir
@spec field_names() :: [field_name()]
```

Returns the workspace field names represented by this context.

# `from_map`

```elixir
@spec from_map(t() | legacy()) :: t()
```

Normalizes a legacy context map into a typed context struct.

# `from_workspace`

```elixir
@spec from_workspace(MingaEditor.Session.State.t()) :: t()
```

Creates a tab context directly from a workspace struct, without intermediate map conversion.

# `from_workspace_map`

> This function is deprecated. Use from_workspace/1 for struct inputs. This remains for legacy map inputs only..

```elixir
@spec from_workspace_map(map()) :: t()
```

# `put_fields`

```elixir
@spec put_fields(t(), map() | keyword()) :: t()
```

Returns a context with valid workspace field overrides applied.

# `scrub_buffer`

```elixir
@spec scrub_buffer(t() | legacy(), pid()) :: t()
```

Returns a context with the dead buffer removed from its `buffers` snapshot when present.

# `to_workspace_map`

```elixir
@spec to_workspace_map(t() | legacy()) :: map()
```

Returns a workspace map containing only fields present in this context.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
