Documentation
¶
Overview ¶
Package inputcontent keeps editable text and atomic references together. Offsets are UTF-8 bytes; all token boundaries must also be grapheme boundaries.
Index ¶
- Variables
- func Equal(a, b Content) bool
- type Content
- func (c Content) Presentation() Presentation
- func (c Content) Replace(r Range, text string, token *Token) (Content, Range, error)
- func (c Content) Selection(start, end int) (int, int)
- func (c Content) Snap(at, bias int) int
- func (c Content) Text() string
- func (c Content) Tokens() []Span
- func (c Content) WithToken(s Span) (Content, error)
- type DisplaySpan
- type History
- type Presentation
- type Range
- type Session
- func (s *Session) BeginComposition()
- func (s *Session) CancelComposition()
- func (s *Session) Composing() bool
- func (s *Session) EndComposition()
- func (s *Session) Redo() bool
- func (s *Session) ReplaceDisplay(r Range, text string) error
- func (s *Session) ReplaceSource(r Range, text string) error
- func (s *Session) ReplaceToken(token Token) error
- func (s *Session) SelectDisplay(r Range) error
- func (s *Session) SelectSource(r Range) error
- func (s *Session) SelectedText() string
- func (s *Session) Set(content Content)
- func (s *Session) SetText(text string) error
- func (s *Session) Snapshot() Snapshot
- func (s *Session) Undo() bool
- type Snapshot
- type Span
- type Token
Constants ¶
This section is empty.
Variables ¶
var ( ErrToken = errors.New("inputcontent: invalid token") ErrBoundary = errors.New("inputcontent: invalid grapheme boundary") ErrOverlap = errors.New("inputcontent: overlapping tokens") ErrText = errors.New("inputcontent: text mismatch or invalid UTF-8") )
var ErrCompositionActive = errors.New("inputcontent: composition is active")
Functions ¶
Types ¶
type Content ¶
type Content struct {
// contains filtered or unexported fields
}
Content is immutable. Accessors return copies, including when no edit occurs.
func (Content) Presentation ¶
func (c Content) Presentation() Presentation
func (Content) Replace ¶
Replace makes one atomic edit. Partial token selections expand to whole tokens; insertion inside a token is rejected. A plain replacement removes references in the replaced interval. References after it shift by the byte delta.
type DisplaySpan ¶
type Presentation ¶
type Presentation struct {
Text string
Spans []DisplaySpan
}
Presentation replaces reference text with display labels and provides the corresponding source/display byte ranges for hit testing and clipboard maps.
func LayoutPresentation ¶
func LayoutPresentation(c Content, replacements []string) (Presentation, error)
LayoutPresentation supplies editor-only replacements for atomic references, for example a single private-use rune shaped as an inline object. It never changes the stored text or token metadata. Map edits with SourceRange before passing them to Session.ReplaceSource; clipboard text stays source-based.
func (Presentation) DisplayOffset ¶
func (p Presentation) DisplayOffset(source, bias int) int
DisplayOffset maps a source caret to the visible label, snapping token interiors using the same bias as SourceOffset.
func (Presentation) SourceOffset ¶
func (p Presentation) SourceOffset(display, bias int) int
func (Presentation) SourceRange ¶
func (p Presentation) SourceRange(r Range) (Range, error)
SourceRange expands a nonempty display selection to whole references while preserving direction. A caret inside a display label snaps to its nearest edge.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session owns editing transactions. UI adapters must pass explicit edit ranges: a text diff loses reference removal when an edit leaves the characters intact. All ranges are UTF-8 bytes. The platform's rune offsets must be converted before calling these methods. UI focus and read-only policies belong to the adapter.
func (*Session) BeginComposition ¶
func (s *Session) BeginComposition()
BeginComposition groups all subsequent plain edits into one undo transaction. Repeated begin notifications from a platform do not reset the saved snapshot.
func (*Session) CancelComposition ¶
func (s *Session) CancelComposition()
CancelComposition restores both the reference metadata and original selection.
func (*Session) EndComposition ¶
func (s *Session) EndComposition()
func (*Session) ReplaceDisplay ¶
ReplaceDisplay handles typing, plain paste and deletion. Selecting a label copies/removes the whole reference, not its display name. No text matching is used to infer references. Replacing a label with itself still removes its ID.
func (*Session) ReplaceSource ¶
ReplaceSource handles an edit already mapped out of an editor-specific presentation. It keeps the same composition and undo transaction semantics.
func (*Session) ReplaceToken ¶
ReplaceToken replaces the current source selection with an atomic reference. Applications must not insert references in a platform's active composition.