motion

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EndOfLine = lineMotion(func(line emu.Line) int {
	return len(line) - 1
})

EndOfLine corresponds to vim's "$".

View Source
var EndOfScreenLine = screenLineMotion(func(width int, line emu.ScreenLine) int {
	return line.C1 - 1
})

EndOfScreenLine corresponds to vim's `g$`.

View Source
var FirstNonBlank = lineMotion(func(line emu.Line) int {
	first, _ := line.Whitespace()
	return first
})

FirstNonBlank corresponds to vim's "^".

View Source
var FirstNonBlankScreen = screenLineMotion(func(width int, line emu.ScreenLine) int {
	first, _ := line.Chars.Whitespace()
	return line.C0 + first
})

FirstNonBlankScreen corresponds to vim's `g^`.

View Source
var LastNonBlank = lineMotion(func(line emu.Line) int {
	_, last := line.Whitespace()
	return last
})

LastNonBlank corresponds to vim's "g_".

View Source
var LastNonBlankScreen = screenLineMotion(func(width int, line emu.ScreenLine) int {
	_, last := line.Chars.Whitespace()
	return line.C0 + last
})

LastNonBlankScreen corresponds to vim's `g<end>`.

View Source
var MiddleOfLine = lineMotion(func(line emu.Line) int {
	return len(line) / 2
})

MiddleOfLine corresponds to vim's "gM".

View Source
var MiddleOfScreenLine = screenLineMotion(func(width int, line emu.ScreenLine) int {
	return line.C0 + width/2
})

MiddleOfScreenLine corresponds to vim's `gm`.

View Source
var StartOfLine = lineMotion(func(line emu.Line) int {
	return 0
})

StartOfLine corresponds to vim's "0".

View Source
var StartOfScreenLine = screenLineMotion(func(width int, line emu.ScreenLine) int {
	return line.C0
})

StartOfScreenLine corresponds to vim's `g0`.

Functions

func FindNext

func FindNext(
	m Movable,
	re *regexp.Regexp,
	from geom.Vec2,
	isForward bool,
) (to emu.ScreenLine, ok bool)

FindNext gets the next match of a regex pattern in the given direction.

The origin of the search, `from`, is a coordinate in the reference frame of the Movable and determines where the search will start from. `from.C`, or the initial column of the search, has some special behavior in order to mimic the way vim's incremental search works.

When searching forwards, the cell specified by `from.C` will be _excluded_ from the search. This is to prevent the pattern from matching the current location. In addition, specifically when searching forwards, `from.C = -1` is considered to be valid; this means that no cell will be excluded from the search, which will start from the beginning of the line.

When searching backwards, matches must begin before the cell specified by `from`, but can end after or including `from`. Observe that vim works this way. Similarly, if `from.C` is equal to the length of the line, no cell will be excluded in the search.

func Jump

func Jump(m Movable, needle string, isForward bool, isTo bool)

Jump performs a jump that works identically to vim's fF/tT motions.

Types

type Incremental

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

Incremental is a state machine that implements vim/emacs style incremental searching for a Movable.

func NewIncremental

func NewIncremental() *Incremental

func (*Incremental) Accept

func (i *Incremental) Accept()

Accept confirms the motion and stores the pattern. This is equivalent to pressing enter when searching incrementally in vim.

func (*Incremental) Cancel

func (i *Incremental) Cancel(m Movable)

Cancel stops searching incrementally and returns to the origin.

func (*Incremental) Highlight

func (i *Incremental) Highlight() (line emu.ScreenLine, ok bool)

func (*Incremental) IsActive

func (i *Incremental) IsActive() bool

IsActive returns true if the user is currently entering a search pattern.

func (*Incremental) IsForward

func (i *Incremental) IsForward() bool

IsForward returns true if the user is currently searching forward.

func (*Incremental) Next

func (i *Incremental) Next(m Movable, isForward bool)

Next jumps to the next instance of the accepted pattern in the direction of the search. `isForward` is relative to the direction of the original search; if the original search was backwards, `isForward=true` means that the search will go backwards.

func (*Incremental) Pattern

func (i *Incremental) Pattern(m Movable, input string)

Pattern takes a new pattern and jumps to the closest instance of it after the origin in the direction of the search.

func (*Incremental) Start

func (i *Incremental) Start(m Movable, isForward bool)

Start initializes the incremental search by saving the original cursor location and direction.

type LineReader

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

An io.RuneReader that provides a sequence of runes corresponding to the cells in an emu.Line.

func (*LineReader) ReadRune

func (s *LineReader) ReadRune() (r rune, size int, err error)

type Motion

type Motion func(m Movable)

type Movable

type Movable interface {
	Cursor() geom.Vec2
	Line(row int) (line emu.Line, ok bool)
	NumLines() int
	Goto(location geom.Vec2)
	Viewport() (
		screen []emu.ScreenLine,
		size geom.Vec2,
		cursor geom.Vec2,
	)
}

Jump to

Keyboard shortcuts

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