MingaEditor.State.Windows (Minga v0.1.0)

Copy Markdown View Source

Groups window-related fields from EditorState.

Tracks the window tree layout, the map of window structs, the active window id, and the next available window id for splits.

Summary

Functions

Returns the active window struct, or nil if no windows are initialized.

Adds a window to the container using the window's id.

Allocates the next window id and advances the allocator.

Deletes a window from the map without touching the window tree.

Fetches a window by id.

Finds the first window matching the given predicate.

Returns all popup windows as a list of {window_id, window} tuples.

Removes a tree-managed window from the container.

Sets the active window id.

Replaces the window map.

Sets the next available window id.

Replaces the window layout tree.

Returns true if the window tree contains a split.

Updates the window struct for the given window id.

Updates every window that shows the given buffer pid via a mapper function.

Types

t()

@type t() :: %MingaEditor.State.Windows{
  active: MingaEditor.Window.id(),
  map: %{required(MingaEditor.Window.id()) => MingaEditor.Window.t()},
  next_id: MingaEditor.Window.id(),
  tree: MingaEditor.WindowTree.t() | nil
}

Functions

active_struct(windows)

@spec active_struct(t()) :: MingaEditor.Window.t() | nil

Returns the active window struct, or nil if no windows are initialized.

add_window(windows, window)

@spec add_window(t(), MingaEditor.Window.t()) :: t()

Adds a window to the container using the window's id.

allocate_id(windows)

@spec allocate_id(t()) :: {MingaEditor.Window.id(), t()}

Allocates the next window id and advances the allocator.

delete_window(windows, id)

@spec delete_window(t(), MingaEditor.Window.id()) :: t()

Deletes a window from the map without touching the window tree.

fetch(windows, id)

@spec fetch(t(), MingaEditor.Window.id()) :: {:ok, MingaEditor.Window.t()} | :error

Fetches a window by id.

find_by_content(windows, predicate)

@spec find_by_content(t(), (MingaEditor.Window.t() -> boolean())) ::
  {MingaEditor.Window.id(), MingaEditor.Window.t()} | nil

Finds the first window matching the given predicate.

remove_window(windows, id)

@spec remove_window(t(), MingaEditor.Window.id()) :: {:ok, t()} | :error

Removes a tree-managed window from the container.

set_active(windows, id)

@spec set_active(t(), MingaEditor.Window.id()) :: t()

Sets the active window id.

set_map(windows, map)

@spec set_map(t(), %{required(MingaEditor.Window.id()) => MingaEditor.Window.t()}) ::
  t()

Replaces the window map.

set_next_id(windows, id)

@spec set_next_id(t(), MingaEditor.Window.id()) :: t()

Sets the next available window id.

set_tree(windows, tree)

@spec set_tree(t(), MingaEditor.WindowTree.t() | nil) :: t()

Replaces the window layout tree.

split?(windows)

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

Returns true if the window tree contains a split.

update(win, id, fun)

Updates the window struct for the given window id.

Applies the given function to the window and stores the result. Returns the struct unchanged if the id is not found.

update_by_buffer(win, buffer, fun)

@spec update_by_buffer(t(), pid(), (MingaEditor.Window.t() -> MingaEditor.Window.t())) ::
  t()

Updates every window that shows the given buffer pid via a mapper function.