model

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is array of line strings. Buffer API's require and returns unit of codepoint positions.

func (*Buffer) CreateTrack added in v0.3.0

func (buf *Buffer) CreateTrack(row int, bytePos int) *Track

CreateTrack creates a new position tracker.

func (*Buffer) GetLineAt

func (buf *Buffer) GetLineAt(row int) *Line

GetLineAt returns specified line.

func (*Buffer) GetLineCount

func (buf *Buffer) GetLineCount() int

GetLineCount returns count of lines.

func (*Buffer) Init

func (buf *Buffer) Init()

Init is initialize Buffer.

func (*Buffer) InsertString

func (buf *Buffer) InsertString(row int, column int, s string) (Position, error)

InsertString is insert string into specified position.

func (*Buffer) RemoveString

func (buf *Buffer) RemoveString(row int, column int, length int)

RemoveString is remove string specified range.

func (*Buffer) RemoveTrack added in v0.3.0

func (buf *Buffer) RemoveTrack(track *Track)

RemoveTrack removes a position tracker from the buffer.

func (*Buffer) ReplaceAll added in v0.3.0

func (buf *Buffer) ReplaceAll(r io.Reader)

ReplaceAll is replace a all content by Reader content

type BufferSegment added in v0.3.0

type BufferSegment struct {
	// contains filtered or unexported fields
}

func (BufferSegment) GetLine added in v0.3.0

func (bs BufferSegment) GetLine(lineIndex int) string

func (BufferSegment) GetLineCount added in v0.3.0

func (bs BufferSegment) GetLineCount() int

func (BufferSegment) GetSpan added in v0.3.0

func (bs BufferSegment) GetSpan(lineIndex int) Span

type Document

type Document interface {
	// Read returns Segment on specified range.
	Read(r Range) Segment

	// Render is presentation a contain string as structured element.
	Render() []Element

	// InsertString is insert string into specified position.
	InsertString(row int, bytePos int, s string)

	// Remove is remove string in specified range.
	Remove(row int, bytePos int, byteLen int)

	// ReplaceAll is replace a all content by Reader content
	ReplaceAll(r io.Reader)

	// Clear is remove all strings.
	Clear()

	// CreateTrack creates a new position tracker.
	CreateTrack(row int, bytePos int) *Track

	// GetLineBytes returns total byte count at specified line.
	GetLineBytes(index int) int

	// GetLineCount returns total line count.
	GetLineCount() int

	// GetVersion returns version. version is changed on modify string.
	GetVersion() uint
}

Document is model for TextBox, and contain string. most important method of Document is Render. TextBox get Element through Render method for rendering. and TextViewResolver is mapping Element to TextView. This results in TextBox is got TextView from structured Element. This is it rendering core. more details is see TextView, TextViewResolver

type Element added in v0.3.0

type Element interface {
	// GetRange returns range at specified index.
	// zero index is always inclusive all range.
	GetRange(index int) Range

	// GetRangeCount returns count of ranges.
	GetRangeCount() int

	// GetElement returns subelement at specified index.
	GetElement(index int) Element

	// GetElementCount returns count of elements.
	GetElementCount() int
}

Element is part of structured document. in example, Heading, Bold, Italic...

type FoldBlockElement added in v0.3.0

type FoldBlockElement struct {
	Ranges   []Range
	Children []Element
	Level    int
}

func (*FoldBlockElement) GetElement added in v0.3.0

func (f *FoldBlockElement) GetElement(index int) Element

func (*FoldBlockElement) GetElementCount added in v0.3.0

func (f *FoldBlockElement) GetElementCount() int

func (*FoldBlockElement) GetRange added in v0.3.0

func (f *FoldBlockElement) GetRange(index int) Range

func (*FoldBlockElement) GetRangeCount added in v0.3.0

func (f *FoldBlockElement) GetRangeCount() int

type GhostElement added in v0.3.0

type GhostElement struct {
	Range Range
	Index int
}

func (*GhostElement) GetElement added in v0.3.0

func (g *GhostElement) GetElement(index int) Element

func (*GhostElement) GetElementCount added in v0.3.0

