pub struct Selection {
pub start: SelectionEnd,
pub end: SelectionEnd,
pub direction: Direction,
/* private fields */
}Expand description
A text selection.
Fields§
§start: SelectionEndThe start of the selection.
end: SelectionEndThe end of the selection.
direction: DirectionThe last direction of the selection.
Implementations§
Source§impl Selection
impl Selection
Sourcepub fn text(&self, paragraph: &Paragraph) -> String
pub fn text(&self, paragraph: &Paragraph) -> String
Returns the selected text from the given Paragraph.
Sourcepub fn active_end(&self) -> SelectionEnd
pub fn active_end(&self) -> SelectionEnd
Returns the currently active SelectionEnd.
self.end if self.direction is Right, self.start otherwise.
Sourcepub fn select_range(&mut self, start: SelectionEnd, end: SelectionEnd)
pub fn select_range(&mut self, start: SelectionEnd, end: SelectionEnd)
Select a new range.
self.start will be set to the smaller value, self.end to the larger.
§Example
use iced_selection::selection::{Selection, SelectionEnd};
let mut selection = Selection::default();
let start = SelectionEnd::new(5, 17);
let end = SelectionEnd::new(2, 8);
selection.select_range(start, end);
assert_eq!(selection.start, end);
assert_eq!(selection.end, start);Sourcepub fn change_selection(&mut self, new_end: SelectionEnd)
pub fn change_selection(&mut self, new_end: SelectionEnd)
Updates the current selection by setting a new end point.
This method adjusts the selection range based on the provided new_end position. The
current Direction is used to determine the new values:
-
If the current direction is
Right(i.e., the selection goes fromstarttoend), the range becomes(start, new_end). Ifnew_endis beforestart, the direction is flipped toLeft. -
If it’s
Left, the range becomes(new_end, end). Ifnew_endis afterend, the direction is flipped toRight.
§Example
use iced_selection::selection::{Direction, Selection, SelectionEnd};
let mut selection = Selection::default();
let start = SelectionEnd::new(5, 17);
let end = SelectionEnd::new(2, 8);
selection.select_range(start, end);
assert_eq!(selection.start, end);
assert_eq!(selection.end, start);
assert_eq!(selection.direction, Direction::Right);
let new_end = SelectionEnd::new(2, 2);
selection.change_selection(new_end);
assert_eq!(selection.start, new_end);
assert_eq!(selection.end, end);
assert_eq!(selection.direction, Direction::Left);Sourcepub fn change_selection_by_word(
&mut self,
new_end: SelectionEnd,
paragraph: &Paragraph,
)
pub fn change_selection_by_word( &mut self, new_end: SelectionEnd, paragraph: &Paragraph, )
Updates the current selection by setting a new end point, either to the start of the previous word, or to the next one’s end.
Sourcepub fn change_selection_by_line(
&mut self,
new_line: usize,
paragraph: &Paragraph,
)
pub fn change_selection_by_line( &mut self, new_line: usize, paragraph: &Paragraph, )
Updates the current selection by setting a new end point, either to the end of a following line, or the beginning of a previous one.
Sourcepub fn select_word(&mut self, line: usize, index: usize, paragraph: &Paragraph)
pub fn select_word(&mut self, line: usize, index: usize, paragraph: &Paragraph)
Selects the word around the given grapheme position.
Sourcepub fn select_left(&mut self, paragraph: &Paragraph)
pub fn select_left(&mut self, paragraph: &Paragraph)
Moves the active SelectionEnd to the left by one, wrapping to the previous line if
possible and required.
Sourcepub fn select_right(&mut self, paragraph: &Paragraph)
pub fn select_right(&mut self, paragraph: &Paragraph)
Moves the active SelectionEnd to the right by one, wrapping to the next line if
possible and required.
Sourcepub fn select_up(&mut self, paragraph: &Paragraph)
pub fn select_up(&mut self, paragraph: &Paragraph)
Moves the active SelectionEnd up by one, keeping track of the original grapheme index.
Sourcepub fn select_down(&mut self, paragraph: &Paragraph)
pub fn select_down(&mut self, paragraph: &Paragraph)
Moves the active SelectionEnd down by one, keeping track of the original grapheme index.
Sourcepub fn select_left_by_words(&mut self, paragraph: &Paragraph)
pub fn select_left_by_words(&mut self, paragraph: &Paragraph)
Moves the active SelectionEnd to the previous start of a word on its current line, or
the previous line if it exists and index == 0.
Sourcepub fn select_right_by_words(&mut self, paragraph: &Paragraph)
pub fn select_right_by_words(&mut self, paragraph: &Paragraph)
Moves the active SelectionEnd to the next end of a word on its current line, or
the next line if it exists and index == line.len().
Sourcepub fn select_line_beginning(&mut self)
pub fn select_line_beginning(&mut self)
Moves the active SelectionEnd to the beginning of its current line.
Sourcepub fn select_line_end(&mut self, paragraph: &Paragraph)
pub fn select_line_end(&mut self, paragraph: &Paragraph)
Moves the active SelectionEnd to the end of its current line.
Sourcepub fn select_beginning(&mut self)
pub fn select_beginning(&mut self)
Moves the active SelectionEnd to the beginning of the Paragraph.
Sourcepub fn select_end(&mut self, paragraph: &Paragraph)
pub fn select_end(&mut self, paragraph: &Paragraph)
Moves the active SelectionEnd to the end of the Paragraph.
Sourcepub fn select_line(&mut self, line: usize, paragraph: &Paragraph)
pub fn select_line(&mut self, line: usize, paragraph: &Paragraph)
Selects an entire line.
Sourcepub fn select_all(&mut self, paragraph: &Paragraph)
pub fn select_all(&mut self, paragraph: &Paragraph)
Selects the entire Paragraph.