Documentation
¶
Overview ¶
Package editor exposes reusable Zed editor instances over protobuf and Sable. The native backend links GPL-3.0-or-later components. The Go API and custom transports can be used without linking a native backend.
Index ¶
- Variables
- func Run(ctx context.Context, application func(context.Context, *Client) error) error
- type Capabilities
- type Clamp
- type Client
- func (c *Client) Capabilities() Capabilities
- func (c *Client) NextEvent(ctx context.Context) (*Event, error)
- func (c *Client) Open(ctx context.Context, options Options) (*Editor, error)
- func (c *Client) OpenEmbedded(ctx context.Context, target EmbedTarget, options EmbedOptions) (*Editor, error)
- func (c *Client) Quit(ctx context.Context) error
- type Code
- type Editor
- func (e *Editor) Close(ctx context.Context) error
- func (e *Editor) Focus(ctx context.Context) error
- func (e *Editor) ID() uint64
- func (e *Editor) InsertText(ctx context.Context, text string) (*State, error)
- func (e *Editor) Redo(ctx context.Context) (*State, error)
- func (e *Editor) SetReadOnly(ctx context.Context, value bool) (*State, error)
- func (e *Editor) SetSelection(ctx context.Context, start, end Position) (*State, error)
- func (e *Editor) SetText(ctx context.Context, text string) (*State, error)
- func (e *Editor) State(ctx context.Context) (*State, error)
- func (e *Editor) Undo(ctx context.Context) (*State, error)
- type EmbedOptions
- type EmbedTarget
- type Event
- type EventKind
- type Operation
- type Options
- type Position
- type ProtocolError
- type Selection
- type State
- type Transport
- type WidthTable
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Run ¶
Run enters the standalone native host on the process main thread. Call from main, once per process. The callback runs on a goroutine and must return when its context is canceled; returning requests host shutdown. The native host owns Sable and cannot share a process with another Sable runtime owner. Rust applications embedding EditorComponent can provide their own Transport and use NewClient instead of this standalone host.
Types ¶
type Capabilities ¶
type Capabilities struct{ Major, MaxTextBytes, MaxEditors uint32 }
type Clamp ¶
type Clamp int32
Clamp says where a Position inside a wide character, a tab or a grapheme cluster goes.
const ( // ClampNone rejects the position with InvalidArgument. ClampNone Clamp = iota // ClampBefore moves before the character or tab in text order. On a // right-to-left line that is toward the right of the screen. ClampBefore // ClampAfter moves after the character or tab in text order. ClampAfter )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client supports concurrent commands and a single ordered event consumer. Handles belong to this client and the lifetime of its host process.
func (*Client) Capabilities ¶
func (c *Client) Capabilities() Capabilities
func (*Client) NextEvent ¶
NextEvent consumes one event across all editors. Cancellation can race receipt and lose an event; no replay/retry guarantee is provided by this protocol.
func (*Client) OpenEmbedded ¶
func (c *Client) OpenEmbedded(ctx context.Context, target EmbedTarget, options EmbedOptions) (*Editor, error)
OpenEmbedded creates an editor in target's window without showing it. Pass its ID to scene.Embedded, in a view committed after the window has opened. The editor closes with the window. Use a Client from Attach.
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor identifies one persistent native buffer. Closing it invalidates the handle; IDs are never recycled. Closing an editor does not quit the host.
func (*Editor) InsertText ¶
InsertText replaces the current native selections in one undo transaction.
func (*Editor) SetReadOnly ¶
func (*Editor) SetSelection ¶
SetSelection replaces all selections with one from start to end and scrolls it into view. Pass the same position twice for a caret. It is also allowed on a read-only editor, does not move keyboard focus and emits no Changed event. A position outside the buffer returns InvalidArgument, and so does one inside a tab or character unless its Clamp says which way to move. Clamp each end separately: the start before and the end after selects the whole character.
type EmbedOptions ¶
type EmbedOptions struct {
Text string
ReadOnly bool
HideGutter bool
DisableSoftWrap bool
// WidthTable chooses how a Position counts East Asian Ambiguous characters.
// It does not change how they are drawn.
WidthTable WidthTable
}
EmbedOptions configure an editor that is placed inside a generic view.
type EmbedTarget ¶
EmbedTarget is implemented by client.Window. This package has no dependency on the generic client.
type Event ¶
type Event struct {
Sequence, EditorID uint64
Kind EventKind
State *State
Error *ProtocolError
}
type Options ¶
type Options struct {
Title string
Width, Height float32
Text string
ReadOnly bool
HideGutter bool
DisableSoftWrap bool
// WidthTable chooses how a Position counts East Asian Ambiguous characters.
// It does not change how they are drawn.
WidthTable WidthTable
}
Options configure a new local editor window in the supplied standalone host. Zero dimensions select 1000x700. Gutter and soft wrap are enabled by default.
type Position ¶
Position is a zero-based location. Line is a buffer line, and Column counts visual cells from its start, as the editor lays them out and by the East Asian Width table: a wide or fullwidth character takes two, a tab reaches its stop, and a combining mark takes none. An ambiguous character follows the editor's WidthTable. Soft wrapping does not restart the count. Column does not index a Go string.
Character is an alternative to Column when setting a selection: the number of Unicode code points from the start of the line, as counted by utf8.RuneCountInString. Setting both nonzero returns InvalidArgument.
Character and Clamp apply only when setting a selection. Reported positions leave them zero.
type ProtocolError ¶
func (*ProtocolError) Error ¶
func (e *ProtocolError) Error() string
func (*ProtocolError) Is ¶
func (e *ProtocolError) Is(target error) bool
type Selection ¶
type Selection struct{ Start, End Position }
Selection never has Start after End. Equal positions are a caret.
type State ¶
State is an owned snapshot. Revision begins at zero and is local to EditorID. Selection is the newest selection; moving it does not change Revision.
type Transport ¶
Transport must return independently owned response bytes and respect context cancellation. It must not retain request bytes without copying them.
type WidthTable ¶
type WidthTable int32
WidthTable chooses how positions count East Asian Ambiguous characters. The editor draws glyphs from the font either way, so choose the table that matches the font: Japanese fonts usually draw these characters two columns wide.
const ( // WidthNarrowAmbiguous counts every ambiguous character as one column. WidthNarrowAmbiguous WidthTable = iota // WidthWideAmbiguous counts every ambiguous character that has a width as // two columns, including letters such as α and é. WidthWideAmbiguous // WidthWideSymbols counts ambiguous symbols, punctuation and numbers as two // columns and ambiguous letters as one. WidthWideSymbols )