MingaEditor.Agent.UIState.View (Minga v0.1.0)

Copy Markdown View Source

Layout, search, preview, and toast state for the agent UI.

Holds the data for the full-screen agentic view (focus, split sizing, preview pane, search, toasts, diff baselines, context estimate). This is the "view" half of the agent UI, separated from prompt editing concerns in UIState.Panel.

Most callers interact through UIState functions rather than accessing this struct directly.

Summary

Types

Which panel has keyboard focus inside the agentic view.

Active prefix key awaiting a follow-up keystroke.

A search match: message index, byte start, byte end.

Search state for the chat panel.

t()

Layout, search, preview, and toast state.

A notification toast.

Functions

Activates the view, saving the current window layout.

Cancels search and returns nil (caller restores scroll).

Clears all diff baselines (called at the start of a new turn).

Clears any pending prefix.

Clears all toasts.

Confirms search (keeps matches for n/N navigation, disables input).

Deactivates the view and returns the restored window layout.

Dismisses the help overlay.

Dismisses the current toast. Shows the next one in the queue if any.

Returns the baseline content for a path, or nil if none recorded.

Grows the chat panel width by one step (clamped at max).

Creates a new view state with defaults.

Moves to the next search match.

Moves to the previous search match.

Pushes a toast. If no toast is showing, it becomes the current toast.

Records the baseline content for a file path (first edit only).

Resets the chat panel width to the configured default.

Scrolls the preview pane down by the given number of lines.

Scrolls the preview pane to a large offset (renderer clamps to actual content).

Scrolls the preview pane to the top (offset 0).

Scrolls the preview pane up by the given number of lines, clamped at 0.

Returns true if search input is being typed (vs confirmed).

Returns the search query, or nil if not searching.

Returns the saved scroll position from before search started.

Returns true if search is active (either inputting or confirmed with matches).

Switches focus to the given panel.

Sets the pending prefix for multi-key sequences.

Sets search matches and resets current to 0.

Shrinks the chat panel width by one step (clamped at min).

Starts a search, saving the current scroll position.

Returns true if a toast is currently visible.

Toggles the help overlay visibility.

Updates the preview state with the given function.

Updates the search query string.

Types

focus()

@type focus() :: :chat | :file_viewer

Which panel has keyboard focus inside the agentic view.

prefix()

@type prefix() ::
  nil | :g | :z | :bracket_next | :bracket_prev | Minga.Keymap.Bindings.Node.t()

Active prefix key awaiting a follow-up keystroke.

search_match()

@type search_match() ::
  {msg_index :: non_neg_integer(), col_start :: non_neg_integer(),
   col_end :: non_neg_integer()}

A search match: message index, byte start, byte end.

search_state()

@type search_state() :: %{
  query: String.t(),
  matches: [search_match()],
  current: non_neg_integer(),
  saved_scroll: non_neg_integer(),
  input_active: boolean()
}

Search state for the chat panel.

t()

@type t() :: %MingaEditor.Agent.UIState.View{
  active: boolean(),
  chat_width_pct: non_neg_integer(),
  context_estimate: non_neg_integer(),
  diff_baselines: %{required(String.t()) => String.t()},
  focus: focus(),
  help_visible: boolean(),
  pending_prefix: prefix(),
  preview: MingaEditor.Agent.View.Preview.t(),
  saved_file_tree: MingaEditor.State.FileTree.t() | nil,
  saved_windows: MingaEditor.State.Windows.t() | nil,
  search: search_state() | nil,
  toast: toast() | nil,
  toast_queue: term()
}

Layout, search, preview, and toast state.

toast()

@type toast() :: %{
  message: String.t(),
  icon: String.t(),
  level: :info | :warning | :error
}

A notification toast.

Functions

activate(view, windows, file_tree)

Activates the view, saving the current window layout.

cancel_search(view)

@spec cancel_search(t()) :: t()

Cancels search and returns nil (caller restores scroll).

clear_baselines(view)

@spec clear_baselines(t()) :: t()

Clears all diff baselines (called at the start of a new turn).

