autocomplete

package
v0.0.0-...-5788b19 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: GPL-3.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const AutocompleterWidth = 250

AutocompleterWidth is the minimum width of the popped up autocompleter.

View Source
const MaxResults = 8

MaxResults is the maximum number of search results.

View Source
const WhitespaceRune rune = ' '

WhitespaceRune is a special rune that Searcher can return to indicate that it should be activated on every word.

Variables

This section is empty.

Functions

This section is empty.

Types

type Autocompleter

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

Autocompleter is the autocompleter instance.

func New

func New(ctx context.Context, text *gtk.TextView) *Autocompleter

New creates a new instance of autocompleter.

func (*Autocompleter) AddSelectedFunc

func (a *Autocompleter) AddSelectedFunc(selectedFunc SelectedFunc)

AddSelectedFunc adds a callback that is called when the user has selected an entry inside the autocompleter.

func (*Autocompleter) Autocomplete

func (a *Autocompleter) Autocomplete()

Autocomplete updates the Autocompleter popover to show what the internal input buffer has.

func (*Autocompleter) Clear

func (a *Autocompleter) Clear() bool

Clear clears the Autocompleter and hides it.

func (*Autocompleter) IsVisible

func (a *Autocompleter) IsVisible() bool

IsVisible returns true if the popover is currently visible.

func (*Autocompleter) MoveDown

func (a *Autocompleter) MoveDown() bool

func (*Autocompleter) MoveUp

func (a *Autocompleter) MoveUp() bool

func (*Autocompleter) Pause

func (a *Autocompleter) Pause()

Pause pauses the autocompleter. The popover is hidden if it's currently being shown.

func (*Autocompleter) Select

func (a *Autocompleter) Select() bool

Select selects the current Autocompleter entry.

func (*Autocompleter) SetCancelOnChange

func (a *Autocompleter) SetCancelOnChange(v bool)

SetCancelOnChange sets whether or not the autocompleter context should be cancelled every time the buffer is changed. Default is false, so the context is alive even when the old widgets are thrown away.

func (*Autocompleter) SetMinLength

func (a *Autocompleter) SetMinLength(minLength int)

SetMinLength sets the minimum number of characters before the autocompleter kicks in.

func (*Autocompleter) SetPopoverWidth

func (a *Autocompleter) SetPopoverWidth(width int)

SetPopoverWidth sets the width of the popover. The default width is 250px.

func (*Autocompleter) SetTimeout

func (a *Autocompleter) SetTimeout(d time.Duration)

SetTimeout sets the timeout for each autocompletion.

func (*Autocompleter) Unpause

func (a *Autocompleter) Unpause()

Unpause unpauses the autocompleter.

func (*Autocompleter) Unuse

func (a *Autocompleter) Unuse(searcher Searcher)

Unuse removes the given searcher instance from the autocompleter using the given identifying rune.

func (*Autocompleter) Use

func (a *Autocompleter) Use(searchers ...Searcher)

Use registers the given searcher instance into the autocompleter.

type Data

type Data interface {
	// Row constructs a new ListBoxRow for display inside the list.
	Row(context.Context) *gtk.ListBoxRow
}

Data represents a data structure capable of being displayed inside a list by constructing a new ListBoxRow.

type IterData

type IterData struct {
	Start *gtk.TextIter
	End   *gtk.TextIter
}

IterData contains iterator data that's given to Searcher.Search's context. Use IterDataFromContext to get it.

func IterDataFromContext

func IterDataFromContext(ctx context.Context) *IterData

IterDataFromContext returns the IterData from the given context. If the context does not contain any IterData, then it panics.

type Searcher

type Searcher interface {
	// Rune is the triggering rune for this searcher. If ' ' is returned, then
	// the searcher is always invoked on a complete word.
	Rune() rune
	// Search searches the given string and returns a list of data. The returned
	// list of Data only needs to be valid until the next call of Search.
	Search(ctx context.Context, str string) []Data
}

Searcher is the interface for anything that can handle searching up a particular entity, such as a room member.

type SelectedData

type SelectedData struct {
	// Bounds contains the iterators that sit around the word used for
	// searching. The iterators are guaranteed to be valid until the callback
	// returns.
	Bounds [2]*gtk.TextIter
	// Data is the selected entry's data.
	Data Data
}

SelectedData wraps around a Data to provide additional metadata that could be useful for the user.

type SelectedFunc

type SelectedFunc func(SelectedData) bool

SelectedFunc is the callback type that is called when the user has selected an entry inside the autocompleter. If the callback returns true, then the autocompleter closes itself; otherwise, it does nothing.

Jump to

Keyboard shortcuts

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