Documentation
¶
Index ¶
- func SetDebug(enable bool)
- type CursorPos
- type PieceTable
- func (pt *PieceTable) Changed() bool
- func (pt *PieceTable) GroupOp()
- func (pt *PieceTable) Len() int
- func (pt *PieceTable) Lines() int
- func (pt *PieceTable) ReadAt(p []byte, offset int64) (total int, err error)
- func (pt *PieceTable) ReadRuneAt(runeOff int) (rune, error)
- func (pt *PieceTable) Redo() ([]CursorPos, bool)
- func (pt *PieceTable) Replace(startOff, endOff int, text string) bool
- func (pt *PieceTable) RuneOffset(runeOff int) int
- func (pt *PieceTable) SetText(text []byte)
- func (pt *PieceTable) Size() int
- func (pt *PieceTable) UnGroupOp()
- func (pt *PieceTable) Undo() ([]CursorPos, bool)
- type TextReader
- type TextSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PieceTable ¶
type PieceTable struct {
// contains filtered or unexported fields
}
PieceTable implements a piece table data structure. See the following resources for more information:
https://en.wikipedia.org/wiki/Piece_table
https://www.cs.unm.edu/~crowley/papers/sds.pdf
This implementation is heavily inspired by the design described in James Brown's Piece Chain(http://www.catch22.net/tuts/neatpad/piece-chains).
func NewPieceTable ¶
func NewPieceTable(text []byte) *PieceTable
func NewTextSource ¶
func NewTextSource() *PieceTable
func (*PieceTable) Changed ¶
func (pt *PieceTable) Changed() bool
func (*PieceTable) GroupOp ¶
func (pt *PieceTable) GroupOp()
Group operations such as insert, earase or replace in a batch. Nested call share the same single batch.
func (*PieceTable) Len ¶
func (pt *PieceTable) Len() int
Size returns the total length of the document data in runes.
func (*PieceTable) Lines ¶ added in v0.3.0
func (pt *PieceTable) Lines() int
func (*PieceTable) ReadAt ¶ added in v0.3.0
func (pt *PieceTable) ReadAt(p []byte, offset int64) (total int, err error)
ReadAt implements io.ReaderAt
func (*PieceTable) ReadRuneAt ¶ added in v0.3.0
func (pt *PieceTable) ReadRuneAt(runeOff int) (rune, error)
func (*PieceTable) Redo ¶
func (pt *PieceTable) Redo() ([]CursorPos, bool)
func (*PieceTable) Replace ¶
func (pt *PieceTable) Replace(startOff, endOff int, text string) bool
Replace removes text from startOff to endOff(exclusive), and insert text at the position of startOff.
func (*PieceTable) RuneOffset ¶ added in v0.3.0
func (pt *PieceTable) RuneOffset(runeOff int) int
RuneOffset returns the byte offset for the rune at position runeOff.
func (*PieceTable) SetText ¶
func (pt *PieceTable) SetText(text []byte)
func (*PieceTable) Size ¶ added in v0.3.0
func (pt *PieceTable) Size() int
func (*PieceTable) UnGroupOp ¶
func (pt *PieceTable) UnGroupOp()
Ungroup a batch. Latter insert, earase or replace operations outside of a group is not batched.
This results in global batch op if writes are accessed from concurrent goroutine, may be not what the user want. But in our scenarios most of the time it is safe to do so.
func (*PieceTable) Undo ¶
func (pt *PieceTable) Undo() ([]CursorPos, bool)
type TextReader ¶ added in v0.3.0
type TextReader interface {
io.Seeker
io.Reader
//ReadAll returns the contents of the editor.
ReadAll(buf []byte) []byte
}
func NewReader ¶ added in v0.3.0
func NewReader(src TextSource) TextReader
type TextSource ¶
type TextSource interface {
io.ReaderAt
// ReadRuneAt reads the rune starting at the given rune offset, if any.
ReadRuneAt(runeOff int) (rune, error)
// RuneOffset returns the byte offset for the rune at position runeIndex.
RuneOffset(runeIndex int) int
// Lines returns the total number of lines/paragraphs of the source.
Lines() int
// Len is the length of the editor contents, in runes.
Len() int
// Size returns the size of the editor content in bytes.
Size() int
// SetText reset the buffer and replace the content of the buffer with the provided text.
SetText(text []byte)
// Replace replace text from startOff to endOff(exclusive) with text.
Replace(startOff, endOff int, text string) bool
// Undo the last insert, erase, or replace, or a group of operations.
// It returns all the cursor positions after undo.
Undo() ([]CursorPos, bool)
// Redo the last insert, erase, or replace, or a group of operations.
// It returns all the cursor positions after undo.
Redo() ([]CursorPos, bool)
// Group operations such as insert, earase or replace in a batch.
// Nested call share the same single batch.
GroupOp()
// Ungroup a batch. Latter insert, earase or replace operations outside of
// a group is not batched.
UnGroupOp()
// Changed report whether the contents have changed since the last call to Changed.
Changed() bool
}
TextSource provides data for editor.
Basic editing operations, such as insert, delete, replace, undo/redo are supported. If used with GroupOp and UnGroupOp, the undo and redo operations can be batched.