Skip to content

TextSelection

A range of text that represents a selection.

属性 ​

名称类型默认值说明
base_offsetintrequiredThe offset at which the selection originates.
extent_offsetintrequiredThe offset at which the selection terminates.
affinity'TextAffinity'TextAffinity.DOWNSTREAMIf 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.
directionalboolFalseWhether this selection has disambiguated its base and extent.

只读属性 ​

名称类型默认值说明
startint—The index of the first character in the range. Note: This property is read-only.
endint—The next index after the characters in this range. Note: This property is read-only.
is_validbool—Whether this range represents a valid position in the text. Note: This property is read-only.
is_collapsedbool—Whether this range is empty (but still potentially placed inside the text). Note: This property is read-only.
is_normalizedbool—Whether the start of this range precedes the end. Note: This property is read-only.

方法 ​

名称类型默认值说明
get_selected_textstr—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.

关注我,学习大模型、大数据、Python等热门技术。