From 7db13e93b7035384276b8c029ba9288ad453f01f Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Wed, 7 Nov 2018 18:44:21 +0100 Subject: [PATCH] Correct select all Fixes assertion failure. Set selection direction forward on select all. --- components/script/textinput.rs | 1 + tests/unit/script/textinput.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/components/script/textinput.rs b/components/script/textinput.rs index c12c277c9f2..6f523d11bd8 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -583,6 +583,7 @@ impl TextInput { let last_line = self.lines.len() - 1; self.edit_point.line = last_line; self.edit_point.index = self.lines[last_line].len(); + self.selection_direction = SelectionDirection::Forward; self.assert_ok_selection(); } diff --git a/tests/unit/script/textinput.rs b/tests/unit/script/textinput.rs index 73d99cf1588..f4e65a0e1d3 100644 --- a/tests/unit/script/textinput.rs +++ b/tests/unit/script/textinput.rs @@ -699,3 +699,13 @@ fn test_selection_bounds() { assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_start()); assert_eq!(TextPoint { line: 1, index: 0 }, textinput.selection_end()); } + +#[test] +fn test_select_all() { + let mut textinput = text_input(Lines::Single, "abc"); + textinput.set_selection_range(2, 3, SelectionDirection::Backward); + textinput.select_all(); + assert_eq!(textinput.selection_direction(), SelectionDirection::Forward); + assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_start()); + assert_eq!(TextPoint { line: 0, index: 3 }, textinput.selection_end()); +}