Documentation
¶
Index ¶
- Variables
- type Buffer
- type BufferType
- type LineIndex
- func (li *LineIndex) AppendOffsets(offsets []int, maxAllowed int)
- func (li *LineIndex) GetLineAtOffset(offset int) int
- func (li *LineIndex) GetLineOffset(line int) int
- func (li *LineIndex) LineCount() int
- func (li *LineIndex) Rebuild(pt *PieceTable)
- func (li *LineIndex) UpdateAfterDelete(offset, length int)
- func (li *LineIndex) UpdateAfterInsert(offset int, data []byte)
- type MemoryBuffer
- type Piece
- type PieceTable
- func (pt *PieceTable) AppendRange(dest []byte, offset, length int) ([]byte, error)
- func (pt *PieceTable) Bytes() ([]byte, error)
- func (pt *PieceTable) Delete(offset, length int)
- func (pt *PieceTable) ForEachRange(fn func(data []byte) error) error
- func (pt *PieceTable) GetOriginalBuffer() Buffer
- func (pt *PieceTable) GetRange(offset, length int) ([]byte, error)
- func (pt *PieceTable) GetState() TableState
- func (pt *PieceTable) Insert(offset int, data []byte)
- func (pt *PieceTable) LoadState(s TableState)
- func (pt *PieceTable) Size() int
- func (pt *PieceTable) String() string
- func (pt *PieceTable) UpdateOriginalBuffer(buf Buffer)
- type TableState
Constants ¶
This section is empty.
Variables ¶
var ErrLoading = errors.New("data is loading")
Functions ¶
This section is empty.
Types ¶
type LineIndex ¶
type LineIndex struct {
// contains filtered or unexported fields
}
LineIndex stores start offsets of each line.
func (*LineIndex) AppendOffsets ¶
AppendOffsets adds pre-calculated line offsets (used by background indexer). It performs a safety check to ensure offsets are within reasonable bounds.
func (*LineIndex) GetLineAtOffset ¶
func (*LineIndex) GetLineOffset ¶
GetLineOffset returns byte offset of the specified line start (0-based).
func (*LineIndex) Rebuild ¶
func (li *LineIndex) Rebuild(pt *PieceTable)
Rebuild completely reconstructs the line index based on PieceTable.
func (*LineIndex) UpdateAfterDelete ¶
UpdateAfterDelete incrementally updates the index after data deletion.
func (*LineIndex) UpdateAfterInsert ¶
UpdateAfterInsert incrementally updates the index after data insertion.
type MemoryBuffer ¶
type MemoryBuffer []byte
func (MemoryBuffer) Size ¶
func (m MemoryBuffer) Size() int
type Piece ¶
type Piece struct {
Buf BufferType
Start int // Offset of the fragment start in the corresponding buffer
Length int // Piece length
}
Piece describes one text fragment.
type PieceTable ¶
type PieceTable struct {
// contains filtered or unexported fields
}
PieceTable is a structure for efficient editing of large texts.
func NewWithBuffer ¶
func NewWithBuffer(buf Buffer) *PieceTable
func (*PieceTable) AppendRange ¶
func (pt *PieceTable) AppendRange(dest []byte, offset, length int) ([]byte, error)
AppendRange appends the specified range to the dest slice without new allocations.
func (*PieceTable) Bytes ¶
func (pt *PieceTable) Bytes() ([]byte, error)
Bytes assembles and returns all current text. Note: for large file rendering in future we'll write ReadAt methods, so as not to unload entire buffer into memory.
func (*PieceTable) Delete ¶
func (pt *PieceTable) Delete(offset, length int)
Delete removes a text fragment of specified length starting from offset.
func (*PieceTable) ForEachRange ¶
func (pt *PieceTable) ForEachRange(fn func(data []byte) error) error
ForEachRange sequentially calls a function for each data fragment. This allows processing text without allocating a single large slice.
func (*PieceTable) GetOriginalBuffer ¶
func (pt *PieceTable) GetOriginalBuffer() Buffer
GetOriginalBuffer returns the underlying original buffer.
func (*PieceTable) GetRange ¶
func (pt *PieceTable) GetRange(offset, length int) ([]byte, error)
GetRange returns a byte slice for the specified range.
func (*PieceTable) GetState ¶
func (pt *PieceTable) GetState() TableState
GetState returns a snapshot of the current table structure.
func (*PieceTable) Insert ¶
func (pt *PieceTable) Insert(offset int, data []byte)
Insert inserts data at the specified offset.
func (*PieceTable) LoadState ¶
func (pt *PieceTable) LoadState(s TableState)
LoadState restores the table structure from a snapshot.
func (*PieceTable) Size ¶
func (pt *PieceTable) Size() int
Size returns current logical length of the text.
func (*PieceTable) String ¶
func (pt *PieceTable) String() string
String returns current text as a string (convenient for tests). Ignore errors here to keep tests simple.
func (*PieceTable) UpdateOriginalBuffer ¶
func (pt *PieceTable) UpdateOriginalBuffer(buf Buffer)
UpdateOriginalBuffer safely replaces the original underlying buffer without losing the current logical state and additions. Used primarily for state recovery after a failed I/O operation.
type TableState ¶
TableState represents a snapshot of the PieceTable structure.
func (TableState) Equals ¶
func (s TableState) Equals(other TableState) bool
Equals compares two table states for structural identity.