aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/htmltextareaelement.rs8
-rw-r--r--components/script/textinput.rs10
2 files changed, 18 insertions, 0 deletions
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index d802760a308..2ef5a24775d 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -46,6 +46,8 @@ pub struct HTMLTextAreaElement {
pub trait LayoutHTMLTextAreaElementHelpers {
#[allow(unsafe_code)]
unsafe fn get_value_for_layout(self) -> String;
+ #[allow(unsafe_code)]
+ unsafe fn get_absolute_insertion_point_for_layout(self) -> usize;
}
pub trait RawLayoutHTMLTextAreaElementHelpers {
@@ -61,6 +63,12 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> {
unsafe fn get_value_for_layout(self) -> String {
(*self.unsafe_get()).textinput.borrow_for_layout().get_content()
}
+
+ #[allow(unrooted_must_root)]
+ #[allow(unsafe_code)]
+ unsafe fn get_absolute_insertion_point_for_layout(self) -> usize {
+ (*self.unsafe_get()).textinput.borrow_for_layout().get_absolute_insertion_point()
+ }
}
impl<'a> RawLayoutHTMLTextAreaElementHelpers for &'a HTMLTextAreaElement {
diff --git a/components/script/textinput.rs b/components/script/textinput.rs
index 627ecf29a5f..c75d246d3ba 100644
--- a/components/script/textinput.rs
+++ b/components/script/textinput.rs
@@ -455,4 +455,14 @@ impl<T: ClipboardProvider> TextInput<T> {
self.edit_point.line = min(self.edit_point.line, self.lines.len() - 1);
self.edit_point.index = min(self.edit_point.index, self.current_line_length());
}
+
+ pub fn get_absolute_insertion_point(&self) -> usize {
+ self.lines.iter().enumerate().fold(0, |acc, (i, val)| {
+ if i < self.edit_point.line {
+ acc + val.len() + 1 // +1 for the \n
+ } else {
+ acc
+ }
+ }) + self.edit_point.index
+ }
}