Only display text carets in text inputs

This commit is contained in:
Jacob Parker 2015-09-27 18:10:27 -04:00
parent 9523283c14
commit 9cf43877f2
5 changed files with 40 additions and 12 deletions

View file

@ -954,18 +954,20 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
let insertion_point = unsafe {
input.get_insertion_point_for_layout()
};
let text = unsafe {
input.get_value_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))
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
}
character_count += 1
return Some(CharIndex(character_count))
}
return Some(CharIndex(character_count))
}
None
}

View file

@ -143,7 +143,7 @@ pub trait LayoutHTMLInputElementHelpers {
#[allow(unsafe_code)]
unsafe fn get_size_for_layout(self) -> u32;
#[allow(unsafe_code)]
unsafe fn get_insertion_point_for_layout(self) -> TextPoint;
unsafe fn get_insertion_point_for_layout(self) -> Option<TextPoint>;
}
pub trait RawLayoutHTMLInputElementHelpers {
@ -197,8 +197,12 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
#[allow(unrooted_must_root)]
#[allow(unsafe_code)]
unsafe fn get_insertion_point_for_layout(self) -> TextPoint {
(*self.unsafe_get()).textinput.borrow_for_layout().edit_point
unsafe fn get_insertion_point_for_layout(self) -> Option<TextPoint> {
match (*self.unsafe_get()).input_type.get() {
InputType::InputText | InputType::InputPassword =>
Some((*self.unsafe_get()).textinput.borrow_for_layout().edit_point),
_ => None
}
}
}