LavaUI docs GitHub

struct EditorPosition

Swift

struct EditorPosition

Where an editor was left: what it was scrolled to, and what was selected.

Character offsets rather than String.Index, because the point of saving this is to restore it into a different buffer state — a document swapped out and back, or a workspace reopened days later. An index into a string that no longer exists is not a position, it is a crash waiting for the wrong buffer; an offset is merely clamped.

Sources/LavaUI/EditorView.swift:151

Constructors

init(scrollX: Float = 0, scrollY: Float = 0, anchor: Int = 0, focus: Int = 0)

Creates a position. The default is the top of the buffer with the caret at 0.

Sources/LavaUI/EditorView.swift:162

Properties

var anchor: Int

Selection ends, in character offsets. Equal means a plain caret.

Sources/LavaUI/EditorView.swift:157

var focus: Int

The end of the selection the caret is at. See anchor.

Sources/LavaUI/EditorView.swift:159

var scrollX: Float

Horizontal scroll offset, in pixels.

Sources/LavaUI/EditorView.swift:153

var scrollY: Float

Vertical scroll offset, in pixels.

Sources/LavaUI/EditorView.swift:155

static let start: EditorPosition

The top of the buffer, caret at the first character, nothing selected.

Sources/LavaUI/EditorView.swift:170