inlineedit

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package inlineedit owns the shared lifecycle of an inline tmux-PTY editor hosted inside a pane: session start bookkeeping, activation-epoch guards, stale-start cleanup, mouse/cursor coordinate translation, and the save/discard/cancel exit confirmation.

The package is deliberately host-agnostic. It never measures the host's layout: the host supplies its editor viewport and screen origin through the Host contract, so dimension drift is a host bug rather than a mirrored calculation inside here. It also never consults feature flags — gating inline edit is a host concern (filebrowser gates on features.TmuxInlineEdit; notes deliberately does not).

Index

Constants

This section is empty.

Variables

View Source
var ExitConfirmOptions = []string{"Save & Exit", "Exit without saving", "Cancel"}

ExitConfirmOptions are the choices offered before leaving a live session.

Functions

func Start

func Start(opts StartOptions) tea.Cmd

Start launches a tmux editor session for a pane leaf. It reports failures as toasts rather than errors: there is nowhere else in a pane to say them.

Types

type ExitedMsg

type ExitedMsg struct {
	Surface    string
	LeafID     int
	Path       string
	Activation uint64
	Epoch      uint64
}

ExitedMsg reports that a pane's editor session ended.

type Host

type Host interface {
	// EditorViewport reports the content cells available to the PTY.
	EditorViewport() (width, height int)
	// EditorOrigin reports the top-left cell of that content area in
	// host-local coordinates. ok is false when the host has no usable rect.
	EditorOrigin() (x, y int, ok bool)
}

Host is the contract a pane implements to host an inline editor.

type Outcome

type Outcome int

Outcome is what the exit confirmation decided.

const (
	// OutcomePending means the key moved the selection or was swallowed.
	OutcomePending Outcome = iota
	// OutcomeSave writes the buffer and leaves.
	OutcomeSave
	// OutcomeDiscard leaves without writing.
	OutcomeDiscard
	// OutcomeCancel returns to the editor.
	OutcomeCancel
)

type Session

type Session struct {
	Model *tty.Model
	Host  Host

	// Redraw, when set, is batched after operations that change the editor's
	// geometry so a host that caches its render can invalidate it.
	Redraw func() tea.Cmd

	Active     bool   // an inline edit session is current
	Name       string // tmux session name
	Path       string // file being edited
	EditorCmd  string // editor command (vim, nano, ...)
	Activation uint64 // scopes async start/exit messages
	Dragging   bool   // mouse drag in progress inside the editor

	ShowExitConfirm    bool
	ConfirmSelection   int // 0=Save&Exit, 1=Exit without saving, 2=Cancel
	PendingClickRegion string
	PendingClickData   interface{}
}

Session holds the state shared by every inline-editor host.

func New

func New(host Host, config *tty.Config) *Session

New builds a session bound to host with a fresh tty model.

func (*Session) Begin

func (s *Session) Begin(name, editorCmd, path string) tea.Cmd

Begin records a freshly started tmux editor session and opens the tty model at the host's viewport.

func (*Session) CleanupStale

func (s *Session) CleanupStale(name, editorCmd string) tea.Cmd

CleanupStale kills the tmux session named by a stale start message, unless that name is the one the live model is currently driving (tmux reuses names).

func (*Session) ClearPendingClick

func (s *Session) ClearPendingClick()

ClearPendingClick drops the click that triggered an exit confirmation.

func (*Session) Cursor

func (s *Session) Cursor(hostWidth, hostHeight int) *tea.Cursor

Cursor exposes the editor's native cursor in host-local coordinates, clamped to the host rect.

func (*Session) EditingHeader

func (s *Session) EditingHeader(title string) string

EditingHeader renders the "Editing: <name>" header line with the exit hint and, when the tmux pane is larger than the viewport, the size indicator.

func (*Session) Exit

func (s *Session) Exit()

Exit kills the tmux session and resets state.

func (*Session) ForwardMouseDrag

func (s *Session) ForwardMouseDrag(col, row int) tea.Cmd

ForwardMouseDrag sends a drag/motion at 1-indexed editor coordinates.

func (*Session) ForwardMousePress

func (s *Session) ForwardMousePress(col, row int) tea.Cmd

ForwardMousePress sends a press at 1-indexed editor coordinates.

func (*Session) ForwardMouseRelease

func (s *Session) ForwardMouseRelease(col, row int) tea.Cmd

