Documentation
¶
Index ¶
- Constants
- Variables
- func BracketPairs() [][2]rune
- func CharIsLineEnding(ch rune) bool
- func CharIsPunctuation(ch rune) bool
- func CharIsWhitespace(ch rune) bool
- func CharIsWord(ch rune) bool
- func CreateBlockCommentTransaction(doc Rope, commented bool, commentChanges []CommentChange) (Transaction, []Range, error)
- func EnsureGraphemeBoundaryNext(doc Rope, charIdx int) int
- func EnsureGraphemeBoundaryPrev(doc Rope, charIdx int) int
- func FindMatchingBracket(doc Rope, cursorPos int) (int, bool)
- func GetCommentToken(text Rope, tokens []string, lineNum int) (string, bool)
- func GetSurroundPos(doc Rope, sel Selection, skip int) ([]int, error)
- func GetSurroundPosFor(doc Rope, sel Selection, ch rune, skip int) ([]int, error)
- func HookDelete(doc Rope, r Range, pairs AutoPairs) (Span, Range, bool)
- func HookInsert(doc Rope, r Range, ch rune, pairs AutoPairs) (Change, Range, bool)
- func IsCloseBracket(ch rune) bool
- func IsOpenBracket(ch rune) bool
- func IsValidBracket(ch rune) bool
- func LineEndingNames() []string
- func LoadText(path string) ([]byte, error)
- func LooksBinary(data []byte) bool
- func NextGraphemeBoundary(doc Rope, charIdx int) int
- func NthNextGraphemeBoundary(doc Rope, step GraphemeStep) int
- func NthPrevGraphemeBoundary(doc Rope, step GraphemeStep) int
- func PrevGraphemeBoundary(doc Rope, charIdx int) int
- func ReflowHardWrap(text string, width int) string
- func TabWidthAt(at TabStop) int
- type Assoc
- type AutoPairs
- type BlockCommentToken
- type BracketPair
- type Change
- type ChangeSet
- func (c ChangeSet) Apply(doc Rope) (Rope, error)
- func (c ChangeSet) Changes() []Change
- func (c ChangeSet) Compose(other ChangeSet) ChangeSet
- func (c ChangeSet) Invert(original Rope) (ChangeSet, error)
- func (c ChangeSet) IsEmpty() bool
- func (c ChangeSet) Len() int
- func (c ChangeSet) LenAfter() int
- func (c ChangeSet) MapPos(pos int, assoc Assoc) (int, error)
- func (c ChangeSet) MapRange(r Range) (Range, error)
- func (c ChangeSet) Operations() []Operation
- type CharCategory
- type CommentChange
- type CommentChangeKind
- type Direction
- type GraphemeStep
- type History
- func (h *History) AtRoot() bool
- func (h *History) CommitRevision(tx Transaction, st State) error
- func (h *History) CurrentRevision() int
- func (h *History) Earlier(kind UndoKind) []Transaction
- func (h *History) LastEditPos() int
- func (h *History) Later(kind UndoKind) []Transaction
- func (h *History) Redo() (Transaction, bool)
- func (h *History) Undo() (Transaction, bool)
- type IndentStyle
- type LineEnding
- type LinePos
- type Movement
- type Operation
- type OperationKind
- type Pair
- type Position
- type Range
- func FindNthClosestPairsPos(doc Rope, r Range, skip int) (Range, error)
- func FindNthPairsPos(doc Rope, ch rune, r Range, n int) (Range, error)
- func MoveNextLongWordEnd(doc Rope, r Range, count int) Range
- func MoveNextLongWordStart(doc Rope, r Range, count int) Range
- func MoveNextSubWordEnd(doc Rope, r Range, count int) Range
- func MoveNextSubWordStart(doc Rope, r Range, count int) Range
- func MoveNextWordEnd(doc Rope, r Range, count int) Range
- func MoveNextWordStart(doc Rope, r Range, count int) Range
- func MovePrevLongWordEnd(doc Rope, r Range, count int) Range
- func MovePrevLongWordStart(doc Rope, r Range, count int) Range
- func MovePrevSubWordEnd(doc Rope, r Range, count int) Range
- func MovePrevSubWordStart(doc Rope, r Range, count int) Range
- func MovePrevWordEnd(doc Rope, r Range, count int) Range
- func MovePrevWordStart(doc Rope, r Range, count int) Range
- func PointRange(head int) Range
- func TextObjectParagraph(doc Rope, r Range, kind TextObjectKind, count int) Range
- func TextObjectWord(doc Rope, r Range, kind TextObjectKind, long bool) Range
- func (r Range) Contains(pos int) bool
- func (r Range) ContainsRange(q Range) bool
- func (r Range) Cursor(doc Rope) int
- func (r Range) CursorLine(doc Rope) (int, error)
- func (r Range) Direction() Direction
- func (r Range) Extend(s Span) Range
- func (r Range) Flip() Range
- func (r Range) Fragment(doc Rope) (string, error)
- func (r Range) From() int
- func (r Range) GraphemeAligned(doc Rope) Range
- func (r Range) IsEmpty() bool
- func (r Range) IsSingleGrapheme(doc Rope) bool
- func (r Range) Len() int
- func (r Range) LineSpan(text Rope) (Span, error)
- func (r Range) Merge(q Range) Range
- func (r Range) MinWidth1(doc Rope) Range
- func (r Range) MoveHorizontally(doc Rope, dir Direction, count int, move Movement) Range
- func (r Range) MoveVertically(doc Rope, dir Direction, count int, move Movement) Range
- func (r Range) Overlaps(q Range) bool
- func (r Range) PutCursor(doc Rope, charIdx int, extend bool) Range
- func (r Range) Slice(doc Rope) (Rope, error)
- func (r Range) Span() Span
- func (r Range) TextObjectPairSurround(doc Rope, kind TextObjectKind, ch rune, count int) Range
- func (r Range) To() int
- func (r Range) WithDirection(dir Direction) Range
- type Rope
- func (r Rope) CharAt(pos int) (rune, error)
- func (r Rope) CharToLine(pos int) (int, error)
- func (r Rope) Delete(s Span) (Rope, error)
- func (r Rope) FindNthChar(n int, match rune, pos int, dir Direction) (int, bool)
- func (r Rope) ForEachSegment(s Span, fn func(string))
- func (r Rope) Insert(pos int, text string) (Rope, error)
- func (r Rope) LenChars() int
- func (r Rope) LenLines() int
- func (r Rope) Line(line int) (Rope, error)
- func (r Rope) LineEndCharIndex(line int) (int, error)
- func (r Rope) LineToChar(line int) (int, error)
- func (r Rope) Position(char int) (Position, error)
- func (r Rope) Slice(s Span) (Rope, error)
- func (r Rope) SliceString(s Span) (string, error)
- func (r Rope) String() string
- type Selection
- func (s Selection) Equal(other Selection) bool
- func (s Selection) IntoSingle() Selection
- func (s Selection) LineRanges(text Rope) ([]Span, error)
- func (s Selection) Map(cs ChangeSet) (Selection, error)
- func (s Selection) MergeConsecutiveRanges() Selection
- func (s Selection) MergeRanges() Selection
- func (s Selection) Primary() Range
- func (s Selection) PrimaryIndex() int
- func (s Selection) Push(r Range) Selection
- func (s Selection) Ranges() []Range
- func (s Selection) Remove(idx int) (Selection, error)
- func (s Selection) Replace(idx int, r Range) (Selection, error)
- func (s Selection) SetPrimaryIndex(idx int) (Selection, error)
- func (s Selection) Transform(f func(Range) Range) Selection
- type Slab
- type Source
- type Span
- type State
- type TabStop
- type TextObjectKind
- type Transaction
- func (t Transaction) Apply(doc Rope) (Rope, error)
- func (t Transaction) Changes() ChangeSet
- func (t Transaction) Compose(other Transaction) Transaction
- func (t Transaction) Invert(original Rope) (Transaction, error)
- func (t Transaction) Selection() *Selection
- func (t Transaction) WithChanges(cs ChangeSet) Transaction
- func (t Transaction) WithSelection(s Selection) Transaction
- type UndoKind
- type VisualMoveFormat
- func (vf *VisualMoveFormat) ExtendVerticallyVisual(doc Rope, r Range, dir Direction, count int) Range
- func (vf *VisualMoveFormat) MoveVerticallyVisual(doc Rope, r Range, dir Direction, count int) Range
- func (vf *VisualMoveFormat) VisualRowOfOffset(args VisualRowOfOffsetArgs) int
- func (vf *VisualMoveFormat) VisualRowStarts(runes []rune) []int
- func (vf *VisualMoveFormat) VisualRows(doc Rope, line int) int
- func (vf *VisualMoveFormat) VisualScrollUp(args VisualScrollUpArgs) VisualScrollUpRes
- type VisualRowOfOffsetArgs
- type VisualScrollUpArgs
- type VisualScrollUpRes
- type WordMotionTarget
Constants ¶
const ( LineEndingNameLF = "lf" LineEndingNameCRLF = "crlf" LineEndingNameNative = "native" )
Line-ending option value names, as used in config, completion, and status
const ( // SlabInitSize is the capacity of a Slab's first backing array SlabInitSize = 256 // SlabMaxSize is the largest Slab will allocate for any later backing array SlabMaxSize = 4096 )
const ( // BinarySampleSize is how much of a file LooksBinary inspects; callers can // read just this much before deciding whether to load the rest BinarySampleSize = 1024 )
const DefaultCommentToken = "#"
DefaultCommentToken is used for line comments when no token is configured
const (
DefaultRopeLeafChars = 1024
)
const MaxIndent = 16
MaxIndent is the maximum spaces per indent level
const MaxPlaintextScan = 10000
Variables ¶
var ( ErrChangeSetLengthMismatch = errors.New("change set length mismatch") ErrChangeOutOfRange = errors.New("change out of range") ErrChangeOrder = errors.New("change order invalid") )
var ( ErrRopeIndexOutOfRange = errors.New("rope index out of range") ErrRopeLineOutOfRange = errors.New("rope line out of range") )
var ( ErrEmptySelection = errors.New("empty selection") ErrPrimaryIndexNotFound = errors.New("primary index not found") ErrLastRangeRemoval = errors.New("last range removal") ErrRangeIndexNotFound = errors.New("range index not found") )
var ( ErrPairNotFound = errors.New( "surround pair not found around all cursors", ) ErrSurroundCursorOverlap = errors.New( "cursors overlap for a single surround pair", ) ErrRangeExceedsText = errors.New("cursor range exceeds text length") ErrCursorOnAmbiguousPair = errors.New("cursor on ambiguous surround pair") )
var ( // ErrBinaryFile is returned by LoadText when a file's content looks binary ErrBinaryFile = errors.New("binary file") )
var ErrInvalidLineEnding = errors.New("invalid line ending")
Functions ¶
func BracketPairs ¶ added in v0.3.0
func BracketPairs() [][2]rune
BracketPairs returns every pair GetPair recognizes, open then close
func CharIsLineEnding ¶
CharIsLineEnding reports whether ch terminates a line
func CharIsPunctuation ¶
CharIsPunctuation reports whether ch is punctuation or a symbol
func CharIsWhitespace ¶
CharIsWhitespace reports whether ch is a space or tab
func CharIsWord ¶
CharIsWord reports whether ch may appear inside a word
func CreateBlockCommentTransaction ¶
func CreateBlockCommentTransaction( doc Rope, commented bool, commentChanges []CommentChange, ) (Transaction, []Range, error)
CreateBlockCommentTransaction builds the transaction and updated ranges for a block comment toggle operation
func EnsureGraphemeBoundaryNext ¶
EnsureGraphemeBoundaryNext snaps charIdx to the next grapheme boundary if it is not already on one
func EnsureGraphemeBoundaryPrev ¶
EnsureGraphemeBoundaryPrev snaps charIdx to the previous grapheme boundary if it is not already on one
func FindMatchingBracket ¶
FindMatchingBracket returns the position of the bracket matching the one at cursorPos, scanning at most MaxPlaintextScan characters. Returns (pos, true) on success, (0, false) if not found or not on a bracket
func GetCommentToken ¶
GetCommentToken returns the longest token matching the start of the non-whitespace content on the given line
func GetSurroundPos ¶
GetSurroundPos returns flat pairs of [open, close] positions for every range in sel, auto-detecting the nearest pair. skip controls how many pairs to step over
func GetSurroundPosFor ¶
GetSurroundPosFor returns flat pairs of [open, close] positions for every range in sel, searching for the pair matching ch. skip controls how many pairs to step over
func HookDelete ¶
HookDelete returns a Span and updated Range when backspace should erase an auto-inserted pair, or ok=false when no action is needed
func HookInsert ¶
HookInsert returns a Change and updated Range when ch should trigger an auto-pair action, or ok=false when no action is needed
func IsCloseBracket ¶
IsCloseBracket reports whether ch is a closing bracket
func IsOpenBracket ¶
IsOpenBracket reports whether ch is an opening bracket
func IsValidBracket ¶
IsValidBracket reports whether ch is either side of a bracket pair
func LineEndingNames ¶
func LineEndingNames() []string
LineEndingNames returns the recognized line-ending option values, in display order
func LoadText ¶
LoadText reads path, returning ErrBinaryFile without reading past the leading sample if the content looks binary, so a huge binary file is never fully loaded just to be rejected
func LooksBinary ¶
LooksBinary reports whether data appears to be non-text content, biased toward false negatives: garbled binary is recoverable, a refused-open text file is not
func NextGraphemeBoundary ¶
NextGraphemeBoundary returns the char index one grapheme cluster after charIdx
func NthNextGraphemeBoundary ¶
func NthNextGraphemeBoundary(doc Rope, step GraphemeStep) int
NthNextGraphemeBoundary returns the char index Count grapheme clusters after the step's start
func NthPrevGraphemeBoundary ¶
func NthPrevGraphemeBoundary(doc Rope, step GraphemeStep) int
NthPrevGraphemeBoundary returns the char index Count grapheme clusters before the step's start
func PrevGraphemeBoundary ¶
PrevGraphemeBoundary returns the char index one grapheme cluster before charIdx
func ReflowHardWrap ¶
ReflowHardWrap reformats text to fit within width columns by breaking at word boundaries. Existing line breaks are first collapsed into spaces and common quote, comment, and list prefixes are retained on wrapped rows
func TabWidthAt ¶
TabWidthAt returns the visual width of a tab character at the stop's column
Types ¶
type AutoPairs ¶
AutoPairs holds the set of active bracket pairs, keyed by both opener and closer
func DefaultAutoPairs ¶
func DefaultAutoPairs() AutoPairs
DefaultAutoPairs returns an AutoPairs with the standard bracket/quote pairs
func NewAutoPairs ¶
NewAutoPairs constructs AutoPairs from [open, close] pairs
type BlockCommentToken ¶
BlockCommentToken holds the start and end delimiters for a block comment
func DefaultBlockCommentToken ¶
func DefaultBlockCommentToken() BlockCommentToken
DefaultBlockCommentToken returns the fallback block comment delimiters
type BracketPair ¶ added in v0.2.0
BracketPair is the open and close characters of a bracket pair
func GetPair ¶
func GetPair(ch rune) BracketPair
GetPair returns the open and close characters for a bracket pair. If ch is not in any pair, both sides are ch
type Change ¶
type Change struct {
Span
// contains filtered or unexported fields
}
Change describes a replacement over a character span
func DeleteChange ¶
DeleteChange removes the characters the span covers
func TextChange ¶
TextChange replaces the characters the span covers with text
type ChangeSet ¶
type ChangeSet struct {
// contains filtered or unexported fields
}
ChangeSet is an ordered set of edits over a document snapshot
func NewChangeSet ¶
NewChangeSet returns an empty change set sized for doc
func NewChangeSetFromChanges ¶
NewChangeSetFromChanges builds a change set from non-overlapping changes, which must be ordered by position
func (ChangeSet) Compose ¶
Compose combines two changesets: if c transforms docA→docB and other transforms docB→docC, the result transforms docA→docC
func (ChangeSet) Invert ¶
Invert returns the change set undoing this one, given the document it was built against
func (ChangeSet) IsEmpty ¶ added in v0.3.2
IsEmpty reports whether the change set would leave a document unaltered
func (ChangeSet) MapPos ¶
MapPos rebases a position onto the resulting document; assoc decides which side of an insertion at pos it lands on
func (ChangeSet) Operations ¶
Operations returns a copy of the operation sequence
type CharCategory ¶
type CharCategory int
CharCategory classifies a character for reference word and motion behavior
const ( CharCategoryWhitespace CharCategory = iota + 1 CharCategoryEOL CharCategoryWord CharCategoryPunctuation CharCategoryUnknown )
func CategorizeChar ¶
func CategorizeChar(ch rune) CharCategory
CategorizeChar classifies ch for word-wise motion
type CommentChange ¶
type CommentChange struct {
Kind CommentChangeKind
Range Range
StartPos int
EndPos int
StartMargin bool
EndMargin bool
StartToken string
EndToken string
}
CommentChange describes the comment action for one selection range
func FindBlockComments ¶
func FindBlockComments( tokens []BlockCommentToken, text Rope, sel Selection, ) (bool, []CommentChange, error)
FindBlockComments inspects each range in sel to determine whether it is already block-commented and returns the per-range actions
type CommentChangeKind ¶
type CommentChangeKind int
CommentChangeKind identifies which variant a CommentChange represents
const ( CommentChangeCommented CommentChangeKind = iota CommentChangeUncommented CommentChangeWhitespace )
type Direction ¶
type Direction int
Direction describes whether a range head is before or after its anchor
type GraphemeStep ¶ added in v0.2.0
GraphemeStep is a starting char index and a count of grapheme clusters to move by
type History ¶
type History struct {
// contains filtered or unexported fields
}
History stores committed document revisions
func NewHistory ¶
func NewHistory() History
NewHistory returns an empty history positioned at the root revision
func (*History) CommitRevision ¶
func (h *History) CommitRevision(tx Transaction, st State) error
CommitRevision records tx as a new revision branching from the current one, storing its inverse for undo
func (*History) CurrentRevision ¶
CurrentRevision is the index of the revision in effect
func (*History) Earlier ¶
func (h *History) Earlier(kind UndoKind) []Transaction
Earlier returns the transactions that walk back by kind, without applying them
func (*History) LastEditPos ¶
LastEditPos returns the char offset of the most recently committed change
func (*History) Later ¶
func (h *History) Later(kind UndoKind) []Transaction
Later returns the transactions that walk forward by kind, without applying them
func (*History) Redo ¶
func (h *History) Redo() (Transaction, bool)
Redo steps forward one revision, returning the transaction to apply
func (*History) Undo ¶
func (h *History) Undo() (Transaction, bool)
Undo steps back one revision, returning the transaction to apply
type IndentStyle ¶
type IndentStyle struct {
// contains filtered or unexported fields
}
IndentStyle describes whether indentation uses tabs or spaces
func AutoDetect ¶
func AutoDetect(doc Rope) (IndentStyle, bool)
AutoDetect attempts to detect the indentation style used in doc. Returns the detected style and true, or false if confidence is too low
func ParseIndentStyle ¶
func ParseIndentStyle(s string) IndentStyle
ParseIndentStyle creates an IndentStyle from an indent string such as " " (four spaces) or "\t"
func Spaces ¶
func Spaces(n uint8) IndentStyle
Spaces returns an IndentStyle that uses n space characters per level
func (IndentStyle) AsStr ¶
func (i IndentStyle) AsStr() string
AsStr returns the string for one indent level
func (IndentStyle) IndentWidth ¶
func (i IndentStyle) IndentWidth(tabWidth int) int
IndentWidth returns the number of columns one indent level occupies
func (IndentStyle) IsTabs ¶
func (i IndentStyle) IsTabs() bool
IsTabs reports whether this style uses tab characters
func (IndentStyle) Width ¶
func (i IndentStyle) Width() uint8
Width returns the number of spaces per indent level (0 for tabs)
type LineEnding ¶
type LineEnding string
LineEnding is the actual line-ending byte sequence for a document
const ( LineEndingLF LineEnding = "\n" LineEndingCRLF LineEnding = "\r\n" )
func AutoDetectLineEndingString ¶
func AutoDetectLineEndingString(s string) (LineEnding, bool)
AutoDetectLineEndingString infers the ending from the first terminator found, giving up after 100 ambiguous ones
func GetLineEndingOfString ¶
func GetLineEndingOfString(s string) (LineEnding, bool)
GetLineEndingOfString reports the ending that s itself terminates with
func LineEndingFromChar ¶
func LineEndingFromChar(ch rune) (LineEnding, bool)
LineEndingFromChar reports whether ch terminates a line, normalizing every single-character terminator to LF
func NativeLineEnding ¶
func NativeLineEnding() LineEnding
NativeLineEnding is the platform's default line ending
func ParseLineEnding ¶
func ParseLineEnding(value string) (LineEnding, error)
ParseLineEnding parses a "lf", "crlf", or "native" option value
func (*LineEnding) UnmarshalText ¶
func (l *LineEnding) UnmarshalText(text []byte) error
UnmarshalText parses a line ending name, resolving native to the platform default
type LinePos ¶ added in v0.2.0
LinePos addresses a point inside a line by 0-based line index and the absolute character offset of the point, not a column
type Movement ¶
type Movement int
Movement controls whether a motion extends the selection or moves it
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation is one piece of a change set
func (Operation) Kind ¶
func (o Operation) Kind() OperationKind
Kind reports whether the operation retains, deletes, or inserts
type OperationKind ¶
type OperationKind int
OperationKind identifies the operation variant
const ( OperationRetain OperationKind = iota + 1 OperationDelete OperationInsert )
type Pair ¶
Pair describes one opener/closer bracket pair
type Position ¶ added in v0.1.6
Position is a 1-based line and column document address, the way a person names a location. Distinct from geom.Point, a screen cell
type Range ¶
Range is a selection span with an immovable anchor and movable head
func FindNthClosestPairsPos ¶
FindNthClosestPairsPos finds the nth-nearest surrounding bracket pair around r (plaintext only). The returned Range keeps the source range's direction
func FindNthPairsPos ¶
FindNthPairsPos finds the nth surrounding pair for character ch around r (plaintext only). ch may be either opening or closing
func MoveNextLongWordEnd ¶
MoveNextLongWordEnd moves count WORDS forward to the end of the next WORD
func MoveNextLongWordStart ¶
MoveNextLongWordStart moves count WORDS forward to the start of the next WORD
func MoveNextSubWordEnd ¶
MoveNextSubWordEnd moves count sub-words forward to the end of the next sub-word
func MoveNextSubWordStart ¶
MoveNextSubWordStart moves count sub-words forward to the start of the next sub-word
func MoveNextWordEnd ¶
MoveNextWordEnd moves count words forward to the end of the next word
func MoveNextWordStart ¶
MoveNextWordStart moves count words forward to the start of the next word
func MovePrevLongWordEnd ¶
MovePrevLongWordEnd moves count WORDS backward to the end of the previous WORD
func MovePrevLongWordStart ¶
MovePrevLongWordStart moves count WORDS backward to the start of the previous WORD
func MovePrevSubWordEnd ¶
MovePrevSubWordEnd moves count sub-words backward to the end of the previous sub-word
func MovePrevSubWordStart ¶
MovePrevSubWordStart moves count sub-words backward to the start of the previous sub-word
func MovePrevWordEnd ¶
MovePrevWordEnd moves count words backward to the end of the previous word
func MovePrevWordStart ¶
MovePrevWordStart moves count words backward to the start of the previous word
func TextObjectParagraph ¶
func TextObjectParagraph( doc Rope, r Range, kind TextObjectKind, count int, ) Range
TextObjectParagraph selects the paragraph containing the cursor. A paragraph is a contiguous sequence of non-empty lines around=TextObjectAround includes the trailing empty lines
func TextObjectWord ¶
func TextObjectWord(doc Rope, r Range, kind TextObjectKind, long bool) Range
TextObjectWord selects the word under or adjacent to the cursor long=true uses long-word (WORD) semantics: only whitespace is a boundary around=TextObjectAround includes trailing (or leading) whitespace
func (Range) ContainsRange ¶
ContainsRange reports whether q falls entirely inside this range
func (Range) Cursor ¶
Cursor returns the char index of the block-cursor position. For a forward range the cursor sits one grapheme before the head; for backward or empty ranges it is the head itself
func (Range) CursorLine ¶
CursorLine returns the line number that the block cursor is on
func (Range) GraphemeAligned ¶
GraphemeAligned snaps both ends of the range to grapheme cluster boundaries
func (Range) IsSingleGrapheme ¶
IsSingleGrapheme reports whether this range covers exactly one grapheme cluster
func (Range) LineSpan ¶ added in v0.2.0
LineSpan returns the inclusive line span the range touches. An empty range covers one line; a non-empty one excludes an end on a line start
func (Range) MinWidth1 ¶
MinWidth1 ensures the range covers at least one grapheme by advancing the head forward if the range is empty
func (Range) MoveHorizontally ¶
MoveHorizontally moves range by count grapheme clusters in dir
func (Range) MoveVertically ¶
MoveVertically moves the cursor by count lines, keeping the column the caller last moved to horizontally
func (Range) PutCursor ¶
PutCursor moves the block cursor to charIdx, optionally extending the selection anchor using 1-width block cursor semantics
func (Range) Span ¶ added in v0.2.0
Span is the character interval the range covers, ignoring direction
func (Range) TextObjectPairSurround ¶
TextObjectPairSurround selects the pair surrounding the cursor. ch, if non-zero, specifies which pair; zero uses the nearest pair. kind controls whether the delimiters themselves are included
func (Range) WithDirection ¶
WithDirection flips the range only when it faces the other way
type Rope ¶
type Rope struct {
// contains filtered or unexported fields
}
Rope stores text as a balanced binary tree of string leaves
func (Rope) CharToLine ¶
CharToLine returns the line containing pos
func (Rope) FindNthChar ¶
FindNthChar finds the position of the nth matching character, starting from pos in the given direction
func (Rope) ForEachSegment ¶
ForEachSegment applies fn to each contiguous leaf substring the span covers, without copying
func (Rope) LineEndCharIndex ¶
LineEndCharIndex returns the position after the line's last character, excluding its ending
func (Rope) LineToChar ¶
LineToChar returns the position where the line starts
func (Rope) Position ¶ added in v0.1.6
Position returns the 1-based line and column of a character offset
func (Rope) SliceString ¶
SliceString returns the substring the span covers without constructing a new rope; faster than Slice(s).String()
type Selection ¶
type Selection struct {
// contains filtered or unexported fields
}
Selection is a non-empty ordered set of ranges with one primary range
func NewSelection ¶
NewSelection returns a selection over ranges, sorted and merged, with the range at primaryIndex kept primary
func PointSelection ¶
PointSelection returns a selection of one empty range at pos
func SingleSelection ¶
SingleSelection returns a selection of one range
func SplitLinesOfSelection ¶
SplitLinesOfSelection returns a new selection where each range covers exactly one line within the original selection spans
func (Selection) Equal ¶
Equal reports whether two selections have identical ranges and the same primary index
func (Selection) IntoSingle ¶
IntoSingle discards every range but the primary
func (Selection) LineRanges ¶
LineRanges returns the line span each range touches
func (Selection) MergeConsecutiveRanges ¶
MergeConsecutiveRanges joins only ranges that touch end to start, leaving separated ranges alone
func (Selection) MergeRanges ¶
MergeRanges collapses every range into one spanning first to last
func (Selection) PrimaryIndex ¶
PrimaryIndex is the position of the primary range in Ranges
func (Selection) SetPrimaryIndex ¶
SetPrimaryIndex makes the range at idx primary
type Slab ¶ added in v0.1.38
type Slab[T any] struct { // contains filtered or unexported fields }
Slab batches values into contiguous backing arrays, handing out individually stable pointers to each one
type Source ¶ added in v0.2.0
Source is a document's text together with the language it is written in. Highlighting, parsing, and language detection operate on this pair
type Span ¶ added in v0.2.0
Span is a half-open interval of character offsets, [From, To)
type TextObjectKind ¶
type TextObjectKind int
TextObjectKind controls whether a selection covers the delimiter or just the content inside it
const ( TextObjectAround TextObjectKind = iota + 1 TextObjectInside )
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is an undoable change unit with optional selection state
func NewTransaction ¶
func NewTransaction(doc Rope) Transaction
NewTransaction returns an empty transaction sized for doc
func ToggleBlockComments ¶
func ToggleBlockComments( doc Rope, sel Selection, tokens []BlockCommentToken, ) (Transaction, error)
ToggleBlockComments toggles block comments on all ranges in sel
func ToggleLineComments ¶
func ToggleLineComments( doc Rope, sel Selection, token string, ) (Transaction, error)
ToggleLineComments builds a transaction that toggles line comments on every non-blank line in sel using token (DefaultCommentToken when empty)
func (Transaction) Apply ¶
func (t Transaction) Apply(doc Rope) (Rope, error)
Apply runs the transaction's changes against doc
func (Transaction) Changes ¶
func (t Transaction) Changes() ChangeSet
Changes is the edit the transaction applies
func (Transaction) Compose ¶
func (t Transaction) Compose(other Transaction) Transaction
Compose returns a transaction equivalent to applying this one then other, keeping other's selection
func (Transaction) Invert ¶
func (t Transaction) Invert(original Rope) (Transaction, error)
Invert returns the transaction undoing this one, given the document it was built against. The result carries no selection
func (Transaction) Selection ¶
func (t Transaction) Selection() *Selection
Selection is the selection to adopt afterwards, nil to keep the current
func (Transaction) WithChanges ¶
func (t Transaction) WithChanges(cs ChangeSet) Transaction
WithChanges returns a copy carrying cs
func (Transaction) WithSelection ¶
func (t Transaction) WithSelection(s Selection) Transaction
WithSelection returns a copy that adopts s once applied
type UndoKind ¶
type UndoKind struct {
// contains filtered or unexported fields
}
UndoKind selects how many steps history navigation travels
type VisualMoveFormat ¶
type VisualMoveFormat struct {
ViewportWidth int
TabWidth int
MaxWrap int
MaxIndentRetain int
WrapIndicatorWidth int
}
VisualMoveFormat carries the display parameters needed to compute visual row positions when soft-wrap is active. A zero-value (ViewportWidth == 0) causes MoveVerticallyVisual to fall back to text-line movement
func (*VisualMoveFormat) ExtendVerticallyVisual ¶
func (vf *VisualMoveFormat) ExtendVerticallyVisual( doc Rope, r Range, dir Direction, count int, ) Range
ExtendVerticallyVisual extends r up or down by count visual rows when soft-wrap is active. Falls back to text-line movement when soft-wrap is disabled
func (*VisualMoveFormat) MoveVerticallyVisual ¶
func (vf *VisualMoveFormat) MoveVerticallyVisual( doc Rope, r Range, dir Direction, count int, ) Range
MoveVerticallyVisual moves r up or down by count visual rows when soft-wrap is active. Falls back to text-line movement when soft-wrap is disabled
func (*VisualMoveFormat) VisualRowOfOffset ¶
func (vf *VisualMoveFormat) VisualRowOfOffset(args VisualRowOfOffsetArgs) int
VisualRowOfOffset returns the zero-based visual row within its text line on which the character at CharOff (relative to line start) is displayed
func (*VisualMoveFormat) VisualRowStarts ¶
func (vf *VisualMoveFormat) VisualRowStarts(runes []rune) []int
VisualRowStarts returns the char offsets at which each soft-wrapped visual row after the first begins; empty if the line fits on one row. Wraps at word boundaries, breaking mid-word only past MaxWrap
func (*VisualMoveFormat) VisualRows ¶
func (vf *VisualMoveFormat) VisualRows(doc Rope, line int) int
VisualRows returns the number of visual (soft-wrapped) rows the given text line occupies. It returns 1 when soft-wrap is inactive
func (*VisualMoveFormat) VisualScrollUp ¶
func (vf *VisualMoveFormat) VisualScrollUp( args VisualScrollUpArgs, ) VisualScrollUpRes
VisualScrollUp moves upward from a visual row, clamped at the document start
type VisualRowOfOffsetArgs ¶ added in v0.2.0
VisualRowOfOffsetArgs is a text line and a character offset within it
type VisualScrollUpArgs ¶
VisualScrollUpArgs identifies a visual row and upward distance
type VisualScrollUpRes ¶
VisualScrollUpRes identifies the resulting line and visual row
type WordMotionTarget ¶
type WordMotionTarget int
WordMotionTarget identifies the destination of a word motion
const ( WordMotionNextWordStart WordMotionTarget = iota + 1 WordMotionNextWordEnd WordMotionPrevWordStart WordMotionPrevWordEnd WordMotionNextLongWordStart WordMotionNextLongWordEnd WordMotionPrevLongWordStart WordMotionPrevLongWordEnd WordMotionNextSubWordStart WordMotionNextSubWordEnd WordMotionPrevSubWordStart WordMotionPrevSubWordEnd )
Source Files
¶
- autopairs-handle.go
- autopairs.go
- binary.go
- changeset-apply.go
- changeset-compose.go
- changeset.go
- chars.go
- comment-block-tx.go
- comment-block.go
- comment.go
- graphemes.go
- history.go
- indent.go
- line-ending.go
- line-ending_other.go
- matchbrackets.go
- movement-visual-line.go
- movement-visual.go
- movement-word.go
- movement.go
- position.go
- range.go
- rope-nav.go
- rope-node.go
- rope-str.go
- rope.go
- search.go
- selection.go
- slab.go
- surround-find.go
- surround.go
- textobject-paragraph.go
- textobject.go
- transaction.go
- wrap-fill.go
- wrap.go