mirror of
https://github.com/servo/servo.git
synced 2025-06-08 00:23:30 +00:00
Fix delete_char when selection range is empty
An empty selection range should be treated the same as no selection. Fixes browserhtml/browserhtml#930.
This commit is contained in:
parent
f2f05869d6
commit
db2c1841cb
2 changed files with 9 additions and 2 deletions
|
@ -20,7 +20,7 @@ pub enum Selection {
|
||||||
NotSelected
|
NotSelected
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(JSTraceable, Copy, Clone, HeapSizeOf)]
|
#[derive(JSTraceable, Copy, Clone, HeapSizeOf, PartialEq)]
|
||||||
pub struct TextPoint {
|
pub struct TextPoint {
|
||||||
/// 0-based line number
|
/// 0-based line number
|
||||||
pub line: usize,
|
pub line: usize,
|
||||||
|
@ -123,7 +123,7 @@ impl<T: ClipboardProvider> TextInput<T> {
|
||||||
|
|
||||||
/// Remove a character at the current editing point
|
/// Remove a character at the current editing point
|
||||||
pub fn delete_char(&mut self, dir: Direction) {
|
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.adjust_horizontal_by_one(dir, Selection::Selected);
|
||||||
}
|
}
|
||||||
self.replace_selection(DOMString::new());
|
self.replace_selection(DOMString::new());
|
||||||
|
|
|
@ -150,6 +150,13 @@ fn test_textinput_delete_char() {
|
||||||
textinput.delete_char(Direction::Forward);
|
textinput.delete_char(Direction::Forward);
|
||||||
// Not splitting surrogate pairs.
|
// Not splitting surrogate pairs.
|
||||||
assert_eq!(textinput.get_content(), "ab");
|
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]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue