op

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

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

View Source
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 Actions

func Actions(ctx context.Context, c ui.Creator) []input.Action

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.

func NewFocus

func NewFocus() input.Operation

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 NewEdit

func NewEdit() *Edit

NewEdit returns a new Edit operation.

func (*Edit) Apply

func (e *Edit) Apply(edit []rune) input.Operation

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

func (e *Edit) ApplyEdit(edits ...input.Edit) input.Operation

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

func (e *Edit) ApplyLineEdit(edits ...input.LineEdit) input.Operation

ApplyLineEdit returns a copy of e which will directly apply LineEdits, ignoring selections.

func (*Edit) Delete

func (e *Edit) Delete(n int) input.Operation

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

Empty returns a new, empty *Edit.

func (*Edit) Name

func (e *Edit) Name(context.Context) string

Name implements input.Operation.

func (*Edit) Restore

func (e *Edit) Restore(state text.State) input.Operation

Restore restores a previously created state to the editor.

func (*Edit) Run

func (e *Edit) Run(ctx context.Context, b input.Binder) error

Run runs the prepped changes in a. If no changes are prepped, nothing will happen.

func (*Edit) SetHook

func (e *Edit) SetHook(ctx context.Context, h input.Hook) error

SetHook sets a hook on e.

func (*Edit) Type

func (e *Edit) Type(input.Operation)

Type implements input.Operation.

func (*Edit) Valid

func (e *Edit) Valid(_ context.Context, b input.Binder) error

Valid ensures that Edit is only bound to types which can be edited.

type EditSpanApplier

type EditSpanApplier interface {
	input.Operation
	WithSpans(...ui.Span) input.Operation
}

EditSpanApplier represents the action that the Edit op needs in order to display changed text to the user.

type FileClosedHook

type FileClosedHook interface {
	input.Hook
	FileClosed(context.Context, input.Binder)
}

FileClosedHook is a hook that needs to be called after a file is closed.

type FileClosingHook

type FileClosingHook interface {
	input.Hook
	FileClosing(context.Context, input.Binder) error
}

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) After

func (m *FileManager) After(callback func(context.Context, input.Binder) error) input.Operation

func (*FileManager) CloseFile

func (m *FileManager) CloseFile() input.Operation

func (*FileManager) Empty

Empty implements HookedOperation

func (*FileManager) FileBinder

func (m *FileManager) FileBinder(ctx context.Context, path string) (input.Binder, error)

func (*FileManager) Name

func (m *FileManager) Name(context.Context) string

func (*FileManager) OpenFile

func (m *FileManager) OpenFile(name, path string) input.Operation

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) Run

func (m *FileManager) Run(ctx context.Context, b input.Binder) (retErr error)

func (*FileManager) SaveFile

func (m *FileManager) SaveFile() input.Operation

func (*FileManager) SetHook

func (m *FileManager) SetHook(_ context.Context, h input.Hook) error

func (*FileManager) Type

func (m *FileManager) Type(input.Operation)

func (*FileManager) Valid

func (m *FileManager) Valid(_ context.Context, b input.Binder) error

type FileOpenedHook

type FileOpenedHook interface {
	input.Hook
	FileOpened(context.Context, input.Binder)
}

FileOpenedHook is a hook that needs to be called after a file is opened.

type FileSavedHook

type FileSavedHook interface {
	input.Hook
	FileSaved(context.Context, input.Binder)
}

FileSavedHook is a hook that needs to be called after a file is saved.

type FileSavingHook

type FileSavingHook interface {
	input.Hook
	FileSaving(context.Context, input.Binder) error
}

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.

func (Focus) Focus

func (f Focus) Focus(b input.Binder) input.Operation

func (Focus) Name

func (f Focus) Name(context.Context) string

func (Focus) Run

func (f Focus) Run(ctx context.Context, b input.Binder) error

func (Focus) Type

func (f Focus) Type(input.Operation)

func (Focus) Valid

func (f Focus) Valid(_ context.Context, b input.Binder) error

type Focuser

type Focuser interface {
	Focus(input.Binder) input.Operation
}

type History

type History struct {
}

type InfoAccessor

type InfoAccessor interface {
	input.Action
	WithBox(*internal.InfoBox) input.Action
}

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.

