document

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Branch

type Branch struct {
	Text     string
	Children []Branch
}

Branch is a detached subtree used by copy and paste operations.

type Document

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

Document stores an ordered forest. Most maps contain one root, but accepting a forest lets Beech open indentation-based files without changing them.

func New

func New(rootText string) *Document

New creates a document with one root node.

func NewEmpty

func NewEmpty() *Document

NewEmpty creates a document without roots. It is intended for parsers.

func (*Document) AddChild

func (d *Document) AddChild(parent NodeID, text string) (NodeID, bool)

AddChild adds a child after the parent's existing children.

func (*Document) AddSiblingAfter

func (d *Document) AddSiblingAfter(id NodeID, text string) (NodeID, bool)

AddSiblingAfter adds a node immediately after id.

func (*Document) AppendChild

func (d *Document) AppendChild(parent NodeID, text string) (NodeID, error)

AppendChild adds a child to parent.

func (*Document) AppendRoot

func (d *Document) AppendRoot(text string) NodeID

AppendRoot adds a root at the end of the forest.

func (*Document) Children

func (d *Document) Children(id NodeID) []NodeID

Children returns a node's children in document order.

func (*Document) Clone

func (d *Document) Clone() *Document

Clone returns a deep copy of the document.

func (*Document) CopyBranch

func (d *Document) CopyBranch(id NodeID) (Branch, bool)

CopyBranch returns a detached copy of id and its descendants.

func (*Document) Delete

func (d *Document) Delete(id NodeID) bool

Delete removes a node and all descendants. The final root cannot be removed.

func (*Document) Demote

func (d *Document) Demote(id NodeID) bool

Demote moves a node under its previous sibling.

func (*Document) Len

func (d *Document) Len() int

Len returns the number of nodes.

func (*Document) MoveSibling

func (d *Document) MoveSibling(id NodeID, delta int) bool

MoveSibling moves a node by delta positions among its siblings.

func (*Document) Node

func (d *Document) Node(id NodeID) (Node, bool)

Node returns a copy of one node.

func (*Document) Parent

func (d *Document) Parent(id NodeID) NodeID

Parent returns a node's parent, or NoNode for a root or unknown node.

func (*Document) PasteChild

func (d *Document) PasteChild(parent NodeID, branch Branch) (NodeID, bool)

PasteChild clones branch as the last child of parent.

func (*Document) PasteSibling

func (d *Document) PasteSibling(id NodeID, branch Branch) (NodeID, bool)

PasteSibling clones branch immediately after id.

func (*Document) Promote

func (d *Document) Promote(id NodeID) bool

Promote moves a non-root node after its parent.

func (*Document) Rename

func (d *Document) Rename(id NodeID, text string) bool

Rename changes a node's text. Empty text is rejected.

func (*Document) Roots

func (d *Document) Roots() []NodeID

Roots returns the top-level nodes in document order.

func (*Document) Text

func (d *Document) Text(id NodeID) string

Text returns a node's text, or the empty string for an unknown node.

func (*Document) Validate

func (d *Document) Validate() error

Validate checks all structural invariants.

type Node

type Node struct {
	ID       NodeID
	Text     string
	Parent   NodeID
	Children []NodeID
}

Node is one entry in an ordered tree.

type NodeID

type NodeID uint64

NodeID identifies a node for the lifetime of a document.

const NoNode NodeID = 0

NoNode is the absence of a node.

Jump to

Keyboard shortcuts

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