Skip to main content

Module active

Module active 

Source
Expand description

Active-snippet state machine. The host instantiates one ActiveSnippet when a snippet expands; while it’s the “active” snippet, <Tab> / <S-Tab> step through placeholders and edits to one tabstop ripple to the others that share its index.

Buffer-position tracking is the host’s job. This module owns the intent (which placeholder is focused, what the mirror groups are, exit semantics); the host translates that into rope edits + cursor moves.

Lifecycle:

  1. Host renders a RenderedSnippet, splices its text into the buffer, and constructs an ActiveSnippet keyed by the snippet’s start position + the RenderedSnippet’s tabstops.
  2. Host moves the cursor to the first tabstop’s range. If it has a default, the host can mark the range selected (vim Visual) so a typed character replaces the default.
  3. <Tab> -> ActiveSnippet::next returns the next tabstop group; host moves cursor there.
  4. Edit inside one mirror -> host updates the rope, asks ActiveSnippet::shift_ranges_after to ripple the change to the other mirrors of the same tabstop group, then re-renders.
  5. Reaching $0 exits; the host drops the ActiveSnippet and lets normal Insert-mode resume.

Structs§

ActiveSnippet
State of an in-flight snippet expansion.
TabstopGroup
One group of mirror ranges sharing the same tabstop index. <Tab> cycles between groups; edits within one group ripple to every range in the same group.