locate

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var (
	ParenPair   = DelimiterPair{OpenRune: '(', CloseRune: ')'}
	BracketPair = DelimiterPair{OpenRune: '[', CloseRune: ']'}
	BracePair   = DelimiterPair{OpenRune: '{', CloseRune: '}'}
	AnglePair   = DelimiterPair{OpenRune: '<', CloseRune: '>'}
)

Functions

func ClosestCharOnLine

func ClosestCharOnLine(tree *text.Tree, pos uint64) uint64

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

func ClosestValidLineNum(tree *text.Tree, targetLineNum uint64) uint64

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

func InnerWordObject(textTree *text.Tree, pos uint64, targetCount uint64) (uint64, uint64)

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

func LineNumAndColToPos(tree *text.Tree, lineNum uint64, col uint64) uint64

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

func NextCharInLine(tree *text.Tree, count uint64, includeEndOfLineOrFile bool, pos uint64) uint64

NextCharInLine locates the next grapheme cluster in the current line.

func NextLineBoundary

func NextLineBoundary(tree *text.Tree, includeEndOfLineOrFile bool, pos uint64) uint64

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

func NextNewline(tree *text.Tree, pos uint64) (uint64, uint64, bool)

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

func NextNonWhitespaceOrNewline(tree *text.Tree, pos uint64) uint64

NonWhitespaceOrNewline locates the next non-whitespace character or newline on or after a position.

func NextParagraph

func NextParagraph(tree *text.Tree, pos uint64) uint64

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

func NextWordEnd(textTree *text.Tree, pos uint64, targetCount uint64, withPunctuation bool) uint64

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:

  1. at the first non-whitespace after a whitespace
  2. at the start of an empty line
  3. between punctuation and non-punctuation (unless withPunctuation=true)

func NumGraphemeClustersInRange added in v0.2.0

func NumGraphemeClustersInRange(tree *text.Tree, startPos, endPos uint64) uint64

NumGraphemeClustersInRange counts the number of grapheme clusters from the start position (inclusive) to the end position (exclusive).

func PosToLineNumAndCol added in v0.5.0

func PosToLineNumAndCol(tree *text.Tree, pos uint64) (uint64, uint64)

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

func PrevAutoIndent(tree *text.Tree, autoIndentEnabled bool, tabSize uint64, pos uint64) uint64

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

func PrevChar(tree *text.Tree, count uint64, pos uint64) uint64

PrevChar locates the grapheme cluster before a position, which may be on a previous line.

func PrevCharInLine

func PrevCharInLine(tree *text.Tree, count uint64, includeEndOfLineOrFile bool, pos uint64) uint64

PrevCharInLine locates the previous grapheme cluster in the current line.

func PrevLineBoundary

func PrevLineBoundary(tree *text.Tree, pos uint64) uint64

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

func PrevParagraph(tree *text.Tree, pos uint64) uint64

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

func StartOfLastLine(tree *text.Tree) uint64

StartOfLastLine locates the start of the last line.

func StartOfLineAbove

func StartOfLineAbove(tree *text.Tree, count uint64, pos uint64) uint64

StartOfLineAbove locates the start of a line above the cursor.

func StartOfLineAtPos

func StartOfLineAtPos(tree *text.Tree, pos uint64) uint64

StartOfLineAtPos locates the start of the line for a given position.

func StartOfLineBelow

func StartOfLineBelow(tree *text.Tree, count uint64, pos uint64) uint64

StartOfLineBelow locates the start of a line below the cursor.

func StartOfLineNum

func StartOfLineNum(tree *text.Tree, lineNum uint64) uint64

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

func WordObject(textTree *text.Tree, pos uint64, targetCount uint64) (uint64, uint64)

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

type DelimiterPair struct {
	OpenRune  rune
	CloseRune rune
}

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

Jump to

Keyboard shortcuts

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