Skip to content

TextSelection

A range of text that represents a selection.

Properties

  • affinity(TextAffinity) –

    If the text range is collapsed and has more than one visual location (e.g., occurs

  • base_offset(int) –

    The offset at which the selection originates.

  • directional(bool) –

    Whether this selection has disambiguated its base and extent.

  • end(int) –

    The next index after the characters in this range.

  • extent_offset(int) –

    The offset at which the selection terminates.

  • is_collapsed(bool) –

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

  • is_normalized(bool) –

    Whether the start of this range precedes the end.

  • is_valid(bool) –

    Whether this range represents a valid position in the text.

  • start(int) –

    The index of the first character in the range.

Methods

Properties#

affinity class-attribute instance-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_offset instance-attribute #

base_offset: int

The offset at which the selection originates.

directional class-attribute instance-attribute #

directional: bool = False

Whether this selection has disambiguated its base and extent.

end property #

end: int

The next index after the characters in this range.

Note

This property is read-only.

extent_offset instance-attribute #

extent_offset: int

The offset at which the selection terminates.

is_collapsed property #

is_collapsed: bool

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

Note

This property is read-only.

is_normalized property #

is_normalized: bool

Whether the start of this range precedes the end.

Note

This property is read-only.

is_valid property #

is_valid: bool

Whether this range represents a valid position in the text.

Note

This property is read-only.

start property #

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) -> str

Returns the selected text from the given full text.

Parameters:

  • source_text (str) –

    The full text to get the selection from.

Raises: