diff options
-rw-r--r-- | components/script/textinput.rs | 4 | ||||
-rw-r--r-- | tests/unit/script/textinput.rs | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 343b114bf2d..cc5936d42b0 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -21,7 +21,7 @@ pub enum Selection { NotSelected } -#[derive(JSTraceable, Copy, Clone, HeapSizeOf)] +#[derive(JSTraceable, Copy, Clone, HeapSizeOf, PartialEq)] pub struct TextPoint { /// 0-based line number pub line: usize, @@ -124,7 +124,7 @@ impl<T: ClipboardProvider> TextInput<T> { /// Remove a character at the current editing point pub fn delete_char(&mut self, dir: Direction) { - if self.selection_begin.is_none() { + if self.selection_begin.is_none() || self.selection_begin == Some(self.edit_point) { self.adjust_horizontal_by_one(dir, Selection::Selected); } self.replace_selection(DOMString::new()); diff --git a/tests/unit/script/textinput.rs b/tests/unit/script/textinput.rs index c5071f36090..2613c0f640a 100644 --- a/tests/unit/script/textinput.rs +++ b/tests/unit/script/textinput.rs @@ -150,6 +150,13 @@ fn test_textinput_delete_char() { textinput.delete_char(Direction::Forward); // Not splitting surrogate pairs. assert_eq!(textinput.get_content(), "ab"); + + let mut textinput = text_input(Lines::Single, "abcdefg"); + textinput.adjust_horizontal(2, Selection::NotSelected); + // Set an empty selection range. + textinput.selection_begin = Some(textinput.edit_point); + textinput.delete_char(Direction::Backward); + assert_eq!(textinput.get_content(), "acdefg"); } #[test] |