Documentation ¶
Index ¶
- Constants
- Variables
- func ClosestCharOnLine(tree *text.Tree, pos uint64) uint64
- func ClosestValidLineNum(tree *text.Tree, targetLineNum uint64) uint64
- func DelimitedBlock(delimiterPair DelimiterPair, textTree *text.Tree, syntaxParser *parser.P, ...) (uint64, uint64)
- func InnerWordObject(textTree *text.Tree, pos uint64, targetCount uint64) (uint64, uint64)
- func LineNumAndColToPos(tree *text.Tree, lineNum uint64, col uint64) uint64
- func MatchingCodeBlockDelimiter(textTree *text.Tree, syntaxParser *parser.P, pos uint64) (uint64, bool)
- func NextCharInLine(tree *text.Tree, count uint64, includeEndOfLineOrFile bool, pos uint64) uint64
- func NextLineBoundary(tree *text.Tree, includeEndOfLineOrFile bool, pos uint64) uint64
- func NextMatchingCharInLine(tree *text.Tree, char rune, count uint64, includeChar bool, pos uint64) (bool, uint64)
- func NextNewline(tree *text.Tree, pos uint64) (uint64, uint64, bool)
- func NextNonWhitespaceOrNewline(tree *text.Tree, pos uint64) uint64
- func NextParagraph(tree *text.Tree, pos uint64) uint64
- func NextUnmatchedCloseDelimiter(delimiterPair DelimiterPair, textTree *text.Tree, syntaxParser *parser.P, ...) (uint64, bool)
- func NextWordEnd(textTree *text.Tree, pos uint64, targetCount uint64, withPunctuation bool) uint64
- func NextWordStart(textTree *text.Tree, pos uint64, targetCount uint64, ...) uint64
- func NumGraphemeClustersInRange(tree *text.Tree, startPos, endPos uint64) uint64
- func PosToLineNumAndCol(tree *text.Tree, pos uint64) (uint64, uint64)
- func PrevAutoIndent(tree *text.Tree, autoIndentEnabled bool, tabSize uint64, pos uint64) uint64
- func PrevChar(tree *text.Tree, count uint64, pos uint64) uint64
- func PrevCharInLine(tree *text.Tree, count uint64, includeEndOfLineOrFile bool, pos uint64) uint64
- func PrevLineBoundary(tree *text.Tree, pos uint64) uint64
- func PrevMatchingCharInLine(tree *text.Tree, char rune, count uint64, includeChar bool, pos uint64) (bool, uint64)
- func PrevParagraph(tree *text.Tree, pos uint64) uint64
- func PrevUnmatchedOpenDelimiter(delimiterPair DelimiterPair, textTree *text.Tree, syntaxParser *parser.P, ...) (uint64, bool)
- func PrevWordStart(textTree *text.Tree, pos uint64, targetCount uint64, withPunctuation bool) uint64
- func StartOfLastLine(tree *text.Tree) uint64
- func StartOfLineAbove(tree *text.Tree, count uint64, pos uint64) uint64
- func StartOfLineAtPos(tree *text.Tree, pos uint64) uint64
- func StartOfLineBelow(tree *text.Tree, count uint64, pos uint64) uint64
- func StartOfLineNum(tree *text.Tree, lineNum uint64) uint64
- func StringObject(quoteRune rune, textTree *text.Tree, syntaxParser *parser.P, ...) (uint64, uint64)
- func ViewOriginAfterScroll(cursorPos uint64, tree *text.Tree, wrapConfig segment.LineWrapConfig, ...) uint64
- func WordObject(textTree *text.Tree, pos uint64, targetCount uint64) (uint64, uint64)
- type DelimiterPair
Constants ¶
const ScrollMargin = 3
ScrollMargin is the number of lines at the beginning and end of the displayed text where a cursor movement would trigger a scroll.
Variables ¶
var ( ParenPair = DelimiterPair{OpenRune: '(', CloseRune: ')'} BracketPair = DelimiterPair{OpenRune: '[', CloseRune: ']'} BracePair = DelimiterPair{OpenRune: '{', CloseRune: '}'} AnglePair = DelimiterPair{OpenRune: '<', CloseRune: '>'} )
Functions ¶
func ClosestCharOnLine ¶
ClosestCharOnLine locates the closest grapheme cluster on a line (not newline or past end of text). This is useful for "resetting" the cursor onto a line (for example, after deleting the last character on the line or exiting insert mode).
func ClosestValidLineNum ¶
ClosestValidLineNum returns the line number in the text that is closest to the target.
func DelimitedBlock ¶ added in v1.0.0
func DelimitedBlock(delimiterPair DelimiterPair, textTree *text.Tree, syntaxParser *parser.P, includeDelimiters bool, pos uint64) (uint64, uint64)
DelimitedBlock locates the start and end positions for matched open/close delimiters.
func InnerWordObject ¶ added in v0.7.0
InnerWordObject returns the start and end positions of the word object or whitespace regions under the cursor. This is similar to WordObject, except that whitespace regions are counted as if they were words. This is equivalent to vim's "iw" ("inner word") object.
func LineNumAndColToPos ¶ added in v0.5.0
LineNumAndColToPos converts a line number and column to a position. The line number is zero-indexed, and the column is the number of grapheme clusters from the start of the line. If the column is greater than the number of grapheme clusters in the line, it returns position of the last character on the line (excluding newlines and EOF).
func MatchingCodeBlockDelimiter ¶ added in v0.7.0
func MatchingCodeBlockDelimiter(textTree *text.Tree, syntaxParser *parser.P, pos uint64) (uint64, bool)
MatchingCodeBlockDelimiter locates the matching paren, brace, or bracket at a position, if it exists.
func NextCharInLine ¶
NextCharInLine locates the next grapheme cluster in the current line.
func NextLineBoundary ¶
NextLineBoundary locates the end of the current line. This assumes that the start position is on a line (not a newline character); if not, the result is undefined.
func NextMatchingCharInLine ¶ added in v0.2.0
func NextMatchingCharInLine(tree *text.Tree, char rune, count uint64, includeChar bool, pos uint64) (bool, uint64)
NextMatchingCharInLine locates the count'th next occurrence of a rune in the line.
func NextNewline ¶
NextNewline locates the next newline on or after the specified position. It returns both the positon of the newline as well as its length in runes, since the grapheme cluster could be either '\n' or '\r\n'.
func NextNonWhitespaceOrNewline ¶
NonWhitespaceOrNewline locates the next non-whitespace character or newline on or after a position.
func NextParagraph ¶
NextParagraph locates the start of the next paragraph after the cursor. Paragraph boundaries occur at empty lines.
func NextUnmatchedCloseDelimiter ¶ added in v1.0.0
func NextUnmatchedCloseDelimiter(delimiterPair DelimiterPair, textTree *text.Tree, syntaxParser *parser.P, pos uint64) (uint64, bool)
NextUnmatchedCloseDelimiter locates the next unmatched close delimiter after a position.
func NextWordEnd ¶
NextWordEnd locates the next word-end boundary after the cursor. The word break rules are the same as for NextWordStart, except that empty lines are NOT treated as word boundaries.
func NextWordStart ¶
func NextWordStart(textTree *text.Tree, pos uint64, targetCount uint64, withPunctuation, stopAtEndOfLastLine bool) uint64
NextWordStart locates the start of the next word after the cursor. Word boundaries occur:
- at the first non-whitespace after a whitespace
- at the start of an empty line
- between punctuation and non-punctuation (unless withPunctuation=true)
func NumGraphemeClustersInRange ¶ added in v0.2.0
NumGraphemeClustersInRange counts the number of grapheme clusters from the start position (inclusive) to the end position (exclusive).
func PosToLineNumAndCol ¶ added in v0.5.0
PosToLineNumAndCol converts a position to a line number and column. The line number is zero-indexed, and the column is the number of grapheme clusters from the start of the line.
func PrevAutoIndent ¶
PrevAutoIndent locates the previous tab stop if autoIndent is enabled. If autoIndent is disabled or the characters before the cursor are not spaces/tabs, it returns the original position.
func PrevChar ¶
PrevChar locates the grapheme cluster before a position, which may be on a previous line.
func PrevCharInLine ¶
PrevCharInLine locates the previous grapheme cluster in the current line.
func PrevLineBoundary ¶
PrevLineBoundary locates the start of the current line, reading backwards from the specified position. This assumes that the start position is on a line (not a newline character); if not, the result is undefined.
func PrevMatchingCharInLine ¶ added in v0.2.0
func PrevMatchingCharInLine(tree *text.Tree, char rune, count uint64, includeChar bool, pos uint64) (bool, uint64)
PrevMatchingCharInLine locates the count'th previous occurrence of a rune in the line.
func PrevParagraph ¶
PrevParagraph locates the start of the first paragraph before the cursor. Paragraph boundaries occur at empty lines.
func PrevUnmatchedOpenDelimiter ¶ added in v1.0.0
func PrevUnmatchedOpenDelimiter(delimiterPair DelimiterPair, textTree *text.Tree, syntaxParser *parser.P, pos uint64) (uint64, bool)
PrevUnmatchedOpenDelimiter locates the previous unmatched open delimiter before a position.
func PrevWordStart ¶
func PrevWordStart(textTree *text.Tree, pos uint64, targetCount uint64, withPunctuation bool) uint64
PrevWordStart locates the start of the word before the cursor. It is the inverse of NextWordStart.
func StartOfLastLine ¶
StartOfLastLine locates the start of the last line.
func StartOfLineAbove ¶
StartOfLineAbove locates the start of a line above the cursor.
func StartOfLineAtPos ¶
StartOfLineAtPos locates the start of the line for a given position.
func StartOfLineBelow ¶
StartOfLineBelow locates the start of a line below the cursor.
func StartOfLineNum ¶
StartOfLineNum locates the start of a given line number.
func StringObject ¶ added in v1.0.0
func StringObject(quoteRune rune, textTree *text.Tree, syntaxParser *parser.P, includeQuotes bool, pos uint64) (uint64, uint64)
StringObject locates the start and end positions for a single- or double-quoted string.
func ViewOriginAfterScroll ¶
func ViewOriginAfterScroll(cursorPos uint64, tree *text.Tree, wrapConfig segment.LineWrapConfig, viewOrigin, viewHeight uint64) uint64
ViewOriginAfterScroll returns a new view origin such that the cursor is visible. It attempts to display a few lines before/after the cursor to help the user navigate.
func WordObject ¶ added in v0.7.0
WordObject returns the start and end positions of the word object under the cursor. If the cursor is on whitespace, include it as leading whitespace. Otherwise, include trailing whitespace. This is equivalent to vim's "aw" ("a word") object.
Types ¶
type DelimiterPair ¶ added in v1.0.0
DelimiterPair is a pair of matching open/close delimiters (parens, braces, etc.)
func (DelimiterPair) MatchRune ¶ added in v1.0.0
func (p DelimiterPair) MatchRune(r rune) bool