Build a `SelectionRange` linked list from a list of spans sorted outermost-first.
(content: &str, spans: &[(u32, u32)])
| 72 | /// Build a `SelectionRange` linked list from a list of spans sorted |
| 73 | /// outermost-first. |
| 74 | fn build_selection_range(content: &str, spans: &[(u32, u32)]) -> SelectionRange { |
| 75 | if spans.is_empty() { |
| 76 | let range = Range::new(Position::new(0, 0), Position::new(0, 0)); |
| 77 | return SelectionRange { |
| 78 | range, |
| 79 | parent: None, |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | // Start from the outermost and wrap inward. |
| 84 | let mut current = to_selection_range(content, spans[0], None); |
| 85 | |
| 86 | for &span in &spans[1..] { |
| 87 | current = to_selection_range(content, span, Some(current)); |
| 88 | } |
| 89 | |
| 90 | current |
| 91 | } |
| 92 | |
| 93 | fn to_selection_range( |
| 94 | content: &str, |
no test coverage detected