diff options
Diffstat (limited to 'components/layout')
-rw-r--r-- | components/layout/text.rs | 12 | ||||
-rw-r--r-- | components/layout/wrapper.rs | 29 |
2 files changed, 22 insertions, 19 deletions
diff --git a/components/layout/text.rs b/components/layout/text.rs index e007eb3d25b..feab75efa65 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -431,9 +431,19 @@ fn split_first_fragment_at_newline_if_necessary(fragments: &mut LinkedList<Fragm string_before = unscanned_text_fragment_info.text[..(position + 1)].to_owned(); - insertion_point_before = unscanned_text_fragment_info.insertion_point; unscanned_text_fragment_info.text = unscanned_text_fragment_info.text[(position + 1)..].to_owned().into_boxed_str(); + let offset = CharIndex(string_before.char_indices().count() as isize); + match unscanned_text_fragment_info.insertion_point { + Some(insertion_point) if insertion_point >= offset => { + insertion_point_before = None; + unscanned_text_fragment_info.insertion_point = Some(insertion_point - offset); + } + Some(_) | None => { + insertion_point_before = unscanned_text_fragment_info.insertion_point; + unscanned_text_fragment_info.insertion_point = None; + } + }; } first_fragment.transform(first_fragment.border_box.size, SpecificFragmentInfo::UnscannedText( 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 |