DocumentSelection class

A selection within a Document.

A DocumentSelection spans from a base position to an extent position, and includes all content in between.

base and extent are instances of DocumentPosition, which represents a single position within a Document.

A DocumentSelection does not hold a reference to a Document, it only represents a directional selection within a Document. The base and extent positions must be interpreted within the context of a specific Document to locate nodes between base and extent, and to identify partial content that is selected within the base and extent nodes within the document.

Inheritance

Constructors

DocumentSelection({required DocumentPosition base, required DocumentPosition extent})
Creates a selection from the base position to the extent position within the document.
const
DocumentSelection.collapsed({required DocumentPosition position})
Creates a collapsed selection at the given position within the document.
const

Properties

base DocumentPosition
The base position of the selection within the document.
final
end DocumentPosition
The bounding position of the other side of a DocumentRange.
finalinherited
extent DocumentPosition
The extent position of the selection within the document.
final
hashCode int
The hash code for this object.
no setteroverride
isCollapsed bool
Returns true if this selection is collapsed, or false if this selection is expanded.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
start DocumentPosition
The bounding position of one side of a DocumentRange.
finalinherited

Methods

calculateAffinity(Document document) TextAffinity
Returns the affinity (direction) for this selection - downstream refers to a selection that starts at earlier content and ends at later content, upstream refers to a selection that starts at later content and ends at earlier content.
collapse() DocumentSelection
Returns a version of this that is collapsed at the extent position.
collapseDownstream(Document document) DocumentSelection
Returns a version of this DocumentSelection that is collapsed in the downstream (end) direction.
collapseUpstream(Document document) DocumentSelection
Returns a version of this DocumentSelection that is collapsed in the upstream (start) direction.
containsPosition(Document document, DocumentPosition position) bool
Returns true if the given position sits within this DocumentSelection.
copyWith({DocumentPosition? base, DocumentPosition? extent}) DocumentSelection
Creates a new DocumentSelection based on the current selection, with the provided parameters overridden.
expandTo(DocumentPosition newExtent) DocumentSelection
Creates a copy of this selection but with the extent expanded to the given new extent.
hasDownstreamAffinity(Document document) bool
Returns true if this selection has an affinity of TextAffinity.downstream.
hasUpstreamAffinity(Document document) bool
Returns true if this selection has an affinity of TextAffinity.upstream.
isNormalized(Document document) bool
Returns true if start appears at, or before end, or false otherwise.
inherited
normalize(Document document) DocumentRange
Returns a version of this DocumentRange that's normalized.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override