Documentation
¶
Index ¶
- func SetDebug(enable bool)
- type CursorPos
- type PieceTable
- func (pt *PieceTable) Changed() bool
- func (pt *PieceTable) Erase(startOff, endOff int) bool
- func (pt *PieceTable) GroupOp()
- func (pt *PieceTable) Insert(runeIndex int, text string) bool
- func (pt *PieceTable) Inspect()
- func (pt *PieceTable) Len() int
- func (pt *PieceTable) Redo() ([]CursorPos, bool)
- func (pt *PieceTable) Replace(startOff, endOff int, text string) bool
- func (pt *PieceTable) SetText(text []byte)
- func (pt *PieceTable) UnGroupOp()
- func (pt *PieceTable) Undo() ([]CursorPos, bool)
- type PieceTableReader
- func (r *PieceTableReader) Lines() int
- func (r *PieceTableReader) Read(p []byte) (int, error)
- func (r *PieceTableReader) ReadAt(p []byte, offset int64) (total int, err error)
- func (r *PieceTableReader) ReadRuneAt(runeOff int) (rune, error)
- func (r *PieceTableReader) RuneOffset(runeOff int) int
- func (r *PieceTableReader) Seek(offset int64, whence int) (int64, error)
- func (r *PieceTableReader) Text(buf []byte) []byte
- 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 (*PieceTable) Changed ¶
func (pt *PieceTable) Changed() bool
func (*PieceTable) Erase ¶
func (pt *PieceTable) Erase(startOff, endOff int) 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) Insert ¶
func (pt *PieceTable) Insert(runeIndex int, text string) bool
Insert insert text at the logical position specifed by runeIndex. runeIndex is measured by rune. There are 2 scenarios need to be handled:
- Insert in the middle of a piece.
- Insert at the boundary of two pieces.
func (*PieceTable) Inspect ¶
func (pt *PieceTable) Inspect()
Inspect prints the internal of the piece table. For debug purpose only.
func (*PieceTable) Len ¶
func (pt *PieceTable) Len() int
Size returns the total length of the document data in runes.
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) SetText ¶
func (pt *PieceTable) SetText(text []byte)
func (*PieceTable) UnGroupOp ¶
func (pt *PieceTable) UnGroupOp()
Ungroup a batch. Latter insert, earase or replace operations outside of a group is not batched.
func (*PieceTable) Undo ¶
func (pt *PieceTable) Undo() ([]CursorPos, bool)
type PieceTableReader ¶
type PieceTableReader struct { *PieceTable // contains filtered or unexported fields }
PieceTableReader implements a TextSource.
func NewTextSource ¶
func NewTextSource() *PieceTableReader
func (*PieceTableReader) Lines ¶
func (r *PieceTableReader) Lines() int
func (*PieceTableReader) Read ¶
func (r *PieceTableReader) Read(p []byte) (int, error)
Read implements io.Reader.
func (*PieceTableReader) ReadAt ¶
func (r *PieceTableReader) ReadAt(p []byte, offset int64) (total int, err error)
ReadAt implements io.ReaderAt.
func (*PieceTableReader) ReadRuneAt ¶
func (r *PieceTableReader) ReadRuneAt(runeOff int) (rune, error)
func (*PieceTableReader) RuneOffset ¶
func (r *PieceTableReader) RuneOffset(runeOff int) int
RuneOffset returns the byte offset for the rune at position runeOff.
func (*PieceTableReader) Seek ¶
func (r *PieceTableReader) Seek(offset int64, whence int) (int64, error)
Seek implements io.Seeker.
func (*PieceTableReader) Text ¶
func (r *PieceTableReader) Text(buf []byte) []byte
type TextSource ¶
type TextSource interface { io.Seeker io.Reader 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 //Text returns the contents of the editor. Text(buf []byte) []byte // Len is the length of the editor contents, in runes. Len() int // SetText reset the buffer and replace the content of the buffer with the provided text. SetText(text []byte) // Insert insert text at the logical position specifed by runeIndex measured by rune. Insert(runeIndex int, text string) bool // Delete text from startOff to endOff(exclusive). Erase(startOff, endOff int) bool // 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.