editor

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package editor implements the mdit inline-render editor widget: a bubbletea component that shows a markdown document with every block rendered in place, except the block under the cursor, which is shown as raw source so it can be edited. The layout is virtualized (only the visible screen slice is drawn) and rendered blocks are cached by content, so a keystroke re-renders at most the one block it touched.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutocompleteMsg

type AutocompleteMsg struct{ Query string }

AutocompleteMsg is emitted (via a tea.Cmd) right after the user types the second '[' of a "[[" so the UI can open the note-completion popup.

type FollowLinkMsg

type FollowLinkMsg struct{ Target string }

FollowLinkMsg is emitted (via a tea.Cmd) when the user presses Ctrl+O (or Ctrl+]) on a [[wikilink]] or [label](dest) under the cursor. The App resolves vault targets and shows external URLs on the status bar.

type Model

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

Model is the editor widget. The zero value is not usable; construct one with New.

func New

func New(d *doc.Document, th theme.Theme, isBroken func(string) bool) Model

New constructs an editor Model over d with the given theme and broken-link predicate (isBroken may be nil). Call SetSize before View.

func (Model) Cursor

func (m Model) Cursor() doc.Position

Cursor returns the current cursor position (Col in runes).

func (Model) CursorViewportRowCol

func (m Model) CursorViewportRowCol() (row, col int)

CursorViewportRowCol returns the cursor's position relative to the visible viewport: row in [0, height) and cell column. The UI layer uses it to anchor popups (e.g. wikilink autocomplete) next to the cursor.

func (Model) Doc

func (m Model) Doc() *doc.Document

Doc returns the underlying document.

func (Model) HasSelection added in v0.3.0

func (m Model) HasSelection() bool

HasSelection reports whether a non-empty selection is active.

func (*Model) InsertText

func (m *Model) InsertText(s string)

InsertText inserts s at the cursor (replacing any selection) and rebuilds layout.

func (Model) Register added in v0.3.0

func (m Model) Register() string

Register returns the internal yank/paste buffer.

func (Model) Scroll

func (m Model) Scroll() int

Scroll returns the top screen row of the viewport.

func (Model) SelectedText added in v0.3.0

func (m Model) SelectedText() string

SelectedText returns the document text covered by the selection, or "".

func (Model) Selection added in v0.3.0

func (m Model) Selection() (from, to doc.Position, ok bool)

Selection returns the normalized half-open selection range [from, to). ok is false when there is no active selection (or the range is empty).

func (*Model) SetCursor

func (m *Model) SetCursor(p doc.Position)

SetCursor moves the cursor to p (clamped on next recompute) and rebuilds layout.

func (*Model) SetDoc

func (m *Model) SetDoc(d *doc.Document)

SetDoc swaps the document and resets cursor, scroll, selection, and layout.

func (*Model) SetPlaceholder added in v0.2.0

func (m *Model) SetPlaceholder(s string)

SetPlaceholder sets the dim hint drawn when the document is a single empty line. It does not force a re-layout; View reads it directly.

func (*Model) SetScroll

func (m *Model) SetScroll(s int)

SetScroll sets the viewport scroll offset (clamped).

func (*Model) SetSize

func (m *Model) SetSize(w, h int)

SetSize sets the viewport dimensions and rebuilds the layout.

func (*Model) SetZen

func (m *Model) SetZen(on bool)

SetZen toggles read-only fully-rendered mode (no raw cursor block).

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update handles incoming messages (currently key and window-size messages) and returns the updated model plus any command to run.

func (Model) View

func (m Model) View() string

View renders exactly height screen lines joined by "\n", drawing the cursor by inverting the cell it occupies (raw block) or a focus caret on the mapped row of a lazy-rendered structural block.

func (Model) Zen

func (m Model) Zen() bool

Zen reports whether the editor is in zen (fully rendered) mode.

Jump to

Keyboard shortcuts

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