[−][src]Struct stdweb::web::Selection
Represents the range of text selected by the user or the current position of the caret. To obtain a Selection object for examination or modification, call Window.get_selection().
A user may make a selection from left to right (in document order) or right to left (reverse of document order). The anchor is where the user began the selection and the focus is where the user ends the selection. If you make a selection with a desktop mouse, the anchor is placed where you pressed the mouse button and the focus is placed where you released the mouse button. Anchor and focus should not be confused with the start and end positions of a selection, since anchor can be placed before the focus or vice versa, depending on the direction you made your selection.
Methods
impl Selection
[src]
impl Selection
pub fn anchor_node(&self) -> Option<Node> | [src] |
Returns the Node in which the selection begins.
A user may make a selection from left to right (in document order) or right to left (reverse of document order). The anchor is where the user began the selection. This can be visualized by holding the Shift key and pressing the arrow keys on your keyboard. The selection's anchor does not move, but the selection's focus, the other end of the selection, does move.
pub fn anchor_offset(&self) -> u32 | [src] |
Returns the number of characters that the selection's anchor is offset within the anchor_node.
This number is zero-based. If the selection begins with the first character in the anchor_node, 0 is returned.
pub fn focus_node(&self) -> Option<Node> | [src] |
Returns the Node in which the selection ends.
A user may make a selection from left to right (in document order) or right to left (reverse of document order). The focus is where the user ended the selection. This can be visualized by holding the Shift key and pressing the arrow keys on your keyboard to modify the current selection. The selection's focus moves, but the selection's anchor, the other end of the selection, does not move.
pub fn focus_offset(&self) -> u32 | [src] |
Returns the number of characters that the selection's anchor is offset within the focus_node.
This number is zero-based. If the selection begins with the first character in the focus_node, 0 is returned.
pub fn is_collapsed(&self) -> bool | [src] |
Returns a boolean which indicates whether or not there is currently any text selected; That is to say that the selection's start and end points are at the same position in the content.
Keep in mind that a collapsed selection may still have one (or more, in Gecko) Ranges, so range_count may not be zero. In that scenario, calling a Selection object's get_range_at method may return a Range object which is collapsed.
pub fn range_count(&self) -> u32 | [src] |
Returns the number of ranges in the selection.
Before the user has clicked a freshly loaded page, the range_count is 0. After the user clicks on the page, range_count even if no selection is visible.
A user can normally only select one range at a time, so the range_count will usually be 1. Scripting can be used to make the selection contain more than 1 range.
Gecko browsers allow multiple selections across table cells.
pub fn kind(&self) -> SelectionType | [src] |
Returns the type of the current selection.
Possible values are:
None
: No selection has currently been made.Caret
: The selection is collapsed (i.e. the caret is placed on some text, but no range has been selected).Range
: A range has been selected.
pub fn get_range_at(&self, index: u32) -> Result<Range, IndexSizeError> | [src] |
Returns a Range object representing one of the ranges currently selected.
pub fn add_range(&self, range: &Range) | [src] |
pub fn remove_range(&self, range: &Range) -> Result<(), NotFoundError> | [src] |
pub fn remove_all_ranges(&self) | [src] |
Removes all ranges from the Selection, leaving the
anchor_node and
focus_node properties equal to
None
and leaving nothing selected.
pub fn collapse<N: INode>(&self, node: &N) | [src] |
Collapses the Selection to a single point. The document is not modified. If the content is focused or editable, the caret will blink there.
pub fn collapse_with_offset<N: INode>( | [src] |
Collapses the Selection to a single point. The document is not modified. If the content is focused or editable, the caret will blink there.
pub fn collapse_to_start(&self) -> Result<(), InvalidStateError> | [src] |
Collapses the Selection to the start of the first range in the selection. If the content is focused or editable, the caret will blink there.
pub fn collapse_to_end(&self) -> Result<(), InvalidStateError> | [src] |
Collapses the Selection to the end of the last range in the selection. If the content is focused or editable, the caret will blink there.
pub fn extend<N: INode>( | [src] |
Moves the focus of the selection to a specified point. The anchor of the selection does not move. The selection will be from the anchor node to the new focus regardless of direction.
pub fn set_base_and_extent<N: INode, M: INode>( | [src] |
Sets the selection to be a range including all or parts of the two specified Nodes, and any content located between them.
pub fn select_all_children<N: INode>(&self, node: &N) | [src] |
Adds all the children of the specified Node to the selection. Previous selection is lost.
pub fn delete_from_document(&self) | [src] |
Deletes the actual text being represented by the Selection from the document's DOM.
pub fn contains_whole<N: INode>(&self, node: &N) -> bool | [src] |
Indicates if the entire node is part of the selection.
pub fn contains_part_of<N: INode>(&self, node: &N) -> bool | [src] |
Indicates if atleast some of the node is part of the selection.
Trait Implementations
impl JsSerialize for Selection
[src]
impl JsSerialize for Selection
impl TryFrom<Selection> for Reference
[src]
impl TryFrom<Selection> for Reference
type Error = Void
The type returned in the event of a conversion error.
fn try_from(value: Selection) -> Result<Self, Self::Error> | [src] |
impl TryFrom<Reference> for Selection
[src]
impl TryFrom<Reference> for Selection
type Error = ConversionError
The type returned in the event of a conversion error.
fn try_from(reference: Reference) -> Result<Self, Self::Error> | [src] |
impl<'_r> TryFrom<&'_r Reference> for Selection
[src]
impl<'_r> TryFrom<&'_r Reference> for Selection
type Error = ConversionError
The type returned in the event of a conversion error.
fn try_from(reference: &Reference) -> Result<Self, Self::Error> | [src] |
impl TryFrom<Value> for Selection
[src]
impl TryFrom<Value> for Selection
type Error = ConversionError
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error> | [src] |
impl<'_r> TryFrom<&'_r Value> for Selection
[src]
impl<'_r> TryFrom<&'_r Value> for Selection
type Error = ConversionError
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error> | [src] |
impl InstanceOf for Selection
[src]
impl InstanceOf for Selection
fn instance_of(reference: &Reference) -> bool | [src] |
impl ReferenceType for Selection
[src]
impl ReferenceType for Selection
unsafe fn from_reference_unchecked(reference: Reference) -> Self | [src] |
impl AsRef<Reference> for Selection
[src]
impl AsRef<Reference> for Selection
impl Clone for Selection
[src]
impl Clone for Selection
fn clone(&self) -> Selection | [src] |
fn clone_from(&mut self, source: &Self) | 1.0.0 [src] |
Performs copy-assignment from source
. Read more
impl From<Selection> for Reference
[src]
impl From<Selection> for Reference
impl Eq for Selection
[src]
impl Eq for Selection
impl PartialEq<Selection> for Selection
[src]
impl PartialEq<Selection> for Selection
impl Debug for Selection
[src]
impl Debug for Selection
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> | [src] |
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |