diff options
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r-- | components/script/textinput.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 35b49ee57a4..cc5936d42b0 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -8,6 +8,7 @@ use clipboard_provider::ClipboardProvider; use dom::keyboardevent::{KeyboardEvent, key_value}; use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; use msg::constellation_msg::{Key, KeyModifiers}; +use range::Range; use std::borrow::ToOwned; use std::cmp::{max, min}; use std::default::Default; @@ -20,7 +21,7 @@ pub enum Selection { NotSelected } -#[derive(JSTraceable, Copy, Clone, HeapSizeOf)] +#[derive(JSTraceable, Copy, Clone, HeapSizeOf, PartialEq)] pub struct TextPoint { /// 0-based line number pub line: usize, @@ -123,7 +124,7 @@ impl<T: ClipboardProvider> TextInput<T> { /// Remove a character at the current editing point pub fn delete_char(&mut self, dir: Direction) { - if self.selection_begin.is_none() { + if self.selection_begin.is_none() || self.selection_begin == Some(self.edit_point) { self.adjust_horizontal_by_one(dir, Selection::Selected); } self.replace_selection(DOMString::new()); @@ -154,6 +155,15 @@ impl<T: ClipboardProvider> TextInput<T> { }) } + pub fn get_absolute_selection_range(&self) -> Range<usize> { + match self.get_sorted_selection() { + Some((begin, _end)) => + Range::new(self.get_absolute_point_for_text_point(&begin), self.selection_len()), + None => + Range::new(self.get_absolute_insertion_point(), 0) + } + } + pub fn get_selection_text(&self) -> Option<String> { self.get_sorted_selection().map(|(begin, end)| { if begin.line != end.line { |