motion

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// vim word
	// warning: not accurate
	WORD_REGEX = regexp.MustCompile(`[!-~\w]+`)
	// vim WORD
	NON_WHITESPACE_REGEX = regexp.MustCompile(`[^\s]+`)
)
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 Jump

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

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

func WORD added in v0.1.17

func WORD(m Movable, isForward, isEnd bool)

func Word added in v0.1.17

func Word(m Movable, isForward, isEnd bool)

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