Documentation
¶
Overview ¶
Package editor provides a Bubble Tea text editor component backed by the buffer package.
The package is responsible for input handling, viewport behavior, grapheme-aware rendering, and host integration hooks (custom gutter, virtual text, highlighting, conditional row/token styling, hyperlink spans, ghost suggestions, completion APIs, and change events).
Index ¶
- func LineNumberWidth(lineCount int) int
- type CompletionAcceptIntentPayload
- type CompletionDismissIntentPayload
- type CompletionFilter
- type CompletionFilterContext
- type CompletionFilterResult
- type CompletionInputMode
- type CompletionIntent
- type CompletionIntentBatch
- type CompletionIntentKind
- type CompletionItem
- type CompletionKeyMap
- type CompletionNavigateIntentPayload
- type CompletionQueryIntentPayload
- type CompletionSegment
- type CompletionState
- type CompletionTriggerIntentPayload
- type Config
- type DeleteDirection
- type DeleteIntentPayload
- type EditorState
- type Ghost
- type GhostAccept
- type GhostContext
- type GhostProvider
- type Gutter
- type GutterCell
- type GutterCellContext
- type GutterSegment
- type GutterWidthContext
- type HighlightSpan
- type Highlighter
- type InsertIntentPayload
- type Intent
- type IntentBatch
- type IntentDecision
- type IntentKind
- type KeyMap
- type LineContext
- type LinkContext
- type LinkHit
- type LinkProvider
- type LinkSpan
- type Model
- func (m Model) Blur() Model
- func (m Model) Buffer() *buffer.Buffer
- func (m Model) ClearCompletion() Model
- func (m Model) CompletionState() CompletionState
- func (m Model) DocToScreen(pos buffer.Pos) (x int, y int, ok bool)
- func (m Model) DocToScreenWithSnapshot(s RenderSnapshot, pos buffer.Pos) (x int, y int, ok bool)
- func (m Model) Focus() Model
- func (m Model) Focused() bool
- func (m Model) Init() tea.Cmd
- func (m Model) InvalidateGutter() Model
- func (m Model) InvalidateGutterRows(rows ...int) Model
- func (m Model) InvalidateStyles() Model
- func (m Model) LinkAt(pos buffer.Pos) (LinkHit, bool)
- func (m Model) LinkAtScreen(x, y int) (LinkHit, bool)
- func (m Model) RenderSnapshot() RenderSnapshot
- func (m Model) ScreenToDoc(x, y int) buffer.Pos
- func (m Model) ScreenToDocWithSnapshot(s RenderSnapshot, x, y int) (buffer.Pos, bool)
- func (m Model) SetCompletionState(state CompletionState) Model
- func (m Model) SetSize(width, height int) Model
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) View() tea.View
- func (m Model) ViewportState() ViewportState
- type MoveIntentPayload
- type MutationMode
- type RedoIntentPayload
- type RenderSnapshot
- type RowMap
- type RowMarkContext
- type RowMarkProvider
- type RowMarkState
- type RowMarkSymbols
- type RowStyleContext
- type ScrollPolicy
- type ScrollbarConfig
- type ScrollbarMode
- type SelectIntentPayload
- type SnapshotToken
- type Style
- type TokenStyleContext
- type UndoIntentPayload
- type ViewportState
- type VirtualDeletion
- type VirtualInsertion
- type VirtualRole
- type VirtualText
- type VirtualTextContext
- type VirtualTextProvider
- type VisualLine
- type VisualToken
- type VisualTokenKind
- type WrapMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LineNumberWidth ¶
LineNumberWidth returns the default line-number gutter width for lineCount.
Types ¶
type CompletionDismissIntentPayload ¶
type CompletionDismissIntentPayload struct{}
type CompletionFilter ¶
type CompletionFilter func(CompletionFilterContext) CompletionFilterResult
type CompletionFilterContext ¶
type CompletionFilterResult ¶
type CompletionInputMode ¶
type CompletionInputMode uint8
const ( CompletionInputQueryOnly CompletionInputMode = iota CompletionInputMutateDocument )
type CompletionIntent ¶
type CompletionIntent struct {
Kind CompletionIntentKind
Before EditorState
Payload any
}
type CompletionIntentBatch ¶
type CompletionIntentBatch struct {
Intents []CompletionIntent
}
type CompletionIntentKind ¶
type CompletionIntentKind uint8
const ( IntentCompletionTrigger CompletionIntentKind = iota IntentCompletionAccept IntentCompletionDismiss IntentCompletionQuery )
type CompletionItem ¶
type CompletionItem struct {
ID string
InsertText string
Edits []buffer.TextEdit
Prefix []CompletionSegment
Label []CompletionSegment
Detail []CompletionSegment
StyleKey string
}
type CompletionKeyMap ¶
type CompletionKeyMap struct {
Trigger key.Binding
Accept key.Binding
AcceptTab bool
Dismiss key.Binding
Next key.Binding
Prev key.Binding
PageNext key.Binding
PagePrev key.Binding
}
func DefaultCompletionKeyMap ¶
func DefaultCompletionKeyMap() CompletionKeyMap
type CompletionNavigateIntentPayload ¶
type CompletionNavigateIntentPayload struct {
}
type CompletionQueryIntentPayload ¶
type CompletionQueryIntentPayload struct {
Query string
}
type CompletionSegment ¶
type CompletionState ¶
type Config ¶
type Config struct {
// Initial text for the internal buffer.
Text string
// Optional host metadata used by hooks for caching.
DocID string
// Rendering options.
Gutter Gutter
// RowMarkProvider optionally supplies inserted/updated/deleted markers for a row.
// Returned marks are rendered in a dedicated marker lane in the gutter area.
RowMarkProvider RowMarkProvider
// RowMarkWidth controls marker lane width in terminal cells.
// When RowMarkProvider is set and width <= 0, it defaults to 2.
RowMarkWidth int
// RowMarkSymbols controls default glyphs used for row markers.
// Empty fields are normalized to defaults.
RowMarkSymbols RowMarkSymbols
Style Style
// GutterStyleForKey resolves a gutter segment style override by key.
// When nil or key is unresolved, Style.Gutter is used.
//
// Returned styles should avoid layout-affecting options (padding/margin/width)
// to keep render mapping deterministic.
GutterStyleForKey func(key string) (lipgloss.Style, bool)
// RowStyleForRow resolves a style override for each rendered visual row.
// When nil or callback returns ok=false, no row-level override is applied.
//
// Row style is applied only to the content area (gutter excluded). Rendered
// output is clamped to one visual line and content width for safety.
RowStyleForRow func(RowStyleContext) (lipgloss.Style, bool)
// TokenStyleForToken resolves a style override for each rendered visual token.
// When nil or callback returns ok=false, no token-level override is applied.
//
// Returned styles should avoid layout-affecting options (padding/margin/width)
// to keep render mapping deterministic.
TokenStyleForToken func(TokenStyleContext) (lipgloss.Style, bool)
// WrapMode controls soft wrapping vs horizontal scrolling. Default is WrapNone.
WrapMode WrapMode
// ScrollPolicy controls whether viewport scrolling can diverge from cursor.
// Default is ScrollAllowManual.
ScrollPolicy ScrollPolicy
// Scrollbar configures editor-owned vertical/horizontal scrollbar behavior.
// Zero value defaults to auto visibility with MinThumb normalized to 1.
Scrollbar ScrollbarConfig
// VirtualTextProvider optionally supplies per-line view-only transforms
// (virtual deletions/insertions) used by the VisualLine mapping layer.
// When nil, the transform is identity.
VirtualTextProvider VirtualTextProvider
// TabWidth controls tab stop width in terminal cells. If <= 0, defaults to 4.
TabWidth int
// If true, movement/selection still work but buffer mutations are ignored.
ReadOnly bool
// KeyMap controls default keybindings. Zero value uses DefaultKeyMap().
KeyMap KeyMap
// Forwarded to buffer.Options.
HistoryLimit int
// Ghost suggestion (inline at cursor column, single-line, non-interactive).
// When nil, ghost is disabled.
GhostProvider GhostProvider
// GhostAccept configures accept keys. Zero value defaults to Tab+Right.
GhostAccept GhostAccept
// GhostStyleForKey resolves a ghost insertion style override by key.
// When nil or key is unresolved, Style.Ghost is used.
//
// Returned styles should avoid layout-affecting options (padding/margin/width)
// to keep render mapping deterministic.
GhostStyleForKey func(key string) (lipgloss.Style, bool)
// VirtualOverlayStyleForKey resolves a virtual overlay style override by key.
// When nil or key is unresolved, Style.VirtualOverlay is used.
//
// Returned styles should avoid layout-affecting options (padding/margin/width)
// to keep render mapping deterministic.
VirtualOverlayStyleForKey func(key string) (lipgloss.Style, bool)
// Highlighter optionally provides per-line highlight spans over the visible
// text after virtual deletions.
Highlighter Highlighter
// LinkProvider optionally provides per-line hyperlink spans over raw line
// text. Link spans are rendered with OSC8 hyperlinks and can be queried via
// LinkAt / LinkAtScreen.
LinkProvider LinkProvider
// OnChange, if set, fires after every effective buffer change triggered via
// Update. It is not fired for host-driven buffer changes.
OnChange func(buffer.Change)
// MutationMode controls whether key handling mutates locally, emits intents,
// or does both. Zero value is MutateInEditor.
MutationMode MutationMode
// OnIntent, if set, receives key-derived semantic intents in intent modes.
// In EmitIntentsAndMutate mode, the return value decides local apply.
OnIntent func(IntentBatch) IntentDecision
// CompletionFilter customizes filtering/ranking of completion items.
// When nil, editor-side default filtering is used in later completion phases.
CompletionFilter CompletionFilter
// CompletionStyleForKey resolves completion row/segment style overrides by key.
// When nil or key is unresolved, completion row defaults are used.
CompletionStyleForKey func(key string) (lipgloss.Style, bool)
// CompletionKeyMap controls completion-specific key bindings.
// Zero value uses DefaultCompletionKeyMap().
CompletionKeyMap CompletionKeyMap
// CompletionInputMode controls typing/backspace behavior while completion is visible.
// Zero value is CompletionInputQueryOnly.
CompletionInputMode CompletionInputMode
// CompletionMaxVisibleRows caps completion popup rows.
// Values <= 0 default to 8.
CompletionMaxVisibleRows int
// CompletionMaxWidth caps completion popup width in terminal cells.
// Values <= 0 default to 60.
CompletionMaxWidth int
// OnCompletionIntent receives completion semantic intents.
// This is separate from document intents emitted by OnIntent.
OnCompletionIntent func(CompletionIntentBatch)
}
Config configures the editor Model.
type DeleteDirection ¶
type DeleteDirection uint8
DeleteDirection identifies requested delete direction semantics.
const ( DeleteBackward DeleteDirection = iota DeleteForward DeleteSelection )
type DeleteIntentPayload ¶
type DeleteIntentPayload struct {
Direction DeleteDirection
}
DeleteIntentPayload describes a delete action.
type EditorState ¶
type EditorState struct {
Version uint64
Cursor buffer.Pos
Selection buffer.SelectionState
}
EditorState captures buffer-local state before an intent is executed.
type GhostAccept ¶
type GhostContext ¶
type GhostProvider ¶
type GhostProvider func(ctx GhostContext) (Ghost, bool)
type Gutter ¶
type Gutter struct {
Width func(ctx GutterWidthContext) int
Cell func(ctx GutterCellContext) GutterCell
}
Gutter configures optional custom gutter rendering and hit-testing.
When Width is nil, gutter rendering is disabled. When Cell is nil, gutter cells render as blanks and clicks map to col 0.
func LineNumberGutter ¶
func LineNumberGutter() Gutter
LineNumberGutter returns the built-in line-number gutter behavior.
type GutterCell ¶
type GutterCell struct {
// Segments contains style-addressable text chunks for this gutter cell.
// Segment text is normalized/clipped/padded to the resolved gutter width.
Segments []GutterSegment
// ClickCol maps gutter clicks to a document grapheme column.
// Negative values are clamped to 0.
ClickCol int
}
type GutterCellContext ¶
type GutterSegment ¶
type GutterSegment struct {
Text string
// StyleKey optionally selects a keyed style via Config.GutterStyleForKey.
// Empty means use Style.Gutter.
StyleKey string
// Style optionally overrides StyleKey for this segment.
// Returned styles should avoid layout-affecting options (padding/margin/width)
// to keep render mapping deterministic.
Style *lipgloss.Style
}
func LineNumberSegment ¶
func LineNumberSegment(ctx GutterCellContext) GutterSegment
LineNumberSegment returns the default line-number segment for one gutter row.
type GutterWidthContext ¶
type HighlightSpan ¶
type Highlighter ¶
type Highlighter interface {
HighlightLine(ctx LineContext) ([]HighlightSpan, error)
}
type InsertIntentPayload ¶
type InsertIntentPayload struct {
Text string
// Edits carries deterministic apply edits for complex insertion sources
// (for example, ghost accepts). For regular typing, this is empty.
Edits []buffer.TextEdit
}
InsertIntentPayload describes an insert action.
type Intent ¶
type Intent struct {
Kind IntentKind
Before EditorState
Payload any
}
Intent is a typed semantic action emitted from key processing.
type IntentBatch ¶
type IntentBatch struct {
Intents []Intent
}
IntentBatch groups intents produced from one input event.
type IntentDecision ¶
type IntentDecision struct {
ApplyLocally bool
}
IntentDecision controls whether the editor applies mutations locally. It is used in EmitIntentsAndMutate mode.
type IntentKind ¶
type IntentKind uint8
IntentKind identifies the semantic action requested by input handling.
const ( IntentInsert IntentKind = iota IntentDelete IntentMove IntentSelect IntentUndo IntentRedo )
type KeyMap ¶
type KeyMap struct {
Left, Right, Up, Down key.Binding
ParagraphUp, ParagraphDown key.Binding
PageUp, PageDown key.Binding
ShiftLeft, ShiftRight, ShiftUp, ShiftDown key.Binding
ParagraphShiftUp, ParagraphShiftDown key.Binding
WordLeft, WordRight key.Binding
WordShiftLeft, WordShiftRight key.Binding
Home, End key.Binding
Backspace, Delete key.Binding
Enter key.Binding
Undo, Redo key.Binding
}
KeyMap defines the editor key bindings.
Bindings must be portable across terminals (ctrl/alt fallbacks).
func DefaultKeyMap ¶
func DefaultKeyMap() KeyMap
type LineContext ¶
type LineContext struct {
Row int
// RawText is the buffer line text (unwrapped) before virtual deletions.
RawText string
// Text is the visible line text (unwrapped) after applying virtual deletions.
Text string
// CursorGraphemeCol is the grapheme index within Text (visible line), if cursor is on this row; otherwise -1.
CursorGraphemeCol int
// RawCursorGraphemeCol is the grapheme index within RawText (buffer line), if cursor is on this row; otherwise -1.
RawCursorGraphemeCol int
HasCursor bool
}
type LinkContext ¶ added in v0.1.2
type LinkContext struct {
Row int
// RawText is the buffer line text (unwrapped) before virtual deletions.
RawText string
// Text is the visible line text (unwrapped) after applying virtual deletions.
Text string
// CursorGraphemeCol is the grapheme index within Text (visible line), if cursor is on this row; otherwise -1.
CursorGraphemeCol int
// RawCursorGraphemeCol is the grapheme index within RawText (buffer line), if cursor is on this row; otherwise -1.
RawCursorGraphemeCol int
HasCursor bool
// Useful for caching.
DocID string
DocVersion uint64
}
LinkContext is passed to LinkProvider for one logical line.
type LinkProvider ¶ added in v0.1.2
type LinkProvider func(ctx LinkContext) ([]LinkSpan, error)
LinkProvider optionally returns hyperlink spans for a visible line.
Spans are line-local and are interpreted in raw grapheme columns. Invalid or overlapping ranges are sanitized deterministically.
type LinkSpan ¶ added in v0.1.2
type LinkSpan struct {
StartGraphemeCol int
EndGraphemeCol int
Target string
Style *lipgloss.Style
}
LinkSpan is a hyperlink span over one raw document line.
StartGraphemeCol and EndGraphemeCol are grapheme indices in RawText, half-open [StartGraphemeCol, EndGraphemeCol).
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is a Bubble Tea component that renders and interacts with a buffer.
func (Model) ClearCompletion ¶
func (Model) CompletionState ¶
func (m Model) CompletionState() CompletionState
func (Model) DocToScreen ¶
DocToScreen maps a document position to viewport-local screen coordinates.
ok is false when the position is outside the visible viewport content.
func (Model) DocToScreenWithSnapshot ¶
func (Model) InvalidateGutter ¶
InvalidateGutter marks gutter rendering as stale for all rows and rebuilds view content. Use this when gutter callbacks depend on host-managed state that changed outside of editor Update flow.
func (Model) InvalidateGutterRows ¶
InvalidateGutterRows marks specific gutter rows as stale and rebuilds view content for those rows. If partial row refresh cannot be applied, it falls back to a full content rebuild.
func (Model) InvalidateStyles ¶ added in v0.1.4
InvalidateStyles marks row/token style callback output as stale and rebuilds rendered content. Use this when style callbacks depend on host-managed state that changed outside editor Update flow.
func (Model) LinkAtScreen ¶ added in v0.1.2
LinkAtScreen returns hyperlink metadata for viewport-local screen coordinates.
func (Model) RenderSnapshot ¶
func (m Model) RenderSnapshot() RenderSnapshot
func (Model) ScreenToDoc ¶
ScreenToDoc maps viewport-local screen coordinates to a document position.
Coordinates use terminal cells relative to the editor viewport.
func (Model) ScreenToDocWithSnapshot ¶
func (Model) SetCompletionState ¶
func (m Model) SetCompletionState(state CompletionState) Model
func (Model) ViewportState ¶
func (m Model) ViewportState() ViewportState
ViewportState returns the current host-facing viewport state.
type MoveIntentPayload ¶
MoveIntentPayload describes a cursor move action.
type MutationMode ¶
type MutationMode uint8
MutationMode controls whether key handling mutates the local buffer, emits intents to the host, or both.
const ( // MutateInEditor keeps current behavior: key handling mutates editor state. MutateInEditor MutationMode = iota // EmitIntentsOnly emits intents and does not apply local mutations. EmitIntentsOnly // EmitIntentsAndMutate emits intents and applies local mutations when the // host decision allows it. EmitIntentsAndMutate )
type RenderSnapshot ¶
type RenderSnapshot struct {
Token SnapshotToken
BufferVersion uint64
Viewport ViewportState
Rows []RowMap
}
type RowMarkContext ¶ added in v0.1.4
type RowMarkContext struct {
Row int
SegmentIndex int
// LineText is raw document line text (unwrapped, before virtual transforms).
LineText string
IsCursorRow bool
Focused bool
DocID string
DocVersion uint64
}
RowMarkContext describes a rendered visual row for marker resolution.
type RowMarkProvider ¶ added in v0.1.4
type RowMarkProvider func(ctx RowMarkContext) RowMarkState
RowMarkProvider resolves inserted/updated/deleted markers for one rendered row.
type RowMarkState ¶ added in v0.1.4
RowMarkState describes change markers to render for a row.
Deleted markers are rendered only on segment index 0. Inserted/Updated markers are rendered on all visual segments of a wrapped row.
type RowMarkSymbols ¶ added in v0.1.4
type RowMarkSymbols struct {
Inserted string // default: "▎"
Updated string // default: "▎"
DeletedAbove string // default: "▼"
DeletedBelow string // default: "▲"
}
RowMarkSymbols configures default marker glyphs.
type RowStyleContext ¶ added in v0.1.4
type RowStyleContext struct {
// Row is the logical document row index.
Row int
// SegmentIndex is the wrapped visual segment index within Row.
SegmentIndex int
// RawText is the unwrapped buffer line text.
RawText string
// Text is the visible line text after virtual deletions.
Text string
// IsActive reports whether Row is the cursor row.
IsActive bool
// IsFocused reports whether the editor is focused.
IsFocused bool
}
RowStyleContext describes a rendered visual row for row-level style overrides.
type ScrollPolicy ¶
type ScrollPolicy int
ScrollPolicy controls how viewport scrolling is allowed to move relative to the cursor.
const ( // ScrollAllowManual allows manual viewport scrolling (for example via mouse // wheel) even when the cursor does not move. ScrollAllowManual ScrollPolicy = iota // ScrollFollowCursorOnly keeps vertical viewport movement cursor-driven. // Manual viewport scrolling is ignored. ScrollFollowCursorOnly )
type ScrollbarConfig ¶ added in v0.1.3
type ScrollbarConfig struct {
Vertical ScrollbarMode
Horizontal ScrollbarMode
// MinThumb is the minimum thumb size in cells. Values <= 0 normalize to 1.
MinThumb int
}
ScrollbarConfig configures editor-owned scrollbar behavior.
type ScrollbarMode ¶ added in v0.1.3
type ScrollbarMode int
ScrollbarMode controls visibility policy for a scrollbar axis.
const ( // ScrollbarAuto shows a scrollbar only when the axis overflows. ScrollbarAuto ScrollbarMode = iota // ScrollbarAlways forces scrollbar visibility even when content fits. ScrollbarAlways // ScrollbarNever disables scrollbar visibility for the axis. ScrollbarNever )
type SelectIntentPayload ¶
SelectIntentPayload describes a selection-extending move action.
type SnapshotToken ¶
type SnapshotToken uint64
type Style ¶
type Style struct {
Gutter lipgloss.Style
// Row marker styles for inserted/updated bars and deleted-row triangles.
RowMarkInserted lipgloss.Style
RowMarkUpdated lipgloss.Style
RowMarkDeleted lipgloss.Style
Text lipgloss.Style
Selection lipgloss.Style
Cursor lipgloss.Style
Link lipgloss.Style
// Scrollbar styles are used for editor-owned scrollbar chrome.
ScrollbarTrack lipgloss.Style
ScrollbarThumb lipgloss.Style
ScrollbarCorner lipgloss.Style
CompletionItem lipgloss.Style
CompletionSelected lipgloss.Style
Ghost lipgloss.Style
VirtualOverlay lipgloss.Style
}
Style controls the editor's rendering.
func DefaultStyle ¶
func DefaultStyle() Style
type TokenStyleContext ¶ added in v0.1.4
type TokenStyleContext struct {
// Row is the logical document row index.
Row int
// SegmentIndex is the wrapped visual segment index within Row.
SegmentIndex int
// Token is the current rendered visual token.
Token VisualToken
// RawText is the unwrapped buffer line text.
RawText string
// Text is the visible line text after virtual deletions.
Text string
// IsActiveRow reports whether Row is the cursor row.
IsActiveRow bool
// IsFocused reports whether the editor is focused.
IsFocused bool
// IsHighlighted reports overlap with highlighter spans.
IsHighlighted bool
// IsLink reports whether link style/target are active for this token.
IsLink bool
// LinkTarget is set when IsLink is true.
LinkTarget string
}
TokenStyleContext describes a rendered visual token for token-level style overrides.
type ViewportState ¶
type ViewportState struct {
// TopVisualRow is the visual row index rendered at viewport screen row 0.
TopVisualRow int
// VisibleRows is the number of content rows available for rendering.
VisibleRows int
// LeftCellOffset is the horizontal cell offset in WrapNone mode.
LeftCellOffset int
// WrapMode is the active wrapping mode used to interpret coordinates.
WrapMode WrapMode
}
ViewportState is a stable host-facing snapshot of editor camera state.
type VirtualDeletion ¶
VirtualDeletion hides a half-open grapheme range [StartGraphemeCol, EndGraphemeCol) within a single logical line.
Columns are grapheme indices in the raw buffer line (before any deletions).
type VirtualInsertion ¶
type VirtualInsertion struct {
GraphemeCol int
Text string
Role VirtualRole
// StyleKey optionally selects a keyed style via config style callbacks.
// Empty means use role default style.
StyleKey string
}
VirtualInsertion inserts view-only text at a grapheme column within a single logical line.
GraphemeCol is a grapheme index in the raw buffer line (before any deletions).
type VirtualRole ¶
type VirtualRole int
const ( VirtualRoleGhost VirtualRole = iota // inline suggestion / completion preview VirtualRoleOverlay // generic inserted text (dim/annotation) )
type VirtualText ¶
type VirtualText struct {
Insertions []VirtualInsertion
Deletions []VirtualDeletion
}
type VirtualTextContext ¶
type VirtualTextContext struct {
Row int
LineText string // raw buffer line text (unwrapped)
// Cursor/selection state for conditional transforms.
CursorGraphemeCol int // grapheme index in raw buffer line
HasCursor bool
SelectionStartGraphemeCol int // grapheme index in raw buffer line
SelectionEndGraphemeCol int // grapheme index in raw buffer line
HasSelection bool
// Useful for caching.
DocID string
DocVersion uint64
}
type VirtualTextProvider ¶
type VirtualTextProvider func(ctx VirtualTextContext) VirtualText
type VisualLine ¶
type VisualLine struct {
RawGraphemeLen int // grapheme length of the raw buffer line
Tokens []VisualToken
// VisualCellToDocGraphemeCol maps each visual cell to a raw document grapheme column.
// For wide graphemes, every cell maps to the same doc column.
// For virtual insertions, every cell maps to the insertion anchor column.
VisualCellToDocGraphemeCol []int
// DocGraphemeColToVisualCell maps raw document grapheme columns to a visual cell offset.
// Deleted doc columns map to the next visible doc column (or EOL if none).
DocGraphemeColToVisualCell []int
}
func BuildVisualLine ¶
func BuildVisualLine(rawLine string, vt VirtualText, tabWidth int) VisualLine
func (VisualLine) DocGraphemeColForVisualCell ¶
func (vl VisualLine) DocGraphemeColForVisualCell(x int) int
func (VisualLine) VisualCellForDocGraphemeCol ¶
func (vl VisualLine) VisualCellForDocGraphemeCol(col int) int
func (VisualLine) VisualLen ¶
func (vl VisualLine) VisualLen() int
type VisualToken ¶
type VisualToken struct {
Kind VisualTokenKind
// Text is the rendered token text. Tabs are expanded to spaces.
Text string
// StartCell is the visual cell offset where this token begins.
StartCell int
// CellWidth is the number of terminal cells this token occupies.
CellWidth int
// VisibleStartGraphemeCol/VisibleEndGraphemeCol define the grapheme span in the visible line text
// (after deletions) that this token corresponds to. Meaningful only for doc tokens.
VisibleStartGraphemeCol int
VisibleEndGraphemeCol int
// DocStartGraphemeCol/DocEndGraphemeCol define the raw document grapheme span this token corresponds to.
// For virtual tokens, DocStartGraphemeCol == DocEndGraphemeCol == AnchorCol.
DocStartGraphemeCol int
DocEndGraphemeCol int
// GraphemeLen is the number of grapheme clusters in Text.
GraphemeLen int
// AllSpaces is true when every grapheme in Text is whitespace.
AllSpaces bool
// Role is meaningful only for virtual tokens.
Role VirtualRole
// StyleKey is meaningful only for virtual tokens.
StyleKey string
}
type VisualTokenKind ¶
type VisualTokenKind int
const ( VisualTokenDoc VisualTokenKind = iota VisualTokenVirtual )
Source Files
¶
- completion.go
- completion_filter.go
- completion_popup_render.go
- completion_style.go
- compositor.go
- config.go
- doc.go
- events.go
- ghost.go
- grapheme.go
- gutter.go
- highlight.go
- hittest.go
- intents.go
- keymap.go
- link.go
- model.go
- render.go
- scroll_policy.go
- scrollbar.go
- snapshot.go
- style.go
- style_hooks.go
- update.go
- update_completion.go
- update_mouse.go
- viewport.go
- viewport_state.go
- virtual_text.go
- visual_line.go
- wrap.go
- wrap_mode.go