Documentation ¶
Index ¶
- func Abs(a int) int
- func Clamp(_min, _max, v int) int
- func Max(a, b int) int
- func Min(a, b int) int
- type Action
- type Buffer
- type BufferChangedCallback
- type BufferObserver
- type CompositeAction
- type InnerBufferInterface
- type Region
- func (r *Region) Adjust(position, delta int)
- func (r Region) Begin() int
- func (r Region) Clip(other Region) (ret Region)
- func (r Region) Contains(point int) bool
- func (r Region) Cover(other Region) Region
- func (r Region) Covers(r2 Region) bool
- func (r Region) Cut(other Region) (ret []Region)
- func (r Region) Empty() bool
- func (r Region) End() int
- func (r Region) Intersection(other Region) (ret Region)
- func (r Region) Intersects(other Region) bool
- func (r Region) Size() int
- func (r Region) String() string
- type RegionSet
- func (r *RegionSet) Add(r2 Region)
- func (r *RegionSet) AddAll(rs []Region)
- func (r *RegionSet) Adjust(position, delta int)
- func (r *RegionSet) Clear()
- func (r *RegionSet) Contains(r2 Region) bool
- func (r *RegionSet) Cut(r2 Region) (ret RegionSet)
- func (r *RegionSet) Get(i int) Region
- func (r *RegionSet) HasEmpty() bool
- func (r *RegionSet) HasNonEmpty() bool
- func (r *RegionSet) Len() int
- func (r *RegionSet) Regions() (ret []Region)
- func (r *RegionSet) Subtract(r2 Region)
- type SerializedBuffer
- func (s *SerializedBuffer) Close()
- func (s *SerializedBuffer) Erase(point, length int) error
- func (s *SerializedBuffer) Index(i int) rune
- func (s *SerializedBuffer) InsertR(point int, data []rune) error
- func (s *SerializedBuffer) RowCol(point int) (row, col int)
- func (s *SerializedBuffer) Size() int
- func (s *SerializedBuffer) SubstrR(re Region) []rune
- func (s *SerializedBuffer) TextPoint(row, col int) (i int)
- type SerializedOperation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Action ¶
type Action interface { Apply() Undo() }
Action defines an interface for Apply-ing and Undo-ing an action.
func NewEraseAction ¶
NewEraseAction returns a new action that erases the given region in the given buffer
func NewInsertAction ¶
NewInsertAction returns a new action that inserts the given string value at position point in the Buffer b.
type Buffer ¶
type Buffer interface { fmt.Stringer InnerBufferInterface util.IDInterface // Adds the given observer to this buffer's list of observers AddObserver(BufferObserver) error // Removes the given observer from this buffer's list of observers RemoveObserver(BufferObserver) error SetName(string) error Name() string SetFileName(string) error FileName() string // Inserts the given string at the given location. // Typically just a wrapper around #InsertR Insert(point int, svalue string) error // Returns the string of the specified Region. // Typically just a wrapper around #SubstrR Substr(r Region) string ChangeCount() int // Returns the line region at the given offset Line(offset int) Region // Returns a Region starting at the start of a line and ending at the end of a (possibly different) line LineR(r Region) Region // Returns the lines intersecting the region Lines(r Region) []Region // Like #Line, but includes the line endings FullLine(offset int) Region // Like #LineR, but includes the line endings FullLineR(r Region) Region // Returns the word region at the given text offset Word(offset int) Region // Returns the Region covering the start of the word in r.Begin() // to the end of the word in r.End() WordR(r Region) Region }
Buffer defines the full buffer interface
type BufferChangedCallback ¶
The BufferChangedCallback is called everytime a buffer is changed.
type BufferObserver ¶
type BufferObserver interface { // Called after Buffer.Erase has executed. // // Modifying the buffer from within the callback will result in an error/nop, but if // it would work the following would restore the buffer's contents as it was before // Erase was executed: // bufferChanged.InsertR(regionRemoved.Begin(), dataRemoved) Erased(bufferChanged Buffer, regionRemoved Region, dataRemoved []rune) // Called after Buffer.Insert/InsertR has executed. // // Modifying the buffer from within the callback will result in an error/nop, but if // it would work the following would restore the buffer's contents as it was before // InsertR was executed: // bufferChanged.Erase(regionInserted.Begin(), regionInserted.Size()) Inserted(bufferChanged Buffer, regionInserted Region, dataInserted []rune) }
BufferObserver tracking changes made to a buffer. (http://en.wikipedia.org/wiki/Observer_pattern)
Modifying the buffer from within the callback is not allowed and will result in a NOP. This is because if there are multiple observers attached to the buffer, they should all first be up to date with the current change before another one is introduced.
type CompositeAction ¶
type CompositeAction struct {
// contains filtered or unexported fields
}
CompositeAction is just a structure containing multiple Action items
func (*CompositeAction) Add ¶
func (ca *CompositeAction) Add(a Action)
Add adds the action to this CompositeAction, without first executing the action
func (*CompositeAction) AddExec ¶
func (ca *CompositeAction) AddExec(a Action)
AddExec executes the provided action and then adds the action to this CompositeAction
func (*CompositeAction) Apply ¶
func (ca *CompositeAction) Apply()
Apply all the sub-actions in order of this CompositeAction
func (*CompositeAction) Len ¶
func (ca *CompositeAction) Len() int
Len returns the number of sub-actions this CompositeAction object contains
func (CompositeAction) String ¶
func (ca CompositeAction) String() string
func (*CompositeAction) Undo ¶
func (ca *CompositeAction) Undo()
Undo all the sub-actions in reverse order of this CompositeAction
type InnerBufferInterface ¶
type InnerBufferInterface interface { // Returns the size of a buffer Size() int // Returns the runes in the specified Region. // Implementations should clamp the region // as appropriate. SubstrR(r Region) []rune // Inserts the given rune data at the // specified point in the buffer. InsertR(point int, data []rune) error // Erases "length" units from "point". Erase(point, length int) error // Returns the rune at the given index Index(int) rune // Convert a text position into a row and column. RowCol(point int) (row, col int) // Inverse of #RowCol, converting a row and column // into a text position. TextPoint(row, col int) (i int) // Close the buffer, freeing any associated resources. Close() }
The InnerBufferInterface defines a minimal interface that different buffer implementations need to implement.
type Region ¶
type Region struct {
A, B int
}
Region defines a Region from point A to B. A can be less than B, in which case the selection is inverted.
func (Region) Begin ¶
Begin returns the starting point of the region, that would be whichever of A and B is the minimal value.
func (Region) Clip ¶
Clip clips this Region against the Region provided in the argument. That would be if any part of this region is inside of the region specified by the argument, that part of the region is removed from this region.
func (Region) Cut ¶
Cut cuts away the parts of the region that is in the argument region. This is similar to Clip, except that the result can be multiple regions.
func (Region) End ¶
End returns the ending point of the region, that would be whichever of A and B is the maximum value.
func (Region) Intersection ¶
Intersection returns the Region that is the intersection of the two regions given
func (Region) Intersects ¶
Intersects returns whether the two regions intersects or not
type RegionSet ¶
type RegionSet struct {
// contains filtered or unexported fields
}
RegionSet manages multiple regions, merging any regions overlapping.
Note that regions that are right next to each other are not merged into a single region. This is because otherwise it would not be possible to have multiple cursors right next to each other.
func (*RegionSet) AddAll ¶
AddAll adds all regions in the array to the set, merging any overlapping regions into a single region
func (*RegionSet) Contains ¶
Contains returns whether the specified region is part of the set or not
func (*RegionSet) HasNonEmpty ¶
HasNonEmpty returns whether the set contains at least one region that isn't empty.
type SerializedBuffer ¶
type SerializedBuffer struct {
// contains filtered or unexported fields
}
SerializedBuffer is a type that serializes all read/write operations from/to the inner buffer implementation.
func (*SerializedBuffer) Close ¶
func (s *SerializedBuffer) Close()
Close closes the buffer operations.
func (*SerializedBuffer) Erase ¶
func (s *SerializedBuffer) Erase(point, length int) error
Erase erases "length" units from "point".
func (*SerializedBuffer) Index ¶
func (s *SerializedBuffer) Index(i int) rune
Index returns the rune at the given index
func (*SerializedBuffer) InsertR ¶
func (s *SerializedBuffer) InsertR(point int, data []rune) error
InsertR inserts the given rune data at the specified point in the buffer.
func (*SerializedBuffer) RowCol ¶
func (s *SerializedBuffer) RowCol(point int) (row, col int)
RowCol convert a text position into a row and column.
func (*SerializedBuffer) Size ¶
func (s *SerializedBuffer) Size() int
Size returns the size of the buffer.
func (*SerializedBuffer) SubstrR ¶
func (s *SerializedBuffer) SubstrR(re Region) []rune
SubstrR returns the runes in the specified Region.
func (*SerializedBuffer) TextPoint ¶
func (s *SerializedBuffer) TextPoint(row, col int) (i int)
TextPoint inverse of #RowCol, converting a row and column into a text position.
type SerializedOperation ¶
type SerializedOperation func() interface{}
SerializedOperation is a function return interface {}.