mirror of
https://github.com/servo/servo.git
synced 2025-07-30 18:50:36 +01:00
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 -->
This commit is contained in:
commit
af6a64e176
6 changed files with 67 additions and 21 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue