scrollwheel

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package scrollwheel coalesces rapid mouse wheel events into batched scroll messages, preventing per-event Update + Render cycles from pegging CPU.

The coalescer intercepts wheel events via a Bubble Tea filter, accumulates deltas over a short debounce window and flushes them as a single Msg. A user-supplied Resolver maps the current model to an application-defined scroll target so the coalescer can route events correctly and flush immediately when the target changes mid-batch.

Index

Constants

View Source
const DefaultDelay = 12 * time.Millisecond

DefaultDelay is the debounce window for coalescing wheel events.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coalescer

type Coalescer[T comparable] struct {
	// contains filtered or unexported fields
}

Coalescer batches rapid mouse wheel events and flushes them as a single Msg after a short debounce window.

func New

func New[T comparable](resolve Resolver[T], send func(tea.Msg), opts ...Option) *Coalescer[T]

New creates a coalescer. The send function is typically tea.Program.Send; it must be safe to call from any goroutine.

func (*Coalescer[T]) Filter

func (c *Coalescer[T]) Filter(model tea.Model, msg tea.Msg) tea.Msg

Filter is a tea.WithFilter-compatible function. It swallows mouse wheel events directed at a scrollable view, accumulates their delta and returns nil so Bubble Tea skips the normal Update + Render cycle. Non-wheel messages pass through unchanged.

func (*Coalescer[T]) Stop

func (c *Coalescer[T]) Stop()

Stop cancels any pending flush and resets accumulated state.

type Msg

type Msg[T comparable] struct {
	Target T
	Delta  int
}

Msg carries an accumulated scroll delta for a given target. Positive delta means scroll down, negative means scroll up.

type Option

type Option func(*config)

Option configures a Coalescer.

func WithDelay

func WithDelay(d time.Duration) Option

WithDelay sets the debounce window. Default is DefaultDelay.

type Resolver

type Resolver[T comparable] func(tea.Model) (T, bool)

Resolver inspects the current model and returns the scroll target for wheel events. Return false when the model is not in a scrollable state; the wheel event will pass through to the normal update loop.

Jump to

Keyboard shortcuts

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