editor

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package editor is the in-TUI ADF-native rich-text editor. The internal buffer is the typed adf.Document, not a Markdown string. Markdown-style key shortcuts mutate the document in place — there is no convert-on-submit step.

Opaque blocks (unknown ADF nodes preserved on parse) are treated as protected: they render but cannot be edited or deleted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Editor

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

Editor is the public ADF editor model. The Bubble Tea model wraps it.

func New

func New(opts Options) *Editor

New constructs an editor with an optional initial document.

func (*Editor) ApplyMarkToCurrentParagraphRange

func (e *Editor) ApplyMarkToCurrentParagraphRange(start, end int, markType string) bool

ApplyMarkToCurrentParagraphRange applies markType to the rune range [start, end) of the current paragraph's flat text content. Existing marks on adjacent runs are preserved — text nodes are split at the range boundaries so the affected run carries exactly the new mark (in addition to whatever marks it already had) and nothing else changes.

Returns false when the caret is not on a text-bearing block, or when [start, end) is empty / out of bounds. Idempotent on a range already carrying the same mark.

Used by the TUI's Markdown-style shortcut layer to apply strong/em/code/strike marks to a precise span without rebuilding the document and losing earlier marks.

func (*Editor) CurrentParagraphLen

func (e *Editor) CurrentParagraphLen() int

CurrentParagraphLen returns the rune length of all text in the current paragraph — used by the form to map between visible buffer length and editor offsets when applying range marks.

func (*Editor) DeleteCurrentBlock

func (e *Editor) DeleteCurrentBlock() bool

DeleteCurrentBlock removes the caret's block, EXCEPT when it is an opaque (protected) block. Returns true if anything was deleted.

func (*Editor) DeleteLastRune

func (e *Editor) DeleteLastRune() bool

DeleteLastRune removes the trailing rune from the current paragraph without disturbing marks on the remaining text. If the trailing run becomes empty, the empty text node is removed. Returns false when the paragraph is already empty.

Used by the TUI form's keystroke mirror so backspace doesn't have to rebuild the editor (which would destroy mark history).

func (*Editor) Document

func (e *Editor) Document() adf.Document

Document returns a snapshot of the typed ADF doc.

func (*Editor) HandleShortcut

func (e *Editor) HandleShortcut(token string)

HandleShortcut applies a Markdown-style shortcut to the editor state. The supported shortcuts are the documented Markdown shortcuts plus the few inline marks the tests exercise; the full MVP set lives behind individual helper methods invoked from the Bubble Tea key handler.

func (*Editor) InsertText

func (e *Editor) InsertText(s string)

InsertText appends text to the current block. If the current block is not a text-bearing paragraph/heading, a new paragraph is appended.

func (*Editor) IsAtOpaqueBlock

func (e *Editor) IsAtOpaqueBlock() bool

IsAtOpaqueBlock reports whether the caret currently sits on a block the editor cannot edit (an unknown ADF node preserved by Parse).

func (*Editor) MoveTo

func (e *Editor) MoveTo(p Position)

MoveTo updates the caret position. Bounds are not strictly enforced here; the renderer clamps when rendering.

func (*Editor) SelectAll

func (e *Editor) SelectAll()

SelectAll selects every text node in the current block. Future versions will model selection as a (Position, Position) range; for now this flag is enough to test the strong/em shortcut path.

type Options

type Options struct {
	// Initial document; if zero, a fresh empty doc with one paragraph is
	// created.
	Initial adf.Document
}

Options configure a new editor.

type Position

type Position struct {
	Block  int // index into Document.Content
	Offset int // rune offset within the current block
}

Position describes a caret position inside the document.

Jump to

Keyboard shortcuts

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