Operator functions for the Minga editor: delete, change, and yank.
Each function takes a Buffer.Server PID and two positions, and applies
the operator to the text between those positions.
Position semantics
All range functions use inclusive bounds — both from and to positions
are included in the operation. Positions are automatically normalised, so
from may be greater than to.
Return values
delete/3—{:ok, :deleted}after removing the range.change/3—{:ok, :changed}after removing the range (caller should then switch to Insert mode).yank/3—{:ok, yanked_text}without modifying the buffer.
Line-wise helpers
delete_line/2, change_line/2, and yank_line/2 operate on an entire
line by index (zero-based).
Summary
Types
A zero-indexed {line, col} cursor position.
Functions
Deletes the text between from and to (inclusive), just like delete/3.
The caller is expected to transition to Insert mode afterward.
Returns {:ok, :changed}.
Deletes the entire line at line_index, just like delete_line/2.
The caller is expected to transition to Insert mode afterward.
Returns {:ok, :changed}.
Deletes the text between from and to (inclusive) in the buffer managed
by server. Positions are automatically normalised.
Returns {:ok, :deleted}.
Deletes the entire line at line_index (zero-based) from the buffer.
Returns the text between from and to (inclusive) without modifying the buffer.
Returns {:ok, yanked_text}.
Returns the full text of the line at line_index (including newline separator
where present) without modifying the buffer.
Returns {:ok, yanked_text}.
Types
@type position() :: Minga.Buffer.Document.position()
A zero-indexed {line, col} cursor position.
Functions
@spec change(GenServer.server(), position(), position()) :: {:ok, :changed}
Deletes the text between from and to (inclusive), just like delete/3.
The caller is expected to transition to Insert mode afterward.
Returns {:ok, :changed}.
@spec change_line(GenServer.server(), non_neg_integer()) :: {:ok, :changed}
Deletes the entire line at line_index, just like delete_line/2.
The caller is expected to transition to Insert mode afterward.
Returns {:ok, :changed}.
@spec delete(GenServer.server(), position(), position()) :: {:ok, :deleted}
Deletes the text between from and to (inclusive) in the buffer managed
by server. Positions are automatically normalised.
Returns {:ok, :deleted}.
@spec delete_line(GenServer.server(), non_neg_integer()) :: {:ok, :deleted}
Deletes the entire line at line_index (zero-based) from the buffer.
If the buffer has more than one line, the trailing newline (or preceding
newline for the last line) is also removed so no blank line is left.
Returns {:ok, :deleted}.
@spec yank(GenServer.server(), position(), position()) :: {:ok, String.t()}
Returns the text between from and to (inclusive) without modifying the buffer.
Returns {:ok, yanked_text}.
@spec yank_line(GenServer.server(), non_neg_integer()) :: {:ok, String.t()}
Returns the full text of the line at line_index (including newline separator
where present) without modifying the buffer.
Returns {:ok, yanked_text}.