pub fn glue_range_to_text(range: &mut Range) -> bool {
    // Reject non-collapsed ranges
    if !range.collapsed() {
        return false;
    }

    // Determine node type of container
    let container = range
        .start_container()
        .expect("Could not get start container");
    match container.node_type() {
        Node::TEXT_NODE => true,
        Node::ELEMENT_NODE => {
            let offset: u32 = range.start_offset().expect("Could not get start offset");
            if offset == 0 {
                false
            } else if let Some(prev_sibling) = container.child_nodes().get(offset - 1) {
                if prev_sibling.node_type() == Node::TEXT_NODE {
                    let length = prev_sibling.dyn_ref::<Text>().unwrap().length();
                    range
                        .set_start(&prev_sibling, length)
                        .expect("Could not set_start");
                    range.collapse_with_to_start(true);
                    true
                } else {
                    false
                }
            } else {
                true
            }
        }
        _ => false,
    }
}
/// This function will check whether the current selection range is adjacent to
/// a text node. It will then modify the range so that the `startContainer` is
/// that text node.
///
/// If the selection is not directly preceding a text node or within a text
/// node with offset 0, `false` will be returned and the range will not be
/// modified.
///
/// Non-collapsed ranges will be immediately rejected.
///
/// Examples of ranges (denoted with the `|`) that are successfully modified:
///
/// - `"|abc"` -> `"|abc"`
/// - `"ab|c"` -> `"ab|c"`
/// - `"abc|"` -> `"abc|"`
/// - `"abc"|` -> `"abc|"`
/// - `<span>"abc"|<span>` -> `<span>"abc|"</span>`
///
/// Examples of ranges where `false` will be returned:
///
/// - `<span>|"abc"</span>`
/// - `<span>"abc"</span>|`
/// - `<span>"abc"<img>|</span>
/// - `<span>"abc"<span></span>|</span>
///
This function will check whether the current selection range is adjacent to
a text node. It will then modify the range so that the `startContainer` is
that text node.

If the selection is not directly preceding a text node or within a text
node with offset 0, `false` will be returned and the range will not be
modified.

Non-collapsed ranges will be immediately rejected.

Examples of ranges (denoted with the `|`) that are successfully modified.



Examples of ranges where `false` will be returned.


This function will check whether the current selection range is adjacent to a text node . It will then modify the range so that the ` startContainer ` is that text node . If the selection is not directly preceding a text node or within a text node with offset 0 ` false ` will be returned and the range will not be modified . Non - collapsed ranges will be immediately rejected . Examples of ranges ( denoted with the ` | ` ) that are successfully modified . Examples of ranges where ` false ` will be returned .
pub fn glue_range_to_text(range: &mut Range) -> bool {
    // Reject non-collapsed ranges
    if !range.collapsed() {
        return false;
    }
    // Determine node type of container
    let container = range
        .start_container()
        .expect("Could not get start container");
    match container.node_type() {
        Node::TEXT_NODE => true,
        Node::ELEMENT_NODE => {
            let offset: u32 = range.start_offset().expect("Could not get start offset");
            if offset == 0 {
                false
            } else if let Some(prev_sibling) = container.child_nodes().get(offset - 1) {
                if prev_sibling.node_type() == Node::TEXT_NODE {
                    let length = prev_sibling.dyn_ref::<Text>().unwrap().length();
                    range
                        .set_start(&prev_sibling, length)
                        .expect("Could not set_start");
                    range.collapse_with_to_start(true);
                    true
                } else {
                    false
                }
            } else {
                true
            }
        }
        _ => false,
    }
}
pub fn glue_range_to_text ( range : & mut Range ) -> bool { // Reject non-collapsed ranges if ! range . collapsed ( ) { return false ; } // Determine node type of container let container = range . start_container ( ) . expect ( " " ) ; match container . node_type ( ) { Node :: TEXT_NODE => true , Node :: ELEMENT_NODE => { let offset : u32 = range . start_offset ( ) . expect ( " " ) ; if offset == 0 { false } else if let Some ( prev_sibling ) = container . child_nodes ( ) . get ( offset - 1 ) { if prev_sibling . node_type ( ) == Node :: TEXT_NODE { let length = prev_sibling . dyn_ref :: < Text > ( ) . unwrap ( ) . length ( ) ; range . set_start ( & prev_sibling , length ) . expect ( " " ) ; range . collapse_with_to_start ( true ) ; true } else { false } } else { true } } _ => false , } }
This function will check whether the current selection range is adjacent to
a text node.
This function will check whether the current selection range is adjacent to a text node .
range
&mut Range
range
&mut Range