This write-up details what could be considered a "full set" of standard core functionality for text input boxes in user interfaces for referential purposes during implementation.
The core components of textbox behaviour are split into three parts: One we can call Movements, which describe a means of moving from one position to the next (eg. one-character-to-the-left), Operations which use a movement to perform an action (eg. select-to) and finally Commmands, most of which will be an operation performing a movement, although they are not limited to this.
The caret/selection of a textbox is typically implemented as a pair of integers; both are grouped together as they are part of the same thing. The first integer (we'll refer to this as the head) is the caret's current position; the second integer (the tail) is the other end of the selection — in the case that there is no text selected the head and tail are the same value and only the caret is displayed. In the case that there is text selected the value of both sides differ from one another.
Textboxes support the following 3 core operations for navigating and editing text; each operation uses a single movement to achieve it's goal — in terms of implementation you could think of each operation implemented as a function which itself takes a movement-function as an argument. As the movements are common between operations this reduces code duplication as each movement only needs to be implemented once to be used by any operation.