| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | TestCase := TextInput { |
| 5 | width: 100phx; |
| 6 | height: 100phx; |
| 7 | property<string> test_text: self.text; |
| 8 | property<int> test_cursor_pos: self.cursor_position_byte_offset; |
| 9 | property<int> test_anchor_pos: self.anchor_position_byte_offset; |
| 10 | property<bool> has_selection: self.test_cursor_pos != self.test_anchor_pos; |
| 11 | property<bool> input_focused: self.has_focus; |
| 12 | } |
| 13 | |
| 14 | /* |
| 15 | ```rust |
| 16 | |
| 17 | const LEFT_CODE: char = '\u{F702}'; |
| 18 | const BACK_CODE: char = '\u{0008}'; // backspace \b |
| 19 | |
| 20 | let instance = TestCase::new().unwrap(); |
| 21 | slint_testing::send_mouse_click(&instance, 50., 50.); |
| 22 | assert!(instance.get_input_focused()); |
| 23 | assert_eq!(instance.get_test_text(), ""); |
| 24 | slint_testing::send_keyboard_string_sequence(&instance, "e\u{0301}"); |
| 25 | assert_eq!(instance.get_test_text(), "e\u{0301}"); |
| 26 | assert!(!instance.get_has_selection()); |
| 27 | |
| 28 | // Test that selecting the grapheme works |
| 29 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), true); |
| 30 | slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string()); |
| 31 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), false); |
| 32 | assert!(instance.get_has_selection()); |
| 33 | slint_testing::send_keyboard_string_sequence(&instance, &BACK_CODE.to_string()); |
| 34 | |
| 35 | assert_eq!(instance.get_test_text(), ""); |
| 36 | |
| 37 | slint_testing::send_keyboard_string_sequence(&instance, "e\u{0301}"); |
| 38 | |
| 39 | // Test that backspace does not operate on the grapheme and just removes the |
| 40 | // diacritic. |
| 41 | slint_testing::send_keyboard_string_sequence(&instance, &BACK_CODE.to_string()); |
| 42 | assert_eq!(instance.get_test_cursor_pos(), 1); |
| 43 | assert_eq!(instance.get_test_text(), "e"); |
| 44 | ``` |
| 45 | */ |
| 46 | |