Documentation ¶
Index ¶
- Variables
- 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 HasId
- type HasSettings
- type Id
- type IdInterface
- type InnerBufferInterface
- type OnChangeCallback
- 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) AddOnChange(key string, cb func())
- func (r *RegionSet) Adjust(position, delta int)
- func (r *RegionSet) Clear()
- func (r *RegionSet) ClearOnChange(key string)
- 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
- type Settings
- func (s *Settings) AddOnChange(key string, cb OnChangeCallback)
- func (s *Settings) Bool(name string, def ...interface{}) bool
- func (s *Settings) ClearOnChange(key string)
- func (s *Settings) Erase(name string)
- func (s *Settings) Get(name string, def ...interface{}) interface{}
- func (s *Settings) Has(name string) bool
- func (s *Settings) Int(name string, def ...interface{}) int
- func (s *Settings) MarshalJSON() (data []byte, err error)
- func (s *Settings) Parent() SettingsInterface
- func (s *Settings) Set(name string, val interface{})
- func (s *Settings) SetParent(p SettingsInterface)
- func (s *Settings) String(name string, def ...interface{}) string
- func (s *Settings) UnmarshalJSON(data []byte) error
- type SettingsInterface
Constants ¶
This section is empty.
Variables ¶
var ( ErrObserverAlreadyAdded = fmt.Errorf("Observer has already been added") ErrObserverNotInList = fmt.Errorf("Observer is not in the list of observers") ErrNothingToInsert = fmt.Errorf("Nothing to insert") ErrNothingToErase = fmt.Errorf("Nothing to erase") ErrBufferInCallbacks = fmt.Errorf("Buffer can not be modified when in a callback") )
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 IdInterface // DEPRECATED! Use AddObserver instead! Add a BufferChangedCallback to the buffer AddCallback(cb BufferChangedCallback) error // 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 }
The full buffer interface defines
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: // changed_buffer.InsertR(region_removed.Begin(), data_removed) Erased(changed_buffer Buffer, region_removed Region, data_removed []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: // changed_buffer.Erase(region_inserted.Begin(), region_inserted.Size()) Inserted(changed_buffer Buffer, region_inserted Region, data_inserted []rune) }
An observer (http://en.wikipedia.org/wiki/Observer_pattern) tracking changes made to a buffer.
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 HasId ¶
type HasId struct {
// contains filtered or unexported fields
}
An utility struct typically embedded to give the type a unique id
type HasSettings ¶
type HasSettings struct {
// contains filtered or unexported fields
}
An utility struct that is typically embedded in other type structs to make that type implement the SettingsInterface
func (*HasSettings) Settings ¶
func (s *HasSettings) Settings() *Settings
type IdInterface ¶
type IdInterface interface {
Id() Id
}
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 OnChangeCallback ¶
type OnChangeCallback func(name string)
type Region ¶
type Region struct {
A, B int
}
Defines a Region from point A to B. A can be less than B, in which case the selection is inverted.
func (Region) Begin ¶
Returns the starting point of the region, that would be whichever of A and B is the minimal value.
func (Region) 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 ¶
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 ¶
Returns the ending point of the region, that would be whichever of A and B is the maximum value.
func (Region) Intersection ¶
Returns the Region that is the intersection of the two regions given
func (Region) Intersects ¶
Returns whether the two regions intersects or not
type RegionSet ¶
type RegionSet struct {
// contains filtered or unexported fields
}
The 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) AddOnChange ¶
Adds a callback func() identified with the given key. If a callback is already defined for that name, it is overwritten
func (*RegionSet) ClearOnChange ¶
Removes the callback func() associated with the given key.
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
}
A type that serializes all read/write operations from/to the inner buffer implementation
func (*SerializedBuffer) Close ¶
func (s *SerializedBuffer) Close()
func (*SerializedBuffer) Erase ¶
func (s *SerializedBuffer) Erase(point, length int) error
func (*SerializedBuffer) Index ¶
func (s *SerializedBuffer) Index(i int) rune
func (*SerializedBuffer) RowCol ¶
func (s *SerializedBuffer) RowCol(point int) (row, col int)
func (*SerializedBuffer) Size ¶
func (s *SerializedBuffer) Size() int
func (*SerializedBuffer) SubstrR ¶
func (s *SerializedBuffer) SubstrR(re Region) []rune
func (*SerializedBuffer) TextPoint ¶
func (s *SerializedBuffer) TextPoint(row, col int) (i int)
type SerializedOperation ¶
type SerializedOperation func() interface{}
A type that serializes all read/write operations from/to the inner buffer implementation
type Settings ¶
type Settings struct { HasId // contains filtered or unexported fields }
func NewSettings ¶
func NewSettings() Settings
func (*Settings) AddOnChange ¶
func (s *Settings) AddOnChange(key string, cb OnChangeCallback)
Adds a OnChangeCallback identified with the given key. If a callback is already defined for that name, it is overwritten
func (*Settings) ClearOnChange ¶
Removes the OnChangeCallback associated with the given key.
func (*Settings) Get ¶
Get the setting identified with the given name. An optional default value may be specified. If the setting does not exist in this object, the parent if available will be queried.
func (*Settings) Has ¶
Returns whether the setting identified by this key exists in this settings object
func (*Settings) MarshalJSON ¶
func (*Settings) Parent ¶
func (s *Settings) Parent() SettingsInterface
Returns the parent Settings of this Settings object
func (*Settings) SetParent ¶
func (s *Settings) SetParent(p SettingsInterface)
Sets the parent Settings of this Settings object
func (*Settings) UnmarshalJSON ¶
type SettingsInterface ¶
type SettingsInterface interface {
Settings() *Settings
}
Defines an interface for types that have settings