func NewInform

func NewInform() *Inform

func (*Inform) Box

func (i *Inform) Box() input.Binder

Box may be used to retrieve the info box. This is mainly for asynchronous actions that need to display information to the user, but may continue to run past when the binder they originally spawned with would be closed.

func (*Inform) Error

func (i *Inform) Error(v string) input.Operation

func (*Inform) Info

func (i *Inform) Info(v string) input.Operation

func (*Inform) Name

func (i *Inform) Name(context.Context) string

func (*Inform) Run

func (i *Inform) Run(ctx context.Context, b input.Binder) error

func (*Inform) Type

func (i *Inform) Type(input.Operation)

func (*Inform) Warn

func (i *Inform) Warn(v string) input.Operation

func (*Inform) WithBox

func (i *Inform) WithBox(b *internal.InfoBox) input.Action

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

func NewLoader

func NewLoader(creator ui.Creator) *Loader

func (*Loader) Add

func (l *Loader) Add(b input.Binder) input.Operation

func (*Loader) Name

func (l *Loader) Name(context.Context) string

func (*Loader) Remove

func (l *Loader) Remove(b input.Binder) input.Operation

func (*Loader) RemoveChild

func (l *Loader) RemoveChild() input.Operation

func (*Loader) Run

func (l *Loader) Run(ctx context.Context, b input.Binder) error

func (*Loader) Type

func (l *Loader) Type(input.Operation)

func (*Loader) Valid

func (l *Loader) Valid(_ context.Context, b input.Binder) error

func (*Loader) WithPlaceholder

func (l *Loader) WithPlaceholder(p *internal.Placeholder) input.Action

type Multi

type Multi interface {
	For(...input.Operation) input.Operation
}

Multi represents the builtin/multi.Op

type Namer

type Namer interface {
	input.Binder
	Name(context.Context) string
}

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

type NewWindowHook interface {
	WindowOpened(context.Context, input.Binder)
}

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 NewPrompt

func NewPrompt() *Prompt

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

func (p *Prompt) Caller(act input.Action) input.Operation

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

func (p *Prompt) Extra(lines ...[]ui.Span) input.Operation

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

func (p *Prompt) Input(text string) input.Operation

Input is used to set the input text, e.g. for providing a default or applying suggestions/completions.

func (*Prompt) Name

func (p *Prompt) Name(context.Context) string

func (*Prompt) Prompt

func (p *Prompt) Prompt(spans ...ui.Span) input.Operation

Prompt is used to set the text prompting the user for information.

func (*Prompt) Run

func (p *Prompt) Run(ctx context.Context, b input.Binder) error

func (*Prompt) Type

func (p *Prompt) Type(input.Operation)

func (*Prompt) WithBox

func (p *Prompt) WithBox(b *internal.InfoBox) input.Action

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

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

func (*PromptCallback) Valid

Valid returns nil only if b is a *internal.InfoBox.

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

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

func (h *PromptInputHook) TextChangedOp(ctx context.Context, b input.Binder) input.Operation

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.

func (*PromptInputHook) Valid

func (h *PromptInputHook) Valid(ctx context.Context, b input.Binder) error

Valid returns nil when b.Bound().Named("prompt-callback") returns non-nil.

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

func (p *RawPrompt) Caller(ctx context.Context, b input.Binder) input.Action

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) Name

func (p *RawPrompt) Name(context.Context) string

func (*RawPrompt) ReturnBinder

func (p *RawPrompt) ReturnBinder(b input.Binder) input.Operation

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.

func (*RawPrompt) Run

func (p *RawPrompt) Run(ctx context.Context, b input.Binder) error

func (*RawPrompt) Type

func (p *RawPrompt) Type(input.Operation)

func (*RawPrompt) Valid

func (p *RawPrompt) Valid(_ context.Context, b input.Binder) error

type Scroll

type Scroll struct {
	// contains filtered or unexported fields
}

func NewScroll

func NewScroll() *Scroll

func (*Scroll) Name

func (s *Scroll) Name(context.Context) string

func (*Scroll) Run

func (s *Scroll) Run(ctx context.Context, b input.Binder) error

func (*Scroll) ScrollPos