ForwardMouseRelease sends a release at 1-indexed editor coordinates.

func (*Session) HandleConfirmKey

func (s *Session) HandleConfirmKey(key string) (outcome Outcome, handled bool)

HandleConfirmKey drives the exit confirmation and reports what it decided. handled is false for keys the dialog does not own, so a host can swallow them itself rather than let them reach the surface behind a modal.

func (*Session) IsAlive

func (s *Session) IsAlive() bool

IsAlive reports whether the tmux session still exists.

func (*Session) IsModelActive

func (s *Session) IsModelActive() bool

IsModelActive reports whether the underlying tty model is attached.

func (*Session) MouseCoords

func (s *Session) MouseCoords(x, y int) (col, row int, ok bool)

MouseCoords converts host-local screen coordinates to 1-indexed editor coordinates for the SGR mouse protocol. ok is false outside the content area.

func (*Session) MoveConfirmSelection

func (s *Session) MoveConfirmSelection(delta int)

MoveConfirmSelection moves the exit-confirmation cursor by delta, wrapping.

func (*Session) NativeActive

func (s *Session) NativeActive() bool

NativeActive reports whether the embedded terminal owns input right now. Hosts AND this with their own conditions (focus, pane, modals).

func (*Session) NextActivation

func (s *Session) NextActivation() uint64

NextActivation bumps and returns the activation counter.

func (*Session) OwnsMessage

func (s *Session) OwnsMessage(activation, epoch, currentEpoch uint64) bool

OwnsMessage reports whether an async message belongs to the live session.

func (*Session) PreferredMouseMode

func (s *Session) PreferredMouseMode(native bool) tea.MouseMode

PreferredMouseMode returns the terminal's preferred mouse mode when native is true, and all-motion hover otherwise.

func (*Session) RenderExitConfirm

func (s *Session) RenderExitConfirm() string

RenderExitConfirm renders the save/discard/cancel dialog body.

func (*Session) Reopen

func (s *Session) Reopen() tea.Cmd

Reopen re-attaches the tty model to the session already recorded here, used when a host returns to a pane/tab that was left in edit mode.

func (*Session) Reset

func (s *Session) Reset()

Reset clears session-scoped state and closes the tty model without killing the tmux session. Callers that own the session should use Exit.

func (*Session) ResizeToViewport

func (s *Session) ResizeToViewport() tea.Cmd

ResizeToViewport re-sizes the PTY to the host's current viewport.

func (*Session) Route

func (s *Session) Route(m tea.Msg) (cmd tea.Cmd, alive bool)

Route hands one message to the live tty model and reports whether the session is still attached afterwards. A host that gets alive=false owes its own exit bookkeeping — the editor quit on its own.

func (*Session) SaveAndQuit

func (s *Session) SaveAndQuit()

SaveAndQuit asks the editor to write and quit.

func (*Session) SetPendingClick

func (s *Session) SetPendingClick(region string, data interface{})

SetPendingClick records the click to replay once the editor exits.

func (*Session) SizeIndicator

func (s *Session) SizeIndicator() string

SizeIndicator reports what part of a larger tmux pane is hidden, if any.

func (*Session) TakePendingClick

func (s *Session) TakePendingClick() (string, interface{})

TakePendingClick returns and clears the pending click.

func (*Session) Target

func (s *Session) Target() tty.EditorSession

Target describes the tmux session backing this editor.

func (*Session) Viewport

func (s *Session) Viewport() (width, height int)

Viewport returns the host's editor viewport, or zeros without a host.

type StartOptions

type StartOptions struct {
	Surface       string
	LeafID        int
	AbsPath       string // file handed to the editor
	Path          string // path echoed back in StartedMsg
	Line          int    // 1-indexed; 0 leaves the editor at the top
	Width, Height int
	Activation    uint64
	Epoch         uint64
}

StartOptions is what a pane host must say to open an editor: which file, at what size, on behalf of which leaf.

type StartedMsg

type StartedMsg struct {
	Surface     string
	LeafID      int
	SessionName string
	Editor      string
	Path        string // the path the host knows the document by
	Activation  uint64
	Epoch       uint64
}

StartedMsg reports a tmux editor session started for a pane leaf. Surface distinguishes the two workspace projections, which both see every message.

Jump to

Keyboard shortcuts

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