func (g *GhostElement) GetElementCount() int

func (*GhostElement) GetRange added in v0.3.0

func (g *GhostElement) GetRange(index int) Range

func (*GhostElement) GetRangeCount added in v0.3.0

func (g *GhostElement) GetRangeCount() int

type Line

type Line struct {
	// contains filtered or unexported fields
}

Line is parts of buffer.

func (*Line) AppendString

func (l *Line) AppendString(s string)

AppendString is appending string into tail.

func (*Line) GetContent

func (l *Line) GetContent() string

GetContent is returns string of content.

func (*Line) InsertString

func (l *Line) InsertString(column int, s string)

InsertString is insert string into specified column.

func (*Line) PrependString

func (l *Line) PrependString(s string)

PrependString is insert string into line ahead.

func (*Line) Remove

func (l *Line) Remove(offset int, length int)

Remove is remove string specified range.

type PlainDocument added in v0.3.0

type PlainDocument struct {
	// contains filtered or unexported fields
}

PlainDocument is wrapper of Buffer. track a current cursor position.

func (*PlainDocument) Clear added in v0.3.0

func (doc *PlainDocument) Clear()

Clear is initialize Buffer.

func (*PlainDocument) CreateTrack added in v0.3.0

func (doc *PlainDocument) CreateTrack(row int, bytePos int) *Track

func (*PlainDocument) GetLineBytes added in v0.3.0

func (doc *PlainDocument) GetLineBytes(index int) int

func (*PlainDocument) GetLineCount added in v0.3.0

func (doc *PlainDocument) GetLineCount() int

func (*PlainDocument) GetLineString added in v0.3.0

func (doc *PlainDocument) GetLineString(lineIndex int) string

func (*PlainDocument) GetVersion added in v0.3.0

func (doc *PlainDocument) GetVersion() uint

func (*PlainDocument) Init added in v0.3.0

func (doc *PlainDocument) Init()

Init is initialize Buffer.

func (*PlainDocument) InsertString added in v0.3.0

func (doc *PlainDocument) InsertString(row int, bytePos int, s string)

func (*PlainDocument) Read added in v0.3.0

func (doc *PlainDocument) Read(r Range) Segment

func (*PlainDocument) Remove added in v0.3.0

func (doc *PlainDocument) Remove(row int, bytePos int, byteLen int)

func (*PlainDocument) Render added in v0.3.0

func (doc *PlainDocument) Render() []Element

func (*PlainDocument) ReplaceAll added in v0.3.0

func (doc *PlainDocument) ReplaceAll(r io.Reader)

type PlainElement added in v0.3.0

type PlainElement struct {
	Range Range
}

func (*PlainElement) GetElement added in v0.3.0

func (p *PlainElement) GetElement(index int) Element

func (*PlainElement) GetElementCount added in v0.3.0

func (p *PlainElement) GetElementCount() int

func (*PlainElement) GetRange added in v0.3.0

func (p *PlainElement) GetRange(index int) Range

func (*PlainElement) GetRangeCount added in v0.3.0

func (p *PlainElement) GetRangeCount() int

type Position

type Position struct {
	Row    int
	Column int
}

Position is representation of coordinate in two dimensional plane.

type Range added in v0.3.0

type Range struct {
	StartPosition Position
	EndPosition   Position
}

Range is range presentation by two Position. end column is exclusive.

func (Range) IsZero added in v0.3.0

func (r Range) IsZero() bool

type Segment added in v0.3.0

type Segment interface {
	// GetSpan returns span at specified line.
	GetSpan(lineIndex int) Span

	// GetLine returns string of line at specified line.
	GetLine(lineIndex int) string

	// GetLineCount returns line count.
	GetLineCount() int
}

Segment is reference to multiline string.

type Span added in v0.3.0

type Span struct {
	StartColumn int
	EndColumn   int
}

Span is range of single line. end column is exclusive.

func (Span) IsZero added in v0.3.0

func (sp Span) IsZero() bool

type Track added in v0.3.0

type Track struct {
	Position Position
	Lost     bool
}

Track is position of moves depend on Document changes.

Jump to

Keyboard shortcuts

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