主题
TextSelection
A range of text that represents a selection.
属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
base_offset | int | required | The offset at which the selection originates. |
extent_offset | int | required | The offset at which the selection terminates. |
affinity | 'TextAffinity' | TextAffinity.DOWNSTREAM | 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. |
directional | bool | False | Whether this selection has disambiguated its base and extent. |
只读属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
start | int | — | The index of the first character in the range. Note: This property is read-only. |
end | int | — | The next index after the characters in this range. Note: This property is read-only. |
is_valid | bool | — | Whether this range represents a valid position in the text. Note: This property is read-only. |
is_collapsed | bool | — | Whether this range is empty (but still potentially placed inside the text). Note: This property is read-only. |
is_normalized | bool | — | Whether the start of this range precedes the end. Note: This property is read-only. |
方法
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
get_selected_text | str | — | Returns the selected text from the given full text. Args: source_text: The full text to get the selection from. Raises: AssertionError: If the selection is not valid, i.e. is_valid is False. |