loom & weft
Made for Swift.

Published release 0.2.1. Unreleased PR #2 reference.

LOOM 0.2.1 / TEXT, MARKDOWN, AND EDITING

TextSelection

Endpoints are inclusive display-cell coordinates ordered by row, then column. A selection is independent of drag direction: first and last normalize anchor/head. Wide graphemes are highlighted and copied whole. These points are not LineEditor’s half-open grapheme offsets.

Standard inherited Swift protocol operations such as synthesized equality and OptionSet set operations are not repeated. The public declarations below are extracted from the exact source revision listed in the coverage manifest.

Example

let selection = TextSelection(anchor: Point(x: 4, y: 0), head: Point(x: 0, y: 0))
_ = selection.intersects(x: 1, y: 0, width: 2)
Members on this page

Feature guides and release status

TextSelection

Structure
struct TextSelection

Conforms to: Swift.Equatable, Swift.Sendable, Swift.SendableMetatype.

An inclusive selection between two positions in laid-out text.

Source · TextSelection.swift:4

anchor

Instance Property
var anchor: Point

The fixed selection endpoint.

Source · TextSelection.swift:5

head

Instance Property
var head: Point

The current selection endpoint.

Source · TextSelection.swift:6

init(anchor:head:)

Initializer
init(anchor: Point, head: Point)

Creates a value with the supplied arguments. Default arguments are shown in the declaration.

Parameters (2)
anchor
Argument type and any default are shown in the declaration; see the behavior notes above.
head
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · TextSelection.swift:8

first

Instance Property
var first: Point { get }

The earlier normalized display-cell endpoint.

Source · TextSelection.swift:12

last

Instance Property
var last: Point { get }

The later normalized display-cell endpoint.

Source · TextSelection.swift:15

intersects(x:y:width:)

Instance Method
func intersects(x: Int, y: Int, width: Int) -> Bool

Tests whether a glyph occupying width cells at (x, y) intersects the inclusive selection.

Parameters (3)
x
Argument type and any default are shown in the declaration; see the behavior notes above.
y
Argument type and any default are shown in the declaration; see the behavior notes above.
width
Available columns in terminal cells.

Returns Bool.

Source · TextSelection.swift:19