LavaUI docs GitHub

struct EditorView

Swift

struct EditorView

A code editor: line-number gutter, current-line highlight, rule-based syntax colouring, and find-match highlighting.

Everything about the buffer — cursor, selection, undo, wrapping, grapheme correctness — is TextEditingState, unchanged and already tested. This type is presentation plus a gutter, which is why it is a component rather than a rewrite of TextField.

Sources/LavaUI/EditorView.swift:314

Constructors

init(text: Binding<String>, isReadOnly: Bool = false, rules: [HighlightRule] = [], style: CodeStyle = CodeStyle(), font: UIFont? = nil, showLineNumbers: Bool = true, wraps: Bool = false, visibleLines: Int = 12, search: TextSearch = TextSearch(), decorations: [EditorDecoration] = [], onDecorationTap: ((EditorDecoration) -> Void)? = nil, controller: EditorController? = nil)

Creates an editor bound to text. Every parameter matches the property of the same name.

Sources/LavaUI/EditorView.swift:349

Properties

var controller: EditorController?

Handle for revealing lines, restoring positions and replacing matches.

Sources/LavaUI/EditorView.swift:346

var decorations: [EditorDecoration]

Diagnostics to underline and mark in the gutter.

Sources/LavaUI/EditorView.swift:341

var dumpDetail: String { get }

Not documented.

Sources/LavaUI/EditorView.swift:380

var font: UIFont?

The editor's font, or nil for the environment's.

Sources/LavaUI/EditorView.swift:324

var isReadOnly: Bool

Allows selection, copying and navigation while preventing text changes.

Sources/LavaUI/EditorView.swift:318

var onDecorationTap: ((EditorDecoration) -> Void)?

Fired when the user clicks a decorated row's gutter icon, instead of the default "select the whole row" gutter click.

Sources/LavaUI/EditorView.swift:344

var resolvedFont: UIFont? { get }

The font the editor draws with: font, or the environment's when that is nil.

Sources/LavaUI/EditorView.swift:378

var rules: [HighlightRule]

Syntax colouring rules, applied per line. Each rule's styleIndex picks a colour from style.palette.

Sources/LavaUI/EditorView.swift:320

var showLineNumbers: Bool

Whether to draw the line-number gutter.

Sources/LavaUI/EditorView.swift:326

var style: CodeStyle

Colours for text, gutter, current line and search matches.

Sources/LavaUI/EditorView.swift:322

@Binding var text: String { get nonmutating set }

The text being edited.

Sources/LavaUI/EditorView.swift:316

var visibleLines: Int

Most lines the editor grows to show before it scrolls. Layout can give it less.

Sources/LavaUI/EditorView.swift:337

var wraps: Bool

Break long lines to the box width instead of scrolling horizontally.

Off by default, which is right for code and wrong for prose. A wrapped editor has no horizontal scroll at all, numbers logical lines rather than the rows it draws, and re-wraps the whole buffer whenever the text or the width changes — that last one is O(buffer) and shapes every line, so a multi-megabyte document is a real cost per keystroke where the same document costs nothing unwrapped.

Sources/LavaUI/EditorView.swift:335

Methods

func mountPrimitive() -> any AnyViewNode

Not documented.

Sources/LavaUI/EditorView.swift:384

func reconcilePrimitive(_ node: any AnyViewNode) -> any AnyViewNode

Not documented.

Sources/LavaUI/EditorView.swift:393