{"modulePath":"github.com/oligo/gvcode","version":"v0.8.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package buffer\n\n## Constants\n\n```go\nconst (\n\t// BiasForward sets the rule that:\n\t//\n\t// - when the marker is at the start of the edit, marker moves\n\t// to the end of the inserted text.\n\t//\n\t// - when the marker is at the end of the edit, it is pushed to\n\t// the end of the inserted text\n\tBiasForward = iota\n\n\t// BiasBackward sets the rule that:\n\t//\n\t// - when the marker is at the start of the edit, it keeps staying\n\t// at the begining.\n\t//\n\t// - when the marker is at the end of the edit, it gets pulled to\n\t// the start of the inserted text.\n\tBiasBackward\n)\n```\n\n## Functions\n\n```go\nfunc SetDebug(enable bool)\n```\nSet debug mode or not. In debug mode, the internal states of PieceTable is printed to console.\n\n## Types\n\n```go\ntype CursorPos struct {\n\t// start rune offset\n\tStart int\n\t// end rune offset\n\tEnd int\n}\n```\nCursorPos keep track of the previous cursor position of undo/redo.\n\n```go\ntype Marker struct {\n\t// contains filtered or unexported fields\n}\n```\nMarker is a text buffer annotation that tracks a logical location in the buffer over time. It tries to remain logically stationary even when the content changes.\n\n```go\nfunc (m *Marker) Offset() int\n```\nOffset returns the rune offset of the marker in the document.\n\n```go\ntype MarkerBias uint8\n```\nThe specific rule that resolves ambiguity when an edit happens exactly at a marker's position.\n\n```go\ntype PieceTable struct {\n\t// contains filtered or unexported fields\n}\n```\nPieceTable implements a piece table data structure. See the following resources for more information:\n\n[https://en.wikipedia.org/wiki/Piece\\_table](https://en.wikipedia.org/wiki/Piece_table)\n\n[https://www.cs.unm.edu/~crowley/papers/sds.pdf](https://www.cs.unm.edu/~crowley/papers/sds.pdf)\n\nThis implementation is heavily inspired by the design described in James Brown's Piece Chain([http://www.catch22.net/tuts/neatpad/piece-chains](http://www.catch22.net/tuts/neatpad/piece-chains)).\n\n```go\nfunc NewPieceTable(text []byte) *PieceTable\n```\n\n```go\nfunc NewTextSource() *PieceTable\n```\n\n```go\nfunc (pt *PieceTable) Changed() bool\n```\n\n```go\nfunc (pt *PieceTable) CreateMarker(runeOff int, bais MarkerBias) (*Marker, error)\n```\n\n```go\nfunc (pt *PieceTable) GroupOp()\n```\nGroup operations such as insert, earase or replace in a batch. Nested call share the same single batch.\n\n```go\nfunc (pt *PieceTable) Len() int\n```\nSize returns the total length of the document data in runes.\n\n```go\nfunc (pt *PieceTable) Lines() int\n```\n\n```go\nfunc (pt *PieceTable) ReadAt(p []byte, offset int64) (total int, err error)\n```\nReadAt implements [io.ReaderAt](/io#ReaderAt)\n\n```go\nfunc (pt *PieceTable) ReadRuneAt(runeOff int) (rune, error)\n```\n\n```go\nfunc (pt *PieceTable) Redo() ([]CursorPos, bool)\n```\n\n```go\nfunc (pt *PieceTable) RemoveMarker(m *Marker)\n```\n\n```go\nfunc (pt *PieceTable) Replace(startOff, endOff int, text string) bool\n```\nReplace removes text from startOff to endOff(exclusive), and insert text at the position of startOff.\n\n```go\nfunc (pt *PieceTable) RuneOffset(runeOff int) int\n```\nRuneOffset returns the byte offset for the rune at position runeOff.\n\n```go\nfunc (pt *PieceTable) SetText(text []byte)\n```\n\n```go\nfunc (pt *PieceTable) Size() int\n```\n\n```go\nfunc (pt *PieceTable) UnGroupOp()\n```\nUngroup a batch. Latter insert, earase or replace operations outside of a group is not batched.\n\nThis 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.\n\n```go\nfunc (pt *PieceTable) Undo() ([]CursorPos, bool)\n```\n\n```go\ntype TextReader interface {\n\tio.Seeker\n\tio.Reader\n\t//ReadAll returns the contents of the editor.\n\tReadAll(buf []byte) []byte\n}\n```\n\n```go\nfunc NewReader(src TextSource) TextReader\n```\n\n```go\ntype TextSource interface {\n\tio.ReaderAt\n\n\t// ReadRuneAt reads the rune starting at the given rune offset, if any.\n\tReadRuneAt(runeOff int) (rune, error)\n\n\t// RuneOffset returns the byte offset for the rune at position runeIndex.\n\tRuneOffset(runeIndex int) int\n\n\t// Lines returns the total number of lines/paragraphs of the source.\n\tLines() int\n\n\t// Len is the length of the editor contents, in runes.\n\tLen() int\n\n\t// Size returns the size of the editor content in bytes.\n\tSize() int\n\n\t// SetText reset the buffer and replace the content of the buffer with the provided text.\n\tSetText(text []byte)\n\n\t// Replace replace text from startOff to endOff(exclusive) with text.\n\tReplace(startOff, endOff int, text string) bool\n\n\t// CreateMarker adds a new marker at position runeOff, with the specified bais. A bais\n\t// controlls how the markers move when the insertion/deletion happens at the boundary location\n\t// of the marker.\n\tCreateMarker(runeOff int, bais MarkerBias) (*Marker, error)\n\t// RemoveMarker removes a marker from the text source.\n\tRemoveMarker(m *Marker)\n\n\t// Undo the last insert, erase, or replace, or a group of operations.\n\t// It returns all the cursor positions after undo.\n\tUndo() ([]CursorPos, bool)\n\t// Redo the last insert, erase, or replace, or a group of operations.\n\t// It returns all the cursor positions after undo.\n\tRedo() ([]CursorPos, bool)\n\n\t// Group operations such as insert, earase or replace in a batch.\n\t// Nested call share the same single batch.\n\tGroupOp()\n\n\t// Ungroup a batch. Latter insert, earase or replace operations outside of\n\t// a group is not batched.\n\tUnGroupOp()\n\n\t// Changed report whether the contents have changed since the last call to Changed.\n\tChanged() bool\n}\n```\nTextSource provides data for editor.\n\nBasic 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.\n\n","path":"github.com/oligo/gvcode/internal/buffer","name":"buffer","synopsis":"","isRedistributable":true}
