Documentation ¶
Overview ¶
Package op has sub-packages that provide core operations that can be used by plugins and built-ins to either to change the editor's state or to trigger hooks from changes to the editor's state. No state change can be applied to the editor without going through these.
For Plugins: This package imports ./internal/. Vidar's compatibility guarantees *do not* prevent us from making changes to any of this code in minor or patch versions. For this reason, the parameter and return types used by types in sub-packages of this package are imported from pkg and its sub-packages. This allows plugin authors to create local interface types to use when type-asserting, rather than relying on volatile code that could break plugins in minor and patch updates.
We recommend that plugins avoid directly importing this package as much as possible. So instead of `bindable.Bound().Named("window-manager").(*window.Manager)`, define a local interface and type assert to that instead:
type WindowManager interface { OpenWindow() input.Operation CloseWindow() (input.Operation, error) } func Op(b Bindable) (input.Operation, error) { w, ok := b.Bound().Named("window-manager").(WindowManager) if !ok { return nil, fmt.Errorf("could not find window-manager op") } return w.Open(), nil }
In the above code, you can see that w is a *window.Manager, but the op package is not referenced at all, decoupling the code from vidar's core/ package.
To help encourage this pattern, vidar itself uses a copyleft license, but the pkg/ directory and its sub-packages use a more permissive license - allowing plugins to be released with permissive or proprietary licenses as long as they don't import anything in vidar outside of pkg.
Index ¶
- Constants
- func Actions(ctx context.Context, c ui.Creator) []input.Action
- func DefaultInputHandler(_ context.Context, _ input.Binder, in *input.Edit, ev *input.KeyEvent) (input.Operation, bool, error)
- func NewFocus() input.Operation
- type Edit
- func (e *Edit) Apply(edit []rune) input.Operation
- func (e *Edit) ApplyEdit(edits ...input.Edit) input.Operation
- func (e *Edit) ApplyLineEdit(edits ...input.LineEdit) input.Operation
- func (e *Edit) Delete(n int) input.Operation
- func (e *Edit) Empty(context.Context) input.HookedOperation
- func (e *Edit) Name(context.Context) string
- func (e *Edit) Restore(state text.State) input.Operation
- func (e *Edit) Run(ctx context.Context, b input.Binder) error
- func (e *Edit) SetHook(ctx context.Context, h input.Hook) error
- func (e *Edit) Type(input.Operation)
- func (e *Edit) Valid(_ context.Context, b input.Binder) error
- type EditSpanApplier
- type FileClosedHook
- type FileClosingHook
- type FileManager
- func (m *FileManager) After(callback func(context.Context, input.Binder) error) input.Operation
- func (m *FileManager) CloseFile() input.Operation
- func (m *FileManager) Empty(context.Context) input.HookedOperation
- func (m *FileManager) FileBinder(ctx context.Context, path string) (input.Binder, error)
- func (m *FileManager) Name(context.Context) string
- func (m *FileManager) OpenFile(name, path string) input.Operation
- func (m *FileManager) RetainFocus() input.Operation
- func (m *FileManager) Run(ctx context.Context, b input.Binder) (retErr error)
- func (m *FileManager) SaveFile() input.Operation
- func (m *FileManager) SetHook(_ context.Context, h input.Hook) error
- func (m *FileManager) Type(input.Operation)
- func (m *FileManager) Valid(_ context.Context, b input.Binder) error
- type FileOpenedHook
- type FileSavedHook
- type FileSavingHook
- type Focus
- type Focuser
- type History
- type InfoAccessor
- type Inform
- func (i *Inform) Box() input.Binder
- func (i *Inform) Error(v string) input.Operation
- func (i *Inform) Info(v string) input.Operation
- func (i *Inform) Name(context.Context) string
- func (i *Inform) Run(ctx context.Context, b input.Binder) error
- func (i *Inform) Type(input.Operation)
- func (i *Inform) Warn(v string) input.Operation
- func (i *Inform) WithBox(b *internal.InfoBox) input.Action
- type Loader
- func (l *Loader) Add(b input.Binder) input.Operation
- func (l *Loader) Name(context.Context) string
- func (l *Loader) Remove(b input.Binder) input.Operation
- func (l *Loader) RemoveChild() input.Operation
- func (l *Loader) Run(ctx context.Context, b input.Binder) error
- func (l *Loader) Type(input.Operation)
- func (l *Loader) Valid(_ context.Context, b input.Binder) error
- func (l *Loader) WithPlaceholder(p *internal.Placeholder) input.Action
- type Multi
- type Namer
- type NewWindowHook
- type PlaceholderAccessor
- type Prompt
- func (p *Prompt) Callback(...) input.Operation
- func (p *Prompt) Caller(act input.Action) input.Operation
- func (p *Prompt) Extra(lines ...[]ui.Span) input.Operation
- func (p *Prompt) HandleInput(...) input.Operation
- func (p *Prompt) Input(text string) input.Operation
- func (p *Prompt) Name(context.Context) string
- func (p *Prompt) Prompt(spans ...ui.Span) input.Operation
- func (p *Prompt) Run(ctx context.Context, b input.Binder) error
- func (p *Prompt) Type(input.Operation)
- func (p *Prompt) WithBox(b *internal.InfoBox) input.Action
- type PromptCallback
- func (c *PromptCallback) Name(context.Context) string
- func (c *PromptCallback) PromptEdit(e input.Edit) input.Operation
- func (c *PromptCallback) PromptEvent(e input.KeyEvent) input.Operation
- func (c *PromptCallback) Run(ctx context.Context, b input.Binder) error
- func (c *PromptCallback) Type(input.Operation)
- func (c *PromptCallback) Valid(_ context.Context, b input.Binder) error
- type PromptInputHook
- func (h *PromptInputHook) Name(context.Context) string
- func (h *PromptInputHook) OpNames(context.Context) []string
- func (h *PromptInputHook) TextChanged(ctx context.Context, b input.Binder, hist ...)
- func (h *PromptInputHook) TextChangedOp(ctx context.Context, b input.Binder) input.Operation
- func (h *PromptInputHook) Type(input.Hook)
- func (h *PromptInputHook) Valid(ctx context.Context, b input.Binder) error
- type RawPrompt
- func (p *RawPrompt) Caller(ctx context.Context, b input.Binder) input.Action
- func (p *RawPrompt) Name(context.Context) string
- func (p *RawPrompt) ReturnBinder(b input.Binder) input.Operation
- func (p *RawPrompt) Run(ctx context.Context, b input.Binder) error
- func (p *RawPrompt) Type(input.Operation)
- func (p *RawPrompt) Valid(_ context.Context, b input.Binder) error
- type Scroll
- func (s *Scroll) Name(context.Context) string
- func (s *Scroll) Run(ctx context.Context, b input.Binder) error
- func (s *Scroll) ScrollPos(pos int) input.Operation
- func (s *Scroll) ScrollType(typ ui.ScrollType) input.Operation
- func (s *Scroll) Type(input.Operation)
- func (s *Scroll) Valid(_ context.Context, b input.Binder) error
- type ScrollOnMoveHook
- type ScrollOp
- type Scrollable
- type SelManager
- type SelectionManager
- func (m *SelectionManager) Empty(context.Context) input.HookedOperation
- func (m *SelectionManager) Name(context.Context) string
- func (m *SelectionManager) Run(ctx context.Context, b input.Binder) error
- func (m *SelectionManager) Select(primary caret.Selection, secondary ...caret.Selection) input.Operation
- func (m *SelectionManager) SetHook(_ context.Context, h input.Hook) error
- func (m *SelectionManager) Type(input.Operation)
- func (m *SelectionManager) Valid(_ context.Context, b input.Binder) error
- type SelectionsChangedHook
- type Selector
- type SpanApplier
- func (a *SpanApplier) Empty(context.Context) input.HookedOperation
- func (a *SpanApplier) Name(context.Context) string
- func (a *SpanApplier) Run(ctx context.Context, b input.Binder) error
- func (a *SpanApplier) SetHook(_ context.Context, h input.Hook) error
- func (a *SpanApplier) Type(input.Operation)
- func (a *SpanApplier) Valid(_ context.Context, b input.Binder) error
- func (a *SpanApplier) WithSpans(spans ...ui.Span) input.Operation
- type SpanUpdater
- type SpansChangingHook
- type TextChangedHook
- type TextChangingHook
- type TextContainer
- type TextJustChangedHook
- type TextMetadata
- type WindowManager
- func (m *WindowManager) CloseWindow() input.Operation
- func (m *WindowManager) Empty(context.Context) input.HookedOperation
- func (m *WindowManager) Name(context.Context) string
- func (m *WindowManager) OpenWindow() input.Operation
- func (m *WindowManager) Run(ctx context.Context, b input.Binder) error
- func (m *WindowManager) SetActions(_ context.Context, a []internal.Action)
- func (m *WindowManager) SetHook(_ context.Context, h input.Hook) error
- func (m *WindowManager) Type(input.Operation)
- func (m *WindowManager) Valid(_ context.Context, b input.Binder) error
Constants ¶
const MetaKey = "vidar|edit-applier"
MetaKey documents the string value that Edit stores TextMetadata in. Types that need to calculate data about the text may check for a value at this key in a context.Context before performing expensive calculations themselves.
Example:
type TextMeta interface { Lines(context.Context) int LineChars(context.Context, int) int LineTabs(context.Context, int) int } func doAThing(ctx context.Context) { meta, ok := ctx.Get("vidar|edit-applier").(TextMeta) }
Variables ¶
This section is empty.
Functions ¶
func DefaultInputHandler ¶
func DefaultInputHandler(_ context.Context, _ input.Binder, in *input.Edit, ev *input.KeyEvent) (input.Operation, bool, error)
DefaultInputHandler is the default function for handling input in prompts. This default callback very simply returns done==true when in.New ends with \n or ev.Code==enter.
Types ¶
type Edit ¶
type Edit struct {
// contains filtered or unexported fields
}
Edit is the Operation that should always be used to change text in an input.Binder. As a core operation, it has direct access to the text storage of the editor itself.
func (*Edit) Apply ¶
Apply returns a copy of e with edit stored as a proposed change. When Run is called, the edit will be applied to all selections.
func (*Edit) ApplyEdit ¶
ApplyEdit returns a copy of e which will directly apply edits, ignoring the selections. This is useful for auto-formatters, line indenters, and other action types that make changes away from the selections.
func (*Edit) ApplyLineEdit ¶
ApplyLineEdit returns a copy of e which will directly apply LineEdits, ignoring selections.
func (*Edit) Delete ¶
Delete returns a copy of e which will delete the following n characters (or the previous -n characters, if n is negative) at each selection.
func (*Edit) Empty ¶
func (e *Edit) Empty(context.Context) input.HookedOperation
Empty returns a new, empty *Edit.
func (*Edit) Run ¶
Run runs the prepped changes in a. If no changes are prepped, nothing will happen.
type EditSpanApplier ¶
EditSpanApplier represents the action that the Edit op needs in order to display changed text to the user.
type FileClosedHook ¶
FileClosedHook is a hook that needs to be called after a file is closed.
type FileClosingHook ¶
FileClosingHook is a hook that needs to be called before a file is closed. If an error is returned, the file will not be closed and the error will be displayed to the user.
type FileManager ¶
type FileManager struct {
// contains filtered or unexported fields
}
FileManager is the core operation that manages opening, saving, and closing files.
func NewFileManager ¶
func NewFileManager(ctx context.Context, creator ui.Creator) *FileManager
NewFileManager creates a FileManager. The creator will be used to create text editing UI componenents for new files.
func (*FileManager) CloseFile ¶
func (m *FileManager) CloseFile() input.Operation
func (*FileManager) Empty ¶
func (m *FileManager) Empty(context.Context) input.HookedOperation
Empty implements HookedOperation
func (*FileManager) FileBinder ¶
func (*FileManager) RetainFocus ¶
func (m *FileManager) RetainFocus() input.Operation
RetainFocus tells FileManager that it should not perform any change to the editor's focus. This is useful for opening files in the background, e.g. for applying refactor operations across multiple files.
func (*FileManager) SaveFile ¶
func (m *FileManager) SaveFile() input.Operation
func (*FileManager) Type ¶
func (m *FileManager) Type(input.Operation)
type FileOpenedHook ¶
FileOpenedHook is a hook that needs to be called after a file is opened.
type FileSavedHook ¶
FileSavedHook is a hook that needs to be called after a file is saved.
type FileSavingHook ¶
FileSavingHook is a hook that needs to perform some work before a file is saved to disk.
A non-nil error will prevent the file from being saved.
type Focus ¶
type Focus struct {
// contains filtered or unexported fields
}
Focus is an input.Operation that can manipulate the focused ui element(s) in a window.
type InfoAccessor ¶
InfoAccessor is a type which needs to have access to the InfoBox for a given Window.
type Inform ¶
type Inform struct {
// contains filtered or unexported fields
}
Inform is an operation that can be used to inform the user about the state of the world.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
func (*Loader) RemoveChild ¶
func (*Loader) WithPlaceholder ¶
func (l *Loader) WithPlaceholder(p *internal.Placeholder) input.Action
type Namer ¶
Namer represents an input.Binder that has a name associated with it (e.g. an open file with the file path as its name).
type NewWindowHook ¶
NewWindowHook is an input.Hook that needs to know when a window is opened.
type PlaceholderAccessor ¶
type PlaceholderAccessor interface { input.Action WithPlaceholder(*internal.Placeholder) input.Action }
PlaceholderAccessor is a type which needs to have access to the main Placeholder for a given Window.
type Prompt ¶
type Prompt struct {
// contains filtered or unexported fields
}
Prompt is an operation that can be used to get input from the user. It is essentially the same as RawPrompt, except that it is bound to all input.Binder values so that it knows which input.Binder to return focus to after loading user input.
Most actions that need to prompt the user for input should use this operation to prompt the user for information.
func (*Prompt) Callback ¶
func (p *Prompt) Callback(f func(_ context.Context, b input.Binder, prompt []ui.Span, input string, extra [][]ui.Span) (input.Operation, error)) input.Operation
Callback is used to set a callback function to configure an input.Operation to run when the user is finished providing input. The callback is passed everything that was last in the prompt at the time of the input handler reporting that the user was done.
We recommend that the callback function look up input.Operation values on b, to ensure that the correct operation (bound to the correct input.Binder) is loaded. Then the callback function should configure the input.Operation based on the user's input and return it.
func (*Prompt) Caller ¶
Caller is used to set the calling input.Action which is prompting the user. This will be available on the raw-prompt action's Caller method.
func (*Prompt) Extra ¶
Extra is used to set the extra spans, displayed after the user input field. This is intended for things like completion suggestions (e.g. files that match the user's input) or information about values already entered.
Each slice of spans will appear on a separate line.
func (*Prompt) HandleInput ¶
func (p *Prompt) HandleInput(f func(context.Context, input.Binder, *input.Edit, *input.KeyEvent) (_ input.Operation, done bool, _ error)) input.Operation
HandleInput is used to set an input handler function on the prompt. This function will be called with either an input.Edit or an input.KeyEvent, never both.
By default, DefaultInputHandler will be used. It is not necessary to implement a callback function unless the prompt needs to do something specialized (e.g. provide auto-completion or handle newlines specially).
We require an input.Operation return type in this function so that it may be implemented by plugins without importing this package; however, the only supported input.Operation types are *Prompt and *RawPrompt. The function may return one of those in order to adjust the prompt text based on user input.
Example:
type Prompt interface { Prompt(...ui.Span) input.Operation Extra(...ui.Span) input.Operation HandleInput(func(*input.Edit, *input.KeyEvent) (input.Operation, bool, error)) input.Operation } func (someCmd) Op(ctx context.Context, b input.Binder) (input.Operation, error) { var filename string return prompterb.Bound(ctx).Named(ctx, "prompt").(Prompt) Prompt(span("file:")).(Prompt) HandleInput(func(e *input.Edit, _ *input.KeyEvent) (input.Operation, bool, error) { if e == nil || len(e.New) == 0 { return nil, false, nil } if e.New[len(e.New)-1] == '\n' { // This part is the same as DefaultInputHandler return nil, true, nil } filename += string(e.New) extra := addCompletions(filename) op := b.Bound(ctx).Named(ctx, "prompt").(Prompt). Extra(extra) return op, false, nil }), nil }
func (*Prompt) Input ¶
Input is used to set the input text, e.g. for providing a default or applying suggestions/completions.
type PromptCallback ¶
type PromptCallback struct {
// contains filtered or unexported fields
}
PromptCallback is used by the PromptInputHook to send events to the InfoBox.
func NewPromptCallback ¶
func NewPromptCallback() *PromptCallback
func (*PromptCallback) Name ¶
func (c *PromptCallback) Name(context.Context) string
Name returns PromptCallback's name.
func (*PromptCallback) PromptEdit ¶
func (c *PromptCallback) PromptEdit(e input.Edit) input.Operation
PromptEdit returns a PromptCallback that will inform the InfoBox about new input when Run is called.
func (*PromptCallback) PromptEvent ¶
func (c *PromptCallback) PromptEvent(e input.KeyEvent) input.Operation
PromptEvent returns a PromptCallback that will inform the InfoBox about a key event when Run is called.
func (*PromptCallback) Run ¶
Run runs c, sending any events that have been queued to b. b must be an *internal.InfoBox.
func (*PromptCallback) Type ¶
func (c *PromptCallback) Type(input.Operation)
Type implements input.Operation
type PromptInputHook ¶
type PromptInputHook struct { }
PromptInputHook is a hook that attaches to the edit-applier operation when the edits are applying to an InfoBox's input. This means that it only works if the input.Binder it is bound to is a child of an InfoBox. To ensure that we reject any binders that are _not_ children of an InfoBox, we look up the PromptCallback operation - if it is not bound, we reject the binder.
func NewPromptInputHook ¶
func NewPromptInputHook() *PromptInputHook
NewPromptInputHook returns an allocated PromptInputHook.
func (*PromptInputHook) Name ¶
func (h *PromptInputHook) Name(context.Context) string
Name returns PromptInputHook's name.
func (*PromptInputHook) OpNames ¶
func (h *PromptInputHook) OpNames(context.Context) []string
OpNames returns the operation names that h needs to be hooked to.
func (*PromptInputHook) TextChanged ¶
func (h *PromptInputHook) TextChanged(ctx context.Context, b input.Binder, hist ...struct { Before text.State Edit input.Edit })
TextChanged is executed by the edit-applier operation after text has changed. h queues these edits up to report to the InfoBox during a lull in user input.
func (*PromptInputHook) TextChangedOp ¶
Op returns a multi-operation to report all edits that have happened to the info box.
func (*PromptInputHook) Type ¶
func (h *PromptInputHook) Type(input.Hook)
Hook implements input.Hook.
type RawPrompt ¶
type RawPrompt struct {
// contains filtered or unexported fields
}
RawPrompt is an operation that reads input from a user on the InfoBox. It relies on the caller to understand which binder to return focus to once it has finished reading user input.
func NewRawPrompt ¶
func NewRawPrompt() *RawPrompt
func (*RawPrompt) Caller ¶
Caller may be used to check the input.Action that called for this prompt. It is the responsibility of the caller to set itself on the Prompt, otherwise this will return nil.
func (*RawPrompt) ReturnBinder ¶
ReturnBinder tells the RawPrompt which binder it needs to return focus to after the user is done entering input. If RawPrompt is run without having this method called first, it will error rather than locking the user in the dialog box.
type Scroll ¶
type Scroll struct {
// contains filtered or unexported fields
}
func (*Scroll) ScrollType ¶
func (s *Scroll) ScrollType(typ ui.ScrollType) input.Operation
type ScrollOnMoveHook ¶
type ScrollOnMoveHook struct{}
func NewScrollOnMove ¶
func NewScrollOnMove() *ScrollOnMoveHook
func (*ScrollOnMoveHook) SelectionsChanged ¶
func (*ScrollOnMoveHook) Type ¶
func (s *ScrollOnMoveHook) Type(input.Hook)
type Scrollable ¶
type SelManager ¶ added in v0.6.3
SelManager is used to restore selections when restoring a previous state.
type SelectionManager ¶
type SelectionManager struct {
// contains filtered or unexported fields
}
func NewSelectionManager ¶
func NewSelectionManager() *SelectionManager
func (*SelectionManager) Empty ¶
func (m *SelectionManager) Empty(context.Context) input.HookedOperation
func (*SelectionManager) Type ¶
func (m *SelectionManager) Type(input.Operation)
type SelectionsChangedHook ¶
type SelectionsChangedHook interface { input.Hook // SelectionsChanged will be called when the selections in the binder have // changed, e.g. when the caret moves. The returned input.Operation will be // run as soon as there is a pause in user input. // // SelectionsChanged may be called multiple times before the returned // input.Operation values are run. SelectionsChanged(_ context.Context, _ input.Binder, oldPrimary caret.Selection, oldSecondary []caret.Selection, newPrimary caret.Selection, newSecondary []caret.Selection, ) input.Operation }
SelectionsChangedHook is a hook that needs to be notified when the selections have changed. This hook is expected to be called concurrently. ctx will be canceled if the selections change before the hook has returned.
Note that the selection slice passed in is a copy - making changes to it will not change the actual selections.
type SpanApplier ¶
type SpanApplier struct {
// contains filtered or unexported fields
}
SpanApplier is an Operation that can apply updated Spans. This can only change how text is _displayed_, not how it is _saved_. The Edit operation is provided for changing the text that will be saved to disk.
func (*SpanApplier) Empty ¶
func (a *SpanApplier) Empty(context.Context) input.HookedOperation
Empty implements input.HookedOperation
func (*SpanApplier) Name ¶
func (a *SpanApplier) Name(context.Context) string
Name returns a's name.
func (*SpanApplier) Type ¶
func (a *SpanApplier) Type(input.Operation)
Type implements input.Operation
type SpanUpdater ¶
SpanUpdater is the type that a SpanApplier needs an input.Binder to implement in order to work.
type SpansChangingHook ¶
type SpansChangingHook interface { input.Hook // SpansChanging will be called with the spans that are about to be drawn. SpansChanging(context.Context, input.Binder, ...ui.Span) []ui.Span }
SpansChangingHook is a type of hook that needs to adjust spans before they are drawn in the UI. This may be used (for example) to adjust syntax highlighting before the text is drawn.
Note that this blocks user input from being drawn, so more resource-intensive work (e.g. parsing code) should be moved to a separate hook, like TextChanged.
type TextChangedHook ¶
type TextChangedHook interface { input.Hook // TextChanged is called for every input.Edit. If text is changing rapidly, // TextChanged may be called multiple times before calling Op. // // Note that input.LineEdit types are converted when they are applied, so // these notifications include converted input.LineEdits. // // Each edit is paired with the state of the text before the edit was // applied, so that any extra context can be checked against that state. // This allows converting character positions to line/column positions using // the state of the text when the edit was applied, for example. TextChanged(context.Context, input.Binder, ...struct { Before text.State Edit input.Edit }) // TextChangedOp is called during a pause in input. It should return an operation to // execute, or nil if nothing is needed. // // Remember that MultiOperation exists to apply multiple operations. TextChangedOp(context.Context, input.Binder) input.Operation }
TextChangedHook is a type of hook that is notified after text has changed.
type TextChangingHook ¶
type TextChangingHook interface { input.Hook // TextChanging is called for all of the input.Edit values that are about to // be applied. The returned slice of input.Edit values will be used instead. // If no changes are needed, return the original slice. // // It is important to note that the At value in the original edits is // dependent on any previous edits, so if TextChanging changes the length of // any text, it must apply an offset to all later At values. // // Since this blocks user input from being displayed, hooks that implement // it should be performant. TextChanging(context.Context, input.Binder, ...input.Edit) []input.Edit // LineTextChanging is like TextChanging but for input.LineEdit types - // usually returned by a language server. LineTextChanging(context.Context, input.Binder, ...input.LineEdit) []input.LineEdit }
TextChangingHook is a type of hook that needs to be notified of text changes while they are being processed. This means that these hooks will block user input from being displayed, so they should be performant.
NOTE: edits are passed in the order that they will be applied. This means that the `At` field of an edit will take into account the changes caused by all previous edits in a single TextChanging call.
So for example:
TextChanging(b, input.Edit{At: 0, Len: 0, New: []rune{"foo"}}, input.Edit{At: 3, Len: 0, New: []rune("bar")}, )
That means that the resulting text is one single block of "foobar", because position 3 is taking into account the three characters ("foo") from the previous edit.
type TextContainer ¶
type TextContainer interface { input.Binder State(context.Context) text.State RawText(context.Context) *internal.PieceTable Selections(context.Context) (caret.Selection, []caret.Selection) }
TextContainer is the input.Binder type that is needed by edit operations.
type TextJustChangedHook ¶
type TextJustChangedHook interface { input.Hook // TextJustChanged is called for every input.Edit. This is identical to the // TextChangedHook, except that there is no Op to execute when input slows. TextJustChanged(context.Context, input.Binder, ...struct { Before text.State Edit input.Edit }) }
TextJustChangedHook is a type of hook that needs to be notified of text changes immediately after they are applied. Unlike the TextChangedHook, this hook blocks user input until the hook is done, so it should perform as little work as possible.
If a TextJustChangedHook is performing resource-intensive work, it is preferred to move the resource intensive work to a TextChangedHook method. A hook may implement both types.
type TextMetadata ¶ added in v0.6.3
type TextMetadata struct {
// contains filtered or unexported fields
}
TextMetadata may be passed to functions called by operations in this package to include metadata about text changes. There is no guarantee that it will be available, hence using a context.Context for it.
Callers should always use a local interface to type assert to rather than import this type.
func (TextMetadata) LineChars ¶ added in v0.6.3
func (m TextMetadata) LineChars(_ context.Context, line int) int
type WindowManager ¶
type WindowManager struct {
// contains filtered or unexported fields
}
WindowManager handles the actual creation and destruction of windows. It is the source of truth for the basic values that vidar was started with before the first window was opened, and opens each additional window with the same basic values.
func NewWindowManager ¶
func NewWindowManager(creator ui.Creator) *WindowManager
NewWindowManager creates a WindowManager operation using creator. When executed, it will create a new window that it associates with itself.
The returned function should be called after all actions have been constructed, to inform the WindowManager about the base Action types registered with vidar.
func (*WindowManager) CloseWindow ¶
func (m *WindowManager) CloseWindow() input.Operation
Close returns a copy of m that can be used to close the window that m is bound to.
func (*WindowManager) Empty ¶
func (m *WindowManager) Empty(context.Context) input.HookedOperation
Empty implements HookedOperation
func (*WindowManager) Name ¶
func (m *WindowManager) Name(context.Context) string
Name implements input.Action
func (*WindowManager) OpenWindow ¶
func (m *WindowManager) OpenWindow() input.Operation
Open returns a copy of m that can be used to open a new window.
func (*WindowManager) Run ¶
Run performs the action that m is prepped for. When opening a new window, Run will create a copy of m that contains a reference to the new window, so that Close can be used to close the window.
func (*WindowManager) SetActions ¶
func (m *WindowManager) SetActions(_ context.Context, a []internal.Action)
SetActions stores the set of actions that c will use when opening new windows. It should be called after all actions have been loaded from all sources.
func (*WindowManager) Type ¶
func (m *WindowManager) Type(input.Operation)
Type implements input.Operation