diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-10-21 15:23:52 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-10-21 15:23:52 -0600 |
commit | af6a64e176ec66a9c066e9e7bf40b6ce3ac77b2e (patch) | |
tree | 16b07286847fc8370efc9bb9bab441c9e913b896 /components/layout/wrapper.rs | |
parent | f9e17d33bb3cd5cfe103bb1631f390123bcddc04 (diff) | |
parent | 80e8a674e219a6b65e070675d1775f0bd0e2ad93 (diff) | |
download | servo-af6a64e176ec66a9c066e9e7bf40b6ce3ac77b2e.tar.gz servo-af6a64e176ec66a9c066e9e7bf40b6ce3ac77b2e.zip |
Auto merge of #7761 - fiji-flo:input_caret, r=pcwalton
display input caret for textarea. fixes #7758
This adds the input caret for textareas. Although, it does not handle multiline textareas correctly. The caret gets displayed for each line.
I'll look into that but that will take more time. Some feedback on this small patch would be appreciated though.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7761)
<!-- Reviewable:end -->
Diffstat (limited to 'components/layout/wrapper.rs')
-rw-r--r-- | components/layout/wrapper.rs | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 2be8382ee4c..e2c0bd89f19 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -71,7 +71,7 @@ use style::node::TElementAttributes; use style::properties::ComputedValues; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use url::Url; -use util::str::is_whitespace; +use util::str::{is_whitespace, search_index}; /// A wrapper so that layout can access only the methods that it should have access to. Layout must /// only ever see these and must never see instances of `LayoutJS`. @@ -918,24 +918,17 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { let this = unsafe { self.get_jsmanaged() }; - let input = this.downcast(); - if let Some(input) = input { - let insertion_point = unsafe { - input.get_insertion_point_for_layout() - }; + + if let Some(area) = this.downcast::<HTMLTextAreaElement>() { + let insertion_point = unsafe { area.get_absolute_insertion_point_for_layout() }; + let text = unsafe { area.get_value_for_layout() }; + return Some(CharIndex(search_index(insertion_point, text.char_indices()))); + } + if let Some(input) = this.downcast::<HTMLInputElement>() { + let insertion_point = unsafe { input.get_insertion_point_for_layout() }; if let Some(insertion_point) = insertion_point { - let text = unsafe { - input.get_value_for_layout() - }; - - let mut character_count = 0; - for (character_index, _) in text.char_indices() { - if character_index == insertion_point.index { - return Some(CharIndex(character_count)) - } - character_count += 1 - } - return Some(CharIndex(character_count)) + let text = unsafe { input.get_value_for_layout() }; + return Some(CharIndex(search_index(insertion_point.index, text.char_indices()))); } } None |