text

package module
v0.0.0-...-a501ee4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2020 License: BSD-2-Clause Imports: 9 Imported by: 88

README

Build Status Coverage Status Go Report Card GoDoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func Abs

func Abs(a int) int

Returns the absolute value of a.

func Clamp

func Clamp(_min, _max, v int) int

Clamps v to be in the range of _min and _max

func Max

func Max(a, b int) int

Returns the maximum of the arguments

func Min

func Min(a, b int) int

Returns the minimum of the arguments

Types

type Action

type Action interface {
	Apply()
	Undo()
}

Action defines an interface for Apply-ing and Undo-ing an action.

func NewEraseAction

func NewEraseAction(b Buffer, region Region) Action

NewEraseAction returns a new action that erases the given region in the given buffer

func NewInsertAction

func NewInsertAction(b Buffer, point int, value string) Action

NewInsertAction returns a new action that inserts the given string value at position point in the Buffer b.

func NewReplaceAction

func NewReplaceAction(b Buffer, region Region, value string) Action

NewReplaceAction returns a new action that replaces the data in the given buffers region with the provided value

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

func NewBuffer

func NewBuffer() Buffer

Returns a new empty Buffer

type BufferChangedCallback

type BufferChangedCallback func(buf Buffer, position, delta int)

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

func (*HasId) Id

func (i *HasId) Id() 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 Id

type Id int

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) Adjust

func (r *Region) Adjust(position, delta int)

Adjusts the region in place for the given position and delta

func (Region) Begin

func (r Region) Begin() int

Returns the starting point of the region, that would be whichever of A and B is the minimal value.

func (Region) Clip

func (r Region) Clip(other Region) (ret Region)

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) Contains

func (r Region) Contains(point int) bool

Returns whether the region contains the given point or not.

func (Region) Cover

func (r Region) Cover(other Region) Region

Returns a region covering both regions

func (Region) Covers

func (r Region) Covers(r2 Region) bool

Returns whether the region fully covers the argument region

func (Region) Cut

func (r Region) Cut(other Region) (ret []Region)

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) Empty

func (r Region) Empty() bool

Returns whether the region is empty or not

func (Region) End

func (r Region) End() int

Returns the ending point of the region, that would be whichever of A and B is the maximum value.

func (Region) Intersection

func (r Region) Intersection(other Region) (ret Region)

Returns the Region that is the intersection of the two regions given

func (Region) Intersects

func (r Region) Intersects(other Region) bool

Returns whether the two regions intersects or not

func (Region) Size

func (r Region) Size() int

Returns the size of the region

func (Region) String

func (r Region) String() string

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) Add

func (r *RegionSet) Add(r2 Region)

Add adds the given region to the set

func (*RegionSet) AddAll

func (r *RegionSet) AddAll(rs []Region)

AddAll adds all regions in the array to the set, merging any overlapping regions into a single region

func (*RegionSet) AddOnChange

func (r *RegionSet) AddOnChange(key string, cb func())

Adds a callback func() identified with the given key. If a callback is already defined for that name, it is overwritten

func (*RegionSet) Adjust

func (r *RegionSet) Adjust(position, delta int)

Adjust adjusts all the regions in the set

func (*RegionSet) Clear

func (r *RegionSet) Clear()

Clear clears the set

func (*RegionSet) ClearOnChange

func (r *RegionSet) ClearOnChange(key string)

Removes the callback func() associated with the given key.

func (*RegionSet) Contains

func (r *RegionSet) Contains(r2 Region) bool

Contains returns whether the specified region is part of the set or not

func (*RegionSet) Cut

func (r *RegionSet) Cut(r2 Region) (ret RegionSet)

Cut cuts away the provided region from the set, and returns the new set

func (*RegionSet) Get

func (r *RegionSet) Get(i int) Region

Get returns the region at index i

func (*RegionSet) HasEmpty

func (r *RegionSet) HasEmpty() bool

HasEmpty returns the opposite of #HasNonEmpty

func (*RegionSet) HasNonEmpty

func (r *RegionSet) HasNonEmpty() bool

HasNonEmpty returns whether the set contains at least one region that isn't empty.

func (*RegionSet) Len

func (r *RegionSet) Len() int

Len returns the number of regions contained in the set

func (*RegionSet) Regions

func (r *RegionSet) Regions() (ret []Region)

Regions returns a copy of the regions in the set

func (*RegionSet) Subtract

func (r *RegionSet) Subtract(r2 Region)

Subtract removes the given region from the set

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) InsertR

func (s *SerializedBuffer) InsertR(point int, data []rune) error

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) Bool

func (s *Settings) Bool(name string, def ...interface{}) bool

func (*Settings) ClearOnChange

func (s *Settings) ClearOnChange(key string)

Removes the OnChangeCallback associated with the given key.

func (*Settings) Erase

func (s *Settings) Erase(name string)

Erases the setting associated with the given key from this settings object

func (*Settings) Get

func (s *Settings) Get(name string, def ...interface{}) interface{}

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

func (s *Settings) Has(name string) bool

Returns whether the setting identified by this key exists in this settings object

func (*Settings) Int

func (s *Settings) Int(name string, def ...interface{}) int

func (*Settings) MarshalJSON

func (s *Settings) MarshalJSON() (data []byte, err error)

func (*Settings) Parent

func (s *Settings) Parent() SettingsInterface

Returns the parent Settings of this Settings object

func (*Settings) Set

func (s *Settings) Set(name string, val interface{})

Sets the setting identified with the given key to the specified value

func (*Settings) SetParent

func (s *Settings) SetParent(p SettingsInterface)

Sets the parent Settings of this Settings object

func (*Settings) String

func (s *Settings) String(name string, def ...interface{}) string

func (*Settings) UnmarshalJSON

func (s *Settings) UnmarshalJSON(data []byte) error

type SettingsInterface

type SettingsInterface interface {
	Settings() *Settings
}

Defines an interface for types that have settings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL