text

package
v0.0.0-...-586e974 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: BSD-2-Clause, BSD-2-Clause Imports: 8 Imported by: 0

README

Build Status Coverage Status Go Report Card GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(a int) int

Abs returns the absolute value of a.

func Clamp

func Clamp(_min, _max, v int) int

Clamp clamps v to be in the range of _min and _max

func Max

func Max(a, b int) int

Max returns the maximum of the arguments

func Min

func Min(a, b int) int

Min 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
	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

func NewBuffer

func NewBuffer() Buffer

NewBuffer 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:
	//     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) Adjust

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

Adjust adjusts the region in place for the given position and delta

func (Region) Begin

func (r Region) Begin() int

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

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

func (r Region) Contains(point int) bool

Contains returns whether the region contains the given point or not.

func (Region) Cover

func (r Region) Cover(other Region) Region

Cover returns a region covering both regions

func (Region) Covers

func (r Region) Covers(r2 Region) bool

Covers returns whether the region fully covers the argument region

func (Region) Cut

func (r Region) Cut(other Region) (ret []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) Empty

func (r Region) Empty() bool

Empty returns whether the region is empty or not

func (Region) End

func (r Region) End() int

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

Intersection returns the Region that is the intersection of the two regions given

func (Region) Intersects

func (r Region) Intersects(other Region) bool

Intersects returns whether the two regions intersects or not

func (Region) Size

func (r Region) Size() int

Size returns the size of the region

func (Region) String

func (r Region) String() string

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

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 {}.

Jump to

Keyboard shortcuts

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