clear_prefix(view)

@spec clear_prefix(t()) :: t()

Clears any pending prefix.

clear_toasts(view)

@spec clear_toasts(t()) :: t()

Clears all toasts.

confirm_search(view)

@spec confirm_search(t()) :: t()

Confirms search (keeps matches for n/N navigation, disables input).

deactivate(view)

@spec deactivate(t()) ::
  {t(), MingaEditor.State.Windows.t() | nil,
   MingaEditor.State.FileTree.t() | nil}

Deactivates the view and returns the restored window layout.

dismiss_help(view)

@spec dismiss_help(t()) :: t()

Dismisses the help overlay.

dismiss_toast(view)

@spec dismiss_toast(t()) :: t()

Dismisses the current toast. Shows the next one in the queue if any.

get_baseline(view, path)

@spec get_baseline(t(), String.t()) :: String.t() | nil

Returns the baseline content for a path, or nil if none recorded.

grow_chat(view)

@spec grow_chat(t()) :: t()

Grows the chat panel width by one step (clamped at max).

new()

@spec new() :: t()

Creates a new view state with defaults.

next_search_match(view)

@spec next_search_match(t()) :: t()

Moves to the next search match.

prev_search_match(view)

@spec prev_search_match(t()) :: t()

Moves to the previous search match.

push_toast(view, message, level)

@spec push_toast(t(), String.t(), :info | :warning | :error) :: t()

Pushes a toast. If no toast is showing, it becomes the current toast.

record_baseline(view, path, content)

@spec record_baseline(t(), String.t(), String.t()) :: t()

Records the baseline content for a file path (first edit only).

reset_split(view)

@spec reset_split(t()) :: t()

Resets the chat panel width to the configured default.

scroll_viewer_down(view, amount)

@spec scroll_viewer_down(t(), pos_integer()) :: t()

Scrolls the preview pane down by the given number of lines.

scroll_viewer_to_bottom(view)

@spec scroll_viewer_to_bottom(t()) :: t()

Scrolls the preview pane to a large offset (renderer clamps to actual content).

scroll_viewer_to_top(view)

@spec scroll_viewer_to_top(t()) :: t()

Scrolls the preview pane to the top (offset 0).

scroll_viewer_up(view, amount)

@spec scroll_viewer_up(t(), pos_integer()) :: t()

Scrolls the preview pane up by the given number of lines, clamped at 0.

search_input_active?(view)

@spec search_input_active?(t()) :: boolean()

Returns true if search input is being typed (vs confirmed).

search_query(view)

@spec search_query(t()) :: String.t() | nil

Returns the search query, or nil if not searching.

search_saved_scroll(view)

@spec search_saved_scroll(t()) :: non_neg_integer() | nil

Returns the saved scroll position from before search started.

searching?(view)

@spec searching?(t()) :: boolean()

Returns true if search is active (either inputting or confirmed with matches).

set_focus(view, focus)

@spec set_focus(t(), focus()) :: t()

Switches focus to the given panel.

set_prefix(view, prefix)

@spec set_prefix(t(), prefix()) :: t()

Sets the pending prefix for multi-key sequences.

set_search_matches(view, matches)

@spec set_search_matches(t(), [search_match()]) :: t()

Sets search matches and resets current to 0.

shrink_chat(view)

@spec shrink_chat(t()) :: t()

Shrinks the chat panel width by one step (clamped at min).

start_search(view, current_scroll)

@spec start_search(t(), non_neg_integer()) :: t()

Starts a search, saving the current scroll position.

toast_visible?(view)

@spec toast_visible?(t()) :: boolean()

Returns true if a toast is currently visible.

toggle_help(view)

@spec toggle_help(t()) :: t()

Toggles the help overlay visibility.

update_preview(view, fun)

@spec update_preview(t(), (MingaEditor.Agent.View.Preview.t() ->
                       MingaEditor.Agent.View.Preview.t())) ::
  t()

Updates the preview state with the given function.

update_search_query(view, query)

@spec update_search_query(t(), String.t()) :: t()

Updates the search query string.