[][src]Struct stdweb::web::Selection

pub struct 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.

(Javascript docs)

Methods

impl Selection[src]

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.

(Javascript docs)

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.

(Javascript docs)

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.

(Javascript docs)

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.

(Javascript docs)

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.

(Javascript docs)

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.

(Javascript docs)

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.

(Javascript docs)

pub fn get_range_at(&self, index: u32) -> Result<Range, IndexSizeError>[src]

Returns a Range object representing one of the ranges currently selected.

(Javascript docs)

pub fn add_range(&self, range: &Range)[src]

pub fn remove_range(&self, range: &Range) -> Result<(), NotFoundError>[src]

Removes a Range from the Selection.

(Javascript docs)

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.

(Javascript docs)

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.

(Javascript docs)

pub fn collapse_with_offset<N: INode>(
    &self,
    node: &N,
    offset: Option<u32>
) -> Result<(), IndexSizeError>
[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.

(Javascript docs)

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.

(Javascript docs)

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.

(Javascript docs)

pub fn extend<N: INode>(
    &self,
    node: &N,
    offset: Option<u32>
) -> Result<(), InvalidStateError>
[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.

(Javascript docs)

pub fn set_base_and_extent<N: INode, M: INode>(
    &self,
    anchor_node: &N,
    anchor_offset: u32,
    focus_node: &M,
    focus_offset: u32
) -> Result<(), IndexSizeError>
[src]

Sets the selection to be a range including all or parts of the two specified Nodes, and any content located between them.

(Javascript docs)

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.

(Javascript docs)

pub fn delete_from_document(&self)[src]

Deletes the actual text being represented by the Selection from the document's DOM.

(Javascript docs)

pub fn contains_whole<N: INode>(&self, node: &N) -> bool[src]

Indicates if the entire node is part of the selection.

(Javascript docs)

pub fn contains_part_of<N: INode>(&self, node: &N) -> bool[src]

Indicates if atleast some of the node is part of the selection.

(Javascript docs)

Trait Implementations

impl JsSerialize for Selection[src]

impl TryFrom<Selection> for Reference[src]

type Error = Void

The type returned in the event of a conversion error.

impl TryFrom<Reference> for Selection[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl<'_r> TryFrom<&'_r Reference> for Selection[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl TryFrom<Value> for Selection[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl<'_r> TryFrom<&'_r Value> for Selection[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl InstanceOf for Selection[src]

impl ReferenceType for Selection[src]

impl AsRef<Reference> for Selection[src]

impl From<Selection> for Reference[src]

impl Clone for Selection[src]

impl Eq for Selection[src]

impl PartialEq<Selection> for Selection[src]

impl Debug for Selection[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]