MingaEditor.YankFlash (Minga v0.1.0)

Copy Markdown View Source

Yank region flash after a yank operation.

Briefly highlights the yanked region with a bright background that fades back to the editor background over several steps, providing visual confirmation of what was copied (like Neovim's YankHighlight).

This is a pure calculation module. It returns structs and side-effect instructions ({:send_after, msg, interval}, {:cancel_timer, ref}). The Editor GenServer executes the side effects.

Summary

Types

Position as {line, col}.

Whether the yanked region is charwise or linewise.

Side-effect instruction returned to the caller.

t()

Active yank flash state tracking the highlighted region and animation progress.

Functions

Advances the flash to the next step.

Returns side effects needed to cancel an active flash.

Computes the flash background color for the current step.

Computes the highlight bounds for the flash decoration.

Creates a new yank flash for the given buffer and range.

Types

position()

@type position() :: {non_neg_integer(), non_neg_integer()}

Position as {line, col}.

range_type()

@type range_type() :: :charwise | :linewise

Whether the yanked region is charwise or linewise.

side_effect()

@type side_effect() ::
  {:send_after, atom(), pos_integer()} | {:cancel_timer, reference()}

Side-effect instruction returned to the caller.

t()

@type t() :: %MingaEditor.YankFlash{
  buf: pid(),
  end_pos: position(),
  max_steps: pos_integer(),
  range_type: range_type(),
  start_pos: position(),
  step: non_neg_integer(),
  timer: reference() | nil
}

Active yank flash state tracking the highlighted region and animation progress.

Functions

advance(flash)

@spec advance(t()) :: {:continue, t(), [side_effect()]} | :done

Advances the flash to the next step.

Returns {:continue, updated_flash, side_effects} if more steps remain, or :done if the flash is complete.

cancel_effects(arg1)

@spec cancel_effects(t() | nil) :: [side_effect()]

Returns side effects needed to cancel an active flash.

color_for_step(yank_flash, flash_bg, target_bg)

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

default_flash_bg()

@spec default_flash_bg() :: non_neg_integer()

Computes the flash background color for the current step.

Interpolates between flash_bg (step 0) and target_bg (final step) linearly.

flash_group()

@spec flash_group() :: atom()

highlight_bounds(buf, start_pos, end_pos, atom)

@spec highlight_bounds(pid(), position(), position(), range_type()) ::
  {position(), position()}

Computes the highlight bounds for the flash decoration.

Charwise ranges pass through unchanged. Linewise ranges expand to full line width using the buffer's line content.

start(buf, start_pos, end_pos, range_type, existing_timer \\ nil)

@spec start(pid(), position(), position(), range_type(), reference() | nil) ::
  {t(), [side_effect()]}

Creates a new yank flash for the given buffer and range.

Returns {flash, side_effects}. The caller must execute the side effects (cancel old timer, schedule new one).