edit

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package edit owns headless, grapheme-safe text state. Offsets are UTF-8 bytes; caret movement is logical, not visual. Rendering may project these offsets onto bidi runs to paint discontiguous selection rectangles.

Index

Constants

View Source
const MaxClipboardBytes = 1 << 20

Variables

This section is empty.

Functions

func Boundaries

func Boundaries(s string) []int

Types

type AsyncClipboard

type AsyncClipboard interface {
	ReadTextAsync(ctx context.Context, limit int, deliver func([]byte, error)) error
	WriteText([]byte) error
}

AsyncClipboard starts an asynchronous paste. The callback must be delivered to the UI loop, never invoked by a Wayland reader or transport goroutine. Unlike Clipboard.ReadText, ReadTextAsync does not wait for another process. Implementations must cap reads at limit bytes plus one and honor cancellation.

type Clipboard

type Clipboard interface {
	ReadText(limit int) ([]byte, error)
	WriteText([]byte) error
}

Clipboard is a bounded text/plain;charset=utf-8 port. Implementations own transport, cancellation and file descriptors; the editor never retains one.

type IME

type IME interface {
	Enable()
	Disable()
	Surrounding(text string, cursor, anchor int)
	CursorRect(x, y, w, h float64)
	ContentType(password, multiline bool)
}

IME is a text-input-v3-shaped output port. All offsets are UTF-8 bytes.

type IMEBatch

type IMEBatch struct {
	Preedit                   string
	Begin, End                int
	Commit                    string
	DeleteBefore, DeleteAfter int
}

IMEBatch is applied atomically on text-input-v3 done. Delete offsets are relative to the cursor in bytes, and rounded outwards to grapheme edges.

type State

type State struct {
	Value                    string
	Cursor, Anchor           int
	PreferredX               float64
	PreferredXValid          bool // retained across successive wrapped-line moves
	Preedit                  string
	PreeditBegin, PreeditEnd int
	// contains filtered or unexported fields
}

func (*State) Blur

func (s *State) Blur(ime IME)

func (*State) Copy

func (s *State) Copy(c Clipboard, password bool) error

func (*State) Cut

func (s *State) Cut(c Clipboard, password bool) (bool, error)

func (*State) Delete

func (s *State) Delete(backward bool, word bool) bool

func (*State) Done

func (s *State) Done(b IMEBatch) bool

func (*State) Focus

func (s *State) Focus(ime IME, password, multiline bool)

func (*State) IMEActive

func (s *State) IMEActive() bool

func (*State) Insert

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

func (*State) Left

func (s *State) Left(shift bool)

func (*State) Mask

func (s *State) Mask() string

func (*State) Move

func (s *State) Move(to int, shift bool)

func (*State) Paste

func (s *State) Paste(c Clipboard) (bool, error)

func (*State) PasteAsync

func (s *State) PasteAsync(data []byte, err error) (bool, error)

PasteAsync applies a completed paste on the UI loop. It is the counterpart of Paste for asynchronous transports. It retains the same UTF-8/size checks.

func (*State) Range

func (s *State) Range() (int, int)

func (*State) Right

func (s *State) Right(shift bool)

func (*State) Select

func (s *State) Select(start, end int)

func (*State) Surround

func (s *State) Surround(ime IME, password bool)

func (*State) Sync

func (s *State) Sync(value string)

func (*State) WordAt

func (s *State) WordAt(offset int) (int, int)

WordAt returns exactly the word-iterator segment containing the byte hit. On a boundary it prefers the segment to the right; whitespace and punctuation are segments in their own right. Offsets and results are grapheme-aligned.

func (*State) WordLeft

func (s *State) WordLeft() int

func (*State) WordRight

func (s *State) WordRight() int

Jump to

Keyboard shortcuts

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