field

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package field keeps what a backend reports about one text field the way NSH's platforms do, whatever control edits it: the user's edits and their count, a composition and the value the app sets during one, the selection, keys and maxLength.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Replaced

func Replaced(old, text string) (start, end int, insert string)

Replaced is what turns old into text, in UTF-16 units, the offsets UIKit's and AppKit's text inputs take: old's units from start to end become insert. A surrogate pair stays whole, and equal texts give an empty range at old's end.

func SingleLine

func SingleLine(s string) string

SingleLine replaces line breaks with spaces, as a single-line field holds them.

Types

type State

type State struct {
	ID driver.NodeID
	// Events is the field's mask (ItemEvents); Config its last ItemInput.
	Events   driver.EventMask
	Config   driver.InputConfig
	Dispatch func(driver.Event)

	// Count is the user's edits reported.
	Count uint32
	// contains filtered or unexported fields
}

State is the reporting side of one text field. Backends call it from their main thread as the control changes, and it dispatches the events the field's mask asks for.

func (*State) Compose

func (s *State) Compose(composing bool, text, current string) (value string, apply bool)

Compose records the input method's composition (composing false once it ended) and reports a change. When it ends, it returns a value the app set meanwhile for the backend to set, provided no edit came since and current, the field's text, is what the engine knows.

func (*State) Composing

func (s *State) Composing() bool

Composing reports whether an input method composes in the field.

func (*State) Edited

func (s *State) Edited(text string) bool

Edited reports the user's edit leaving text in the field, unless the engine already knows it holds text. It returns whether it reported.

func (*State) Insert

func (s *State) Insert(current string, replaced int, insert string) (kept string, ok, whole bool)

Insert answers whether the user's edit replacing replaced UTF-16 units of current with insert may happen, as the platforms' should-change callbacks ask: it reports the key and returns the part of insert MaxLength leaves room for, with line breaks made spaces in a single line. ok is false when nothing of a non-empty insert fits, and whole whether kept is insert as it came.

func (*State) Key

func (s *State) Key(key string)

Key reports a key the user typed: its text, "Backspace" or "Enter".

func (*State) Known

func (s *State) Known() string

Known is the text the engine knows the field holds.

func (*State) Return

func (s *State) Return(text string, lineBreak bool) (insert, blur bool)

Return decides what Return does: true when the backend lets the control insert a line break, else it has reported the key and the submit and returns whether to blur. lineBreak is a modifier held (Shift, Option, Alt) that breaks the line of a multiline field that submits.

func (*State) Selected

func (s *State) Selected(r driver.TextRange)

Selected reports the selection the user left, in UTF-16 units, if it moved.

func (*State) Selection

func (s *State) Selection() driver.TextRange

Selection is the selection last reported or set.

func (*State) SetSelection

func (s *State) SetSelection(r driver.TextRange)

SetSelection records a selection the app set, which is not reported.

func (*State) Value

func (s *State) Value(text string, count uint32) bool

Value is ItemInputValue: it reports whether the backend sets the text now. A value older than the user's last edit is dropped, and one that comes during a composition is held until it ends, since setting the text would end the composition and commit what it composes.

Jump to

Keyboard shortcuts

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