func (s *Scroll) ScrollPos(pos int) input.Operation

func (*Scroll) ScrollType

func (s *Scroll) ScrollType(typ ui.ScrollType) input.Operation

func (*Scroll) Type

func (s *Scroll) Type(input.Operation)

func (*Scroll) Valid

func (s *Scroll) Valid(_ context.Context, b input.Binder) error

type ScrollOnMoveHook

type ScrollOnMoveHook struct{}

func NewScrollOnMove

func NewScrollOnMove() *ScrollOnMoveHook

func (*ScrollOnMoveHook) Name

func (*ScrollOnMoveHook) OpNames

func (s *ScrollOnMoveHook) OpNames(context.Context) []string

func (*ScrollOnMoveHook) SelectionsChanged

func (s *ScrollOnMoveHook) SelectionsChanged(ctx context.Context, b input.Binder,
	oldPri caret.Selection, _ []caret.Selection,
	newPri caret.Selection, _ []caret.Selection,
) input.Operation

func (*ScrollOnMoveHook) Type

func (s *ScrollOnMoveHook) Type(input.Hook)

type ScrollOp

type ScrollOp interface {
	input.Operation
	ScrollType(ui.ScrollType) input.Operation
	ScrollPos(int) input.Operation
}

type Scrollable

type Scrollable interface {
	input.Binder
	ScrollPos(context.Context, ui.ScrollType, internal.Selection) error
}

type SelManager added in v0.6.3

type SelManager interface {
	Select(caret.Selection, ...caret.Selection) input.Operation
}

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 (*SelectionManager) Name

func (*SelectionManager) Run

func (*SelectionManager) Select

func (m *SelectionManager) Select(primary caret.Selection, secondary ...caret.Selection) input.Operation

func (*SelectionManager) SetHook

func (m *SelectionManager) SetHook(_ context.Context, h input.Hook) error

func (*SelectionManager) Type

func (m *SelectionManager) Type(input.Operation)

func (*SelectionManager) Valid

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 Selector

type Selector interface {
	input.Binder
	Selections(context.Context) (caret.Selection, []caret.Selection)
	SetSelections(context.Context, internal.Selection, ...internal.Selection)
}

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 NewSpanApplier

func NewSpanApplier() *SpanApplier

NewSpanApplier returns a new SpanApplier.

func (*SpanApplier) Empty

Empty implements input.HookedOperation

func (*SpanApplier) Name

func (a *SpanApplier) Name(context.Context) string

Name returns a's name.

func (*SpanApplier) Run

func (a *SpanApplier) Run(ctx context.Context, b input.Binder) error

func (*SpanApplier) SetHook

func (a *SpanApplier) SetHook(_ context.Context, h input.Hook) error

SetHook implements input.HookedOperation

func (*SpanApplier) Type

func (a *SpanApplier) Type(input.Operation)

Type implements input.Operation

func (*SpanApplier) Valid

func (a *SpanApplier) Valid(_ context.Context, b input.Binder) error

Valid checks that b implements ScanUpdater.

func (*SpanApplier) WithSpans

func (a *SpanApplier) WithSpans(spans ...ui.Span) input.Operation

WithSpans is a method only usable by core operations, used to tell a about changes to text.

type SpanUpdater

type SpanUpdater interface {
	input.Binder
	UpdateSpans(context.Context, ...internal.Span)
}

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

func (TextMetadata) LineTabs added in v0.6.3

func (m TextMetadata) LineTabs(_ context.Context, line int) int

func (TextMetadata) Lines added in v0.6.3

func (m TextMetadata) Lines(context.Context) 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

Empty implements HookedOperation

func (*WindowManager) Name

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

func (m *WindowManager) Run(ctx context.Context, b input.Binder) error

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) SetHook

func (m *WindowManager) SetHook(_ context.Context, h input.Hook) error

SetHook implements input.HookedOperation.

func (*WindowManager) Type

func (m *WindowManager) Type(input.Operation)

Type implements input.Operation

func (*WindowManager) Valid

func (m *WindowManager) Valid(_ context.Context, b input.Binder) error

Valid implements PickyAction, ensuring this type is only bound to a window (or to an empty binder).

Jump to

Keyboard shortcuts

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