aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/textinput.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-04-16 15:08:59 -0500
committerGitHub <noreply@github.com>2017-04-16 15:08:59 -0500
commite45546edf0445d5ca714162bff89c0780d087993 (patch)
treeea03da7c02aebceac5c07670b22362f4b5753a55 /components/script/textinput.rs
parent5ccb087769fdb5253514e1ea2babd28b21c65907 (diff)
parent49ea443146f52f5d6558970359e26352af616585 (diff)
downloadservo-e45546edf0445d5ca714162bff89c0780d087993.tar.gz
servo-e45546edf0445d5ca714162bff89c0780d087993.zip
Auto merge of #15822 - charlesvdv:unicode-panic, r=emilio
Correct unicode handling for text input <!-- Please describe your changes on the following line: --> Allow proprer handling of unicode sequence in text input. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15819 <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15822) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r--components/script/textinput.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs
index d600b819e4c..144be9dbd78 100644
--- a/components/script/textinput.rs
+++ b/components/script/textinput.rs
@@ -377,18 +377,16 @@ impl<T: ClipboardProvider> TextInput<T> {
}
let adjust = {
let current_line = &self.lines[self.edit_point.line];
- // FIXME: We adjust by one code point, but it proably should be one grapheme cluster
- // https://github.com/unicode-rs/unicode-segmentation
match direction {
Direction::Forward => {
- match current_line[self.edit_point.index..].chars().next() {
- Some(c) => c.len_utf8() as isize,
+ match current_line[self.edit_point.index..].graphemes(true).next() {
+ Some(c) => c.len() as isize,
None => 1, // Going to the next line is a "one byte" offset
}
}
Direction::Backward => {
- match current_line[..self.edit_point.index].chars().next_back() {
- Some(c) => -(c.len_utf8() as isize),
+ match current_line[..self.edit_point.index].graphemes(true).next_back() {
+ Some(c) => -(c.len() as isize),
None => -1, // Going to the previous line is a "one byte" offset
}
}
@@ -845,4 +843,12 @@ impl<T: ClipboardProvider> TextInput<T> {
selection_start as u32
}
+
+ pub fn set_edit_point_index(&mut self, index: usize) {
+ let byte_size = self.lines[self.edit_point.line]
+ .graphemes(true)
+ .take(index)
+ .fold(0, |acc, x| acc + x.len());
+ self.edit_point.index = byte_size;
+ }
}