Documentation ¶
Index ¶
- type AppliedChangeHook
- type Binder
- type Canceler
- type ChangeHook
- type Confirmer
- type ContextChangeHook
- type Handler
- func (h *Handler) Apply(e text.Editor, edits ...text.Edit)
- func (e *Handler) Bind(b bind.Bindable) (text.Handler, error)
- func (e *Handler) HandleEvent(focused text.Editor, ev gxui.KeyboardEvent)
- func (e *Handler) HandleInput(focused text.Editor, ev gxui.KeyStrokeEvent)
- func (e *Handler) Init(newEditor text.Editor, contents []rune)
- func (e *Handler) Name() string
- func (e *Handler) New() text.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppliedChangeHook ¶
An AppliedChangeHook is a hook that needs to be informed about edits immediately after they are applied, before the call to Apply is finished. Its Applied method will be called synchronously in the Handler, so it should be as minimal as possible.
type Canceler ¶
type Canceler interface { // Cancel is called when the hook should be cancelled. It should // return true if it should consume the cancel event. Cancel(text.Editor) (cancelled bool) }
Canceler is a type that needs to know when it's being cancelled. This could be anything from a long-running process that can't make use of the context.Context (for whatever reason) to a type that adds itself to the UI and needs to know when it should be removed.
type ChangeHook ¶
type ChangeHook interface { // Init is called when a file is opened, to initialize the // hook. The full text of the editor will be passed in. Init(text.Editor, []rune) // TextChanged is called for every text edit. // // TextChanged may be called multiple times prior to Apply if // more edits happen before Apply is called. // // Hooks that have to start over from scratch when new updates // are made should implement ContextChangeHook, instead. TextChanged(text.Editor, text.Edit) // Apply is called when there is a break in text changes, to // apply the hook's event. Unlike TextChanged, Apply is // called in the main UI thread. Apply(text.Editor) error }
ChangeHook is a hook that triggers events on text changing. Each ChangeHook gets its own goroutine that will be used to process events. When there is a lull in the number of events coming through (i.e. there is a pause in typing), Apply will be called from the UI goroutine.
For plugins that need to process all events at once, or apply to the entire file instead of one edit at a time, implement ContextChangeHook.
type Confirmer ¶
type Confirmer interface { // Confirm will be called when a confirmation key is pressed. // It should return true if it should consume the confirmation // event. Confirm(text.Editor) (confirmed bool) }
Confirmer is a type that needs to know when a user is confirming an action. It is typically a type that adds itself to the UI requesting that the user respond in some way. The input handler will interpret user key presses and call all confirmers when a confirmation key (enter, in the default handler) is pressed.
type ContextChangeHook ¶
type ContextChangeHook interface { // Init is called when a file is opened, to initialize the // hook. The full text of the editor will be passed in. Init(text.Editor, []rune) // TextChanged is called in a new goroutine whenever any text // is changed in the editor. Any changes to the UI should be // saved for Apply, since most of those calls must be called // in the UI goroutine. // // If TextChanged is currently running and new edits come // through, the context.Context will be cancelled and // TextChanged will be called again with the new edits appended // to those from the previous call. TextChanged(context.Context, text.Editor, []text.Edit) // Apply is called when there is a break in text changes, to // apply the hook's event. Unlike TextChanged, Apply is // called in the main UI thread. Apply(text.Editor) error }
ContextChangeHook is similar to a ChangeHook, but takes a context.Context that will be cancelled if new changes show up before Apply is called.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is vidar's default input handler. It takes the runes typed and writes them to the editor's text box, allowing plugins to bind to text change events.
It can be overridden by installing a plugin that implements commander.Handler.
TODO: Remove the need for so much of the editor's methods. Ideally, we should be able to do what we need to do with just text.Editor. This may require expanding text.Editor some, but we shouldn't need editor.Controller for so much of what we're doing. Basic editing should be handleable by the editor.
func (*Handler) HandleEvent ¶
func (e *Handler) HandleEvent(focused text.Editor, ev gxui.KeyboardEvent)
func (*Handler) HandleInput ¶
func (e *Handler) HandleInput(focused text.Editor, ev gxui.KeyStrokeEvent)