scroll

package
v1.27.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package scroll provides Vim-style scrolling functionality for the Neru application.

This package implements a comprehensive scrolling system that allows users to navigate content using familiar Vim-style keybindings. The scroll functionality can be used both as a standalone mode and within other navigation modes (hints/grid) for precise content navigation.

Index

Constants

View Source
const (
	ArrowUp    = "Up"
	ArrowDown  = "Down"
	ArrowLeft  = "Left"
	ArrowRight = "Right"
	PageUp     = "PageUp"
	PageDown   = "PageDown"
)

Arrow key names for normalized key mapping. These use the canonical display forms from the centralized validNamedKeys registry.

View Source
const (
	ActionScrollUp    = "scroll_up"
	ActionScrollDown  = "scroll_down"
	ActionScrollLeft  = "scroll_left"
	ActionScrollRight = "scroll_right"
	ActionGoTop       = "go_top"
	ActionGoBottom    = "go_bottom"
	ActionPageUp      = "page_up"
	ActionPageDown    = "page_down"
)

Scroll action names used in configuration.

View Source
const SequenceTimeout = 500 * time.Millisecond

SequenceTimeout is the maximum time allowed between keys in a multi-key sequence.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action added in v1.13.0

type Action struct {
	Direction services.ScrollDirection
	Amount    services.ScrollAmount
}

Action represents a scroll action with direction and amount.

type Context

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

Context holds the state and context for scroll mode operations.

func (*Context) IsActive

func (c *Context) IsActive() bool

IsActive returns whether scroll mode is currently active.

func (*Context) LastKey

func (c *Context) LastKey() string

LastKey returns the last key pressed during scroll operations.

func (*Context) LastKeyState added in v1.21.4

func (c *Context) LastKeyState() (string, int64)

LastKeyState atomically returns both the last key and its timestamp. Use this instead of separate LastKey()/LastKeyTime() calls when both values are needed together to avoid TOCTOU races.

func (*Context) LastKeyTime added in v1.13.0

func (c *Context) LastKeyTime() int64

LastKeyTime returns the timestamp when the last key was pressed.

func (*Context) Reset

func (c *Context) Reset()

Reset resets the scroll context to its initial state.

func (*Context) SetIsActive

func (c *Context) SetIsActive(active bool)

SetIsActive sets whether scroll mode is currently active.

func (*Context) SetLastKey

func (c *Context) SetLastKey(key string)

SetLastKey sets the last key pressed during scroll operations. When key is non-empty, the timestamp is updated to now. When key is empty (clearing state), the timestamp is zeroed.

type KeyMap added in v1.13.0

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

KeyMap maps key bindings to scroll actions and handles key sequence detection.

func NewKeyMap added in v1.13.0

func NewKeyMap(bindings map[string][]string) *KeyMap

NewKeyMap creates a new KeyMap from the given bindings. Bindings is a map from action names to lists of key strings.

func (*KeyMap) Action added in v1.13.0

func (m *KeyMap) Action(name string) (Action, bool)

Action returns the Action struct for a given action name and whether it was found.

func (*KeyMap) CanCompleteSequence added in v1.13.0

func (m *KeyMap) CanCompleteSequence(first, second string) bool

CanCompleteSequence returns true if the given two keys form a complete sequence.

func (*KeyMap) IsSequenceStart added in v1.13.0

func (m *KeyMap) IsSequenceStart(key string) bool

IsSequenceStart returns true if the given key can start a multi-key sequence.

func (*KeyMap) KeyToAction added in v1.13.0

func (m *KeyMap) KeyToAction() map[string]string

KeyToAction returns the map of single keys to action names.

func (*KeyMap) Lookup added in v1.13.0

func (m *KeyMap) Lookup(key string) (string, bool)

Lookup returns the action name for a given key and whether it was found.

func (*KeyMap) LookupSequence added in v1.13.0

func (m *KeyMap) LookupSequence(seq string) (string, bool)

LookupSequence returns the action name for a complete key sequence and whether it was found.

func (*KeyMap) Normalize added in v1.13.0

func (m *KeyMap) Normalize(key string) string

Normalize converts a key string to its canonical form.

func (*KeyMap) Sequences added in v1.13.0

func (m *KeyMap) Sequences() map[string]string

Sequences returns the map of key sequences to action names.

type SequenceState added in v1.13.0

type SequenceState struct {
	FirstKey   string
	ReceivedAt int64
}

SequenceState tracks the state of an incomplete key sequence.

func NewSequenceState added in v1.13.0

func NewSequenceState(key string, receivedAt int64) *SequenceState

NewSequenceState creates a new SequenceState for the given first key and timestamp.

func (*SequenceState) Expired added in v1.13.0

func (s *SequenceState) Expired() bool

Expired returns true if the sequence has exceeded the timeout window.

Jump to

Keyboard shortcuts

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