diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-03-26 08:16:20 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-03-26 08:16:20 +0530 |
commit | bed91b3334786970c91a47c3bc95889d8675b4d5 (patch) | |
tree | a4f91a1957a33d18b393b41edab354a113720f5d /components/script/textinput.rs | |
parent | 1554331f06900e69f246ed9986a08aae91a0a71e (diff) | |
parent | 08caf7412fc3e86a76c47876eb9bfab9804f2182 (diff) | |
download | servo-bed91b3334786970c91a47c3bc95889d8675b4d5.tar.gz servo-bed91b3334786970c91a47c3bc95889d8675b4d5.zip |
Auto merge of #10176 - mbrubeck:selection-range, r=pcwalton
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.
r? @pcwalton
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10176)
<!-- Reviewable:end -->
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 { |