Skip to main content

TextSelection

A range of text that represents a selection.

Properties

  • affinity - If the text range is collapsed and has more than one visual location (e.g., occurs at a line break), which of the two locations to use when painting the caret.
  • base_offset - The offset at which the selection originates.
  • directional - Whether this selection has disambiguated its base and extent.
  • end - The next index after the characters in this range.
  • extent_offset - The offset at which the selection terminates.
  • is_collapsed - Whether this range is empty (but still potentially placed inside the text).
  • is_normalized - Whether the start of this range precedes the end.
  • is_valid - Whether this range represents a valid position in the text.
  • start - The index of the first character in the range.

Methods

Properties

affinityclass-attributeinstance-attribute

If the text range is collapsed and has more than one visual location (e.g., occurs at a line break), which of the two locations to use when painting the caret.

base_offsetinstance-attribute

base_offset: int

The offset at which the selection originates.

directionalclass-attributeinstance-attribute

directional: bool = False

Whether this selection has disambiguated its base and extent.

endproperty

end: int

The next index after the characters in this range.

Note

This property is read-only.

extent_offsetinstance-attribute

extent_offset: int

The offset at which the selection terminates.

is_collapsedproperty

is_collapsed: bool

Whether this range is empty (but still potentially placed inside the text).

Note

This property is read-only.

is_normalizedproperty

is_normalized: bool

Whether the start of this range precedes the end.

Note

This property is read-only.

is_validproperty

is_valid: bool

Whether this range represents a valid position in the text.

Note

This property is read-only.

startproperty

start: int

The index of the first character in the range.

Note

This property is read-only.

Methods

get_selected_text

get_selected_text(source_text: str)

Returns the selected text from the given full text.

Parameters:

  • source_text (str) - The full text to get the selection from.

Raises:

  • AssertionError - If the selection is not valid, i.e. is_valid is False.