# `Toddy.Iced.Widget.TextEditor`
[🔗](https://github.com/toddy-ui/toddy-elixir/blob/v0.3.0/lib/toddy/iced/widget/text_editor.ex#L1)

Text editor -- multi-line editable text area.

The renderer manages an internal `text_editor::Content` cache keyed by
node ID. The `content` prop seeds the initial content.

## Props

- `content` (string) -- initial text content (used to seed the editor cache).
- `placeholder` (string) -- placeholder text shown when editor is empty.
- `width` (number) -- editor width in pixels (note: takes pixels, not length).
- `height` (length) -- editor height. Default: shrink. See `Toddy.Iced.Length`.
- `min_height` (number) -- minimum height in pixels.
- `max_height` (number) -- maximum height in pixels.
- `font` (string | map) -- font specification. See `Toddy.Iced.Font`.
- `size` (number) -- font size in pixels.
- `line_height` (number | map) -- line height.
- `padding` (number) -- uniform padding in pixels.
- `wrapping` -- text wrapping mode. See `Toddy.Iced.Wrapping`.
- `ime_purpose` (string) -- IME input purpose hint: `"normal"`, `"secure"`, `"terminal"`.
  Default: `"normal"`.
- `highlight_syntax` (string) -- language extension for syntax highlighting (e.g. "rs", "py", "ex").
- `highlight_theme` (string) -- highlighter theme. One of `"solarized_dark"`, `"base16_mocha"`,
  `"base16_ocean"`, `"base16_eighties"`, `"inspired_github"`. Defaults to `"solarized_dark"`.
- `style` -- `:default` or `StyleMap.t()` for custom styling. See `Toddy.Iced.StyleMap`.
- `key_bindings` (list of maps) -- declarative key binding rules for the editor.
  Each rule is a map with optional `key` (character), `named` (named key string),
  `modifiers` (list of modifier strings), and `binding` (the action to take).
  See `key_bindings/2` for details.
- `placeholder_color` (color) -- placeholder text color. See `Toddy.Iced.Color`.
- `selection_color` (color) -- text selection highlight color. See `Toddy.Iced.Color`.
- `a11y` (map) -- accessibility overrides. See `Toddy.Iced.A11y`.

## Events

The editor emits text action events handled internally by the renderer.
Content changes are reported back to Elixir via the protocol.

# `option`

```elixir
@type option() ::
  {:content, String.t()}
  | {:placeholder, String.t()}
  | {:width, number()}
  | {:height, Toddy.Iced.Length.t()}
  | {:min_height, number()}
  | {:max_height, number()}
  | {:font, Toddy.Iced.Font.t()}
  | {:size, number()}
  | {:line_height, number() | map()}
  | {:padding, number()}
  | {:wrapping, Toddy.Iced.Wrapping.t()}
  | {:ime_purpose, String.t()}
  | {:highlight_syntax, String.t()}
  | {:highlight_theme, String.t()}
  | {:style, style()}
  | {:key_bindings, [map()]}
  | {:placeholder_color, Toddy.Iced.Color.input()}
  | {:selection_color, Toddy.Iced.Color.input()}
  | {:a11y, Toddy.Iced.A11y.t()}
```

# `style`

```elixir
@type style() :: :default | Toddy.Iced.StyleMap.t()
```

# `t`

```elixir
@type t() :: %Toddy.Iced.Widget.TextEditor{
  a11y: Toddy.Iced.A11y.t() | nil,
  content: String.t() | nil,
  font: Toddy.Iced.Font.t() | nil,
  height: Toddy.Iced.Length.t() | nil,
  highlight_syntax: String.t() | nil,
  highlight_theme: String.t() | nil,
  id: String.t(),
  ime_purpose: String.t() | nil,
  key_bindings: [map()] | nil,
  line_height: number() | map() | nil,
  max_height: number() | nil,
  min_height: number() | nil,
  padding: number() | nil,
  placeholder: String.t() | nil,
  placeholder_color: Toddy.Iced.Color.t() | nil,
  selection_color: Toddy.Iced.Color.t() | nil,
  size: number() | nil,
  style: style() | nil,
  width: number() | nil,
  wrapping: Toddy.Iced.Wrapping.t() | nil
}
```

# `a11y`

```elixir
@spec a11y(text_editor :: t(), a11y :: Toddy.Iced.A11y.t()) :: t()
```

Sets accessibility annotations.

# `build`

```elixir
@spec build(text_editor :: t()) :: Toddy.Iced.ui_node()
```

Converts this text editor struct to a `ui_node()` map via the `Toddy.Iced.Widget` protocol.

# `content`

```elixir
@spec content(text_editor :: t(), content :: String.t()) :: t()
```

Sets the initial text content.

# `font`

```elixir
@spec font(text_editor :: t(), font :: Toddy.Iced.Font.t()) :: t()
```

Sets the font.

# `height`

```elixir
@spec height(text_editor :: t(), height :: Toddy.Iced.Length.t()) :: t()
```

Sets the editor height.

# `highlight_syntax`

```elixir
@spec highlight_syntax(text_editor :: t(), highlight_syntax :: String.t()) :: t()
```

Sets the syntax language for highlighting (e.g. "rs", "py", "ex").

# `highlight_theme`

```elixir
@spec highlight_theme(text_editor :: t(), highlight_theme :: String.t()) :: t()
```

Sets the highlighter color theme.

# `ime_purpose`

```elixir
@spec ime_purpose(text_editor :: t(), ime_purpose :: String.t()) :: t()
```

Sets the IME input purpose hint.

# `key_bindings`

```elixir
@spec key_bindings(text_editor :: t(), key_bindings :: [map()]) :: t()
```

Sets declarative key binding rules for the editor.

Each rule is a map with:

- `"key"` (string) -- a character to match (layout-independent via `to_latin`).
- `"named"` (string) -- a named key like `"Enter"`, `"Escape"`, `"Tab"`, etc.
- `"modifiers"` (list of strings) -- required modifiers: `"shift"`, `"ctrl"`,
  `"alt"`, `"logo"`, `"command"`, `"jump"`.
- `"binding"` -- the action: a string like `"copy"`, `"cut"`, `"paste"`,
  `"enter"`, `"backspace"`, `"delete"`, `"unfocus"`, `"select_all"`,
  `"select_word"`, `"select_line"`, `"default"`, or a map for complex
  actions like `%{"move" => "left"}`, `%{"select" => "word_right"}`,
  `%{"insert" => "x"}`, `%{"custom" => "my_tag"}`,
  `%{"sequence" => [binding1, binding2, ...]}`.

Rules are matched in order. The first matching rule wins. If no rule matches,
the key press is ignored (no binding). Use `"default"` as the binding to
delegate to iced's built-in key handler.

# `line_height`

```elixir
@spec line_height(text_editor :: t(), line_height :: number() | map()) :: t()
```

Sets the line height.

# `max_height`

```elixir
@spec max_height(text_editor :: t(), max_height :: number()) :: t()
```

Sets the maximum height in pixels.

# `min_height`

```elixir
@spec min_height(text_editor :: t(), min_height :: number()) :: t()
```

Sets the minimum height in pixels.

# `new`

```elixir
@spec new(id :: String.t(), opts :: [option()]) :: t()
```

Creates a new text editor struct with the given id and optional keyword opts.

# `padding`

```elixir
@spec padding(text_editor :: t(), padding :: number()) :: t()
```

Sets the uniform padding in pixels.

# `placeholder`

```elixir
@spec placeholder(text_editor :: t(), placeholder :: String.t()) :: t()
```

Sets the placeholder text.

# `placeholder_color`

```elixir
@spec placeholder_color(text_editor :: t(), color :: Toddy.Iced.Color.input()) :: t()
```

Sets the placeholder text color. Accepts any form `Color.cast/1` supports.

# `selection_color`

```elixir
@spec selection_color(text_editor :: t(), color :: Toddy.Iced.Color.input()) :: t()
```

Sets the text selection highlight color. Accepts any form `Color.cast/1` supports.

# `size`

```elixir
@spec size(text_editor :: t(), size :: number()) :: t()
```

Sets the font size in pixels.

# `style`

```elixir
@spec style(text_editor :: t(), style :: style()) :: t()
```

Sets the text editor style.

# `width`

```elixir
@spec width(text_editor :: t(), width :: number()) :: t()
```

Sets the editor width in pixels.

# `with_options`

```elixir
@spec with_options(text_editor :: t(), opts :: [option()]) :: t()
```

Applies keyword options to an existing text editor struct.

# `wrapping`

```elixir
@spec wrapping(text_editor :: t(), wrapping :: Toddy.Iced.Wrapping.t()) :: t()
```

Sets the text wrapping mode.

---

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