Documentation
¶
Index ¶
- type Change
- type ChangeList
- type ChangeTracker
- func (c *ChangeTracker) ChangeCount() int
- func (c *ChangeTracker) ClearChanges()
- func (c *ChangeTracker) ForEachChange(fn func(originalRange, currentRange text.TextRange))
- func (c *ChangeTracker) GetOriginalRange(changeIndex int) text.TextRange
- func (c *ChangeTracker) GetRange(changeIndex int) text.TextRange
- func (c *ChangeTracker) TrackChange(preStart, preEnd, postLength int)
- type GapBuffer
- func (g *GapBuffer) Append(text string)
- func (g *GapBuffer) ContentEquals(other string) bool
- func (g *GapBuffer) Delete(start, end int)
- func (g *GapBuffer) Get(index int) rune
- func (g *GapBuffer) Insert(index int, text string)
- func (g *GapBuffer) Length() int
- func (g *GapBuffer) Replace(start, end int, text string)
- func (g *GapBuffer) String() string
- func (g *GapBuffer) SubSequence(start, end int) string
- type OffsetMappingCalculator
- type PartialGapBuffer
- func (p *PartialGapBuffer) ContentEquals(other string) bool
- func (p *PartialGapBuffer) Get(index int) rune
- func (p *PartialGapBuffer) Length() int
- func (p *PartialGapBuffer) Replace(start, end int, replacement string)
- func (p *PartialGapBuffer) String() string
- func (p *PartialGapBuffer) SubSequence(start, end int) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
// OriginalStart is the start position in the original text.
OriginalStart int
// OriginalEnd is the end position in the original text.
OriginalEnd int
// CurrentStart is the start position in the current (modified) text.
CurrentStart int
// CurrentEnd is the end position in the current (modified) text.
CurrentEnd int
}
Change represents a single tracked text change.
type ChangeList ¶
type ChangeList interface {
// ChangeCount returns the number of discrete changes.
ChangeCount() int
// GetRange returns the range in the current (modified) text for the change at index.
GetRange(changeIndex int) text.TextRange
// GetOriginalRange returns the range in the original (unmodified) text that was replaced.
GetOriginalRange(changeIndex int) text.TextRange
}
ChangeList represents a list of non-overlapping, ordered text changes.
This interface is implemented by ChangeTracker and used by InputTransformation to inspect what changes were made during an edit session.
Changes are ordered by their position in the current text. Each change has both a "current" range (position in the modified text) and an "original" range (position in the text before any changes).
type ChangeTracker ¶
type ChangeTracker struct {
// contains filtered or unexported fields
}
ChangeTracker implements ChangeList and records changes as they occur.
It maintains a list of non-overlapping changes ordered by position. Adjacent or overlapping changes are merged automatically.
The tracker handles the complexity of maintaining consistent coordinate mappings between the original text and the current text as edits accumulate.
This is a port of androidx.compose.foundation.text.input.internal.ChangeTracker.
func NewChangeTracker ¶
func NewChangeTracker(initialChanges *ChangeTracker) *ChangeTracker
NewChangeTracker creates a new ChangeTracker. If initialChanges is provided, it copies the changes from that tracker.
func (*ChangeTracker) ChangeCount ¶
func (c *ChangeTracker) ChangeCount() int
ChangeCount returns the number of tracked changes.
func (*ChangeTracker) ClearChanges ¶
func (c *ChangeTracker) ClearChanges()
ClearChanges removes all tracked changes.
func (*ChangeTracker) ForEachChange ¶
func (c *ChangeTracker) ForEachChange(fn func(originalRange, currentRange text.TextRange))
ForEachChange calls the given function for each tracked change.
func (*ChangeTracker) GetOriginalRange ¶
func (c *ChangeTracker) GetOriginalRange(changeIndex int) text.TextRange
GetOriginalRange returns the range in the original text for change at index.
func (*ChangeTracker) GetRange ¶
func (c *ChangeTracker) GetRange(changeIndex int) text.TextRange
GetRange returns the range in the current text for change at index.
func (*ChangeTracker) TrackChange ¶
func (c *ChangeTracker) TrackChange(preStart, preEnd, postLength int)
TrackChange records a change at the given position.
Parameters:
- preStart: Start position in pre-change text (before this change)
- preEnd: End position in pre-change text (before this change)
- postLength: Length of the replacement text
The change is merged with existing tracking data if it overlaps or is adjacent.
type GapBuffer ¶
type GapBuffer struct {
// contains filtered or unexported fields
}
GapBuffer provides efficient text editing via a gap-based data structure.
The gap buffer maintains a "gap" (empty space) in the buffer that moves to the insertion/deletion point. This provides O(1) operations near the cursor while maintaining O(n) worst case for distant operations.
This is a port of androidx.compose.foundation.text.input.internal.GapBuffer.
func NewGapBuffer ¶
NewGapBuffer creates a new GapBuffer with the given initial text.
func (*GapBuffer) ContentEquals ¶
ContentEquals returns true if the content equals the given string.
func (*GapBuffer) SubSequence ¶
SubSequence returns a substring from start (inclusive) to end (exclusive).
type OffsetMappingCalculator ¶
type OffsetMappingCalculator struct {
// contains filtered or unexported fields
}
OffsetMappingCalculator builds bidirectional offset mappings after edit operations.
This class tracks offset transformations between an original text and a transformed text that has had one or more edit operations applied. It supports mapping offsets in both directions:
- Forward: original → transformed
- Reverse: transformed → original
When mappings are ambiguous (e.g., a point mapping to a deleted range), the result is returned as a TextRange indicating all valid mappings.
This is a port of androidx.compose.foundation.text.input.internal.OffsetMappingCalculator.
func NewOffsetMappingCalculator ¶
func NewOffsetMappingCalculator() *OffsetMappingCalculator
NewOffsetMappingCalculator creates a new OffsetMappingCalculator.
func (*OffsetMappingCalculator) MapFromDest ¶
func (o *OffsetMappingCalculator) MapFromDest(offset int) text.TextRange
MapFromDest maps an offset in the transformed string to the corresponding offset or range of offsets in the original string.
func (*OffsetMappingCalculator) MapFromSource ¶
func (o *OffsetMappingCalculator) MapFromSource(offset int) text.TextRange
MapFromSource maps an offset in the original string to the corresponding offset or range of offsets in the transformed string.
func (*OffsetMappingCalculator) RecordEditOperation ¶
func (o *OffsetMappingCalculator) RecordEditOperation(sourceStart, sourceEnd, newLength int)
RecordEditOperation records a replacement from [sourceStart, sourceEnd) with newLength chars.
Parameters:
- sourceStart: Start of the range being replaced (in source text)
- sourceEnd: End of the range being replaced (in source text)
- newLength: Length of the replacement text
func (*OffsetMappingCalculator) Reset ¶
func (o *OffsetMappingCalculator) Reset()
Reset clears all recorded operations.
type PartialGapBuffer ¶
type PartialGapBuffer struct {
// contains filtered or unexported fields
}
PartialGapBuffer wraps text with a localized gap buffer around the cursor.
Unlike GapBuffer, this implementation doesn't convert the entire text to a mutable buffer. Instead, it only converts the cursor-adjacent region, saving construction time and memory for large texts. If editing moves away from the buffer region, the buffer is flushed and a new region is created.
This is a port of androidx.compose.foundation.text.input.internal.PartialGapBuffer.
func NewPartialGapBuffer ¶
func NewPartialGapBuffer(text string) *PartialGapBuffer
NewPartialGapBuffer creates a new PartialGapBuffer with the given text.
func (*PartialGapBuffer) ContentEquals ¶
func (p *PartialGapBuffer) ContentEquals(other string) bool
ContentEquals returns true if the content equals the given string.
func (*PartialGapBuffer) Get ¶
func (p *PartialGapBuffer) Get(index int) rune
Get returns the rune at the given index.
func (*PartialGapBuffer) Length ¶
func (p *PartialGapBuffer) Length() int
Length returns the logical length of the text.
func (*PartialGapBuffer) Replace ¶
func (p *PartialGapBuffer) Replace(start, end int, replacement string)
Replace replaces text from start to end with the given string.
func (*PartialGapBuffer) String ¶
func (p *PartialGapBuffer) String() string
String returns the complete text content.
func (*PartialGapBuffer) SubSequence ¶
func (p *PartialGapBuffer) SubSequence(start, end int) string
SubSequence returns a substring from start (inclusive) to end (exclusive).