Selection

Overview

Selection is a class in Aspose.Html FOSS for Python.

Document-scoped selection with single-range semantics.

This class provides 12 methods for working with Selection objects in Python programs. Available methods include: __init__, add_range, collapse, collapse_to_end, collapse_to_start, contains_node, extend, get_range_at, remove_all_ranges, select_all_children, set_position, to_string. All public members are accessible to any Python application after installing the Aspose.Html FOSS for Python package. Properties: anchor_node, anchor_offset, focus_node, focus_offset, is_collapsed, range_count.

Properties

NameTypeAccessDescription
range_countintReadNumber of ranges in this selection (0 or 1).
anchor_node"Node | None"ReadAnchor node for the current selection direction.
anchor_offsetintReadAnchor offset for the current selection direction.
focus_node"Node | None"ReadFocus node for the current selection direction.
focus_offsetintReadFocus offset for the current selection direction.
is_collapsedboolReadTrue when selection is empty or underlying range is collapsed.

Methods

SignatureDescription
__init__(owner_document: "Document")Calls init(owner_document) on this Selection instance.
get_range_at(index: int)"Range"Return the selected range at index.
add_range(range_obj: "Range")Set this selection’s single range to range_obj.
remove_all_ranges()Clear the current selection.
collapse(node: "Node | None", offset: int)Collapse selection to a single boundary point.
set_position(node: "Node | None", offset: int)Alias for :meth:collapse.
collapse_to_start()Collapse selection to the current start boundary point.
collapse_to_end()Collapse selection to the current end boundary point.
select_all_children(node: "Node")Select all children of node.
extend(node: "Node", offset: int)Move the focus of the selection to (node, offset).
to_string()strReturn the plain-text content of the selected range.
contains_node(node: "Node", allow_partial_containment: bool)boolReturn True if the selection contains node.

See Also