diff options
author | Matt Brubeck <mbrubeck@limpet.net> | 2016-03-18 16:38:17 -0700 |
---|---|---|
committer | Matt Brubeck <mbrubeck@limpet.net> | 2016-03-24 18:33:26 -0700 |
commit | 61710008750f03f1f66ce0b24ea92c2b0286e0e0 (patch) | |
tree | ca9565958734bdba5210691aae2f8da477685b1a /components/script/textinput.rs | |
parent | f2f05869d6ccd445df9b73e2e8d038c6cfa9e687 (diff) | |
download | servo-61710008750f03f1f66ce0b24ea92c2b0286e0e0.tar.gz servo-61710008750f03f1f66ce0b24ea92c2b0286e0e0.zip |
Highlight selected text in input fields
Fixes #9993. This does not yet allow stylesheets to set the selection colors;
instead it uses a hard-coded orange background and white foreground.
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r-- | components/script/textinput.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 35b49ee57a4..343b114bf2d 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; @@ -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 { |