@@ -854,6 +854,44 @@ void lv_textarea_selection_all(lv_obj_t * obj) {
854
854
#endif
855
855
}
856
856
857
+ void lv_textarea_selection_start (lv_obj_t * obj ) {
858
+ LV_ASSERT_OBJ (obj , MY_CLASS );
859
+ #if LV_LABEL_TEXT_SELECTION
860
+ lv_textarea_t * ta = (lv_textarea_t * )obj ;
861
+ if (!ta -> text_sel_in_prog ) {
862
+ lv_textarea_clear_selection (ta );
863
+ lv_label_set_text_selection_start (ta -> label , lv_textarea_get_cursor_pos (obj ));
864
+ ta -> text_sel_in_prog = 1 ;
865
+ }
866
+ #else
867
+ LV_UNUSED (obj ); /*Unused*/
868
+ #endif
869
+ }
870
+
871
+ void lv_textarea_selection_stop (lv_obj_t * obj ) {
872
+ LV_ASSERT_OBJ (obj , MY_CLASS );
873
+ #if LV_LABEL_TEXT_SELECTION
874
+ lv_textarea_t * ta = (lv_textarea_t * )obj ;
875
+ if (ta -> text_sel_in_prog ) {
876
+ ta -> text_sel_in_prog = 0 ;
877
+ }
878
+ #else
879
+ LV_UNUSED (obj ); /*Unused*/
880
+ #endif
881
+ }
882
+
883
+ void lv_textarea_selection_continue (lv_obj_t * obj ) {
884
+ LV_ASSERT_OBJ (obj , MY_CLASS );
885
+ #if LV_LABEL_TEXT_SELECTION
886
+ lv_textarea_t * ta = (lv_textarea_t * )obj ;
887
+ if (ta -> text_sel_in_prog ) {
888
+ lv_label_set_text_selection_end (ta -> label , lv_textarea_get_cursor_pos (obj ));
889
+ }
890
+ #else
891
+ LV_UNUSED (obj ); /*Unused*/
892
+ #endif
893
+ }
894
+
857
895
void lv_textarea_cursor_right (lv_obj_t * obj )
858
896
{
859
897
LV_ASSERT_OBJ (obj , MY_CLASS );
@@ -1001,13 +1039,45 @@ static void lv_textarea_event(const lv_obj_class_t * class_p, lv_event_t * e)
1001
1039
lv_event_code_t code = lv_event_get_code (e );
1002
1040
lv_obj_t * obj = lv_event_get_current_target (e );
1003
1041
1042
+ if (code == LV_EVENT_KEY ) {
1043
+ uint32_t c = * ((uint32_t * )lv_event_get_param (e )); /*uint32_t because can be UTF-8*/
1044
+ if (
1045
+ c != LV_KEY_SELECT_RIGHT &&
1046
+ c != LV_KEY_SELECT_LEFT &&
1047
+ c != LV_KEY_SELECT_UP &&
1048
+ c != LV_KEY_SELECT_DOWN
1049
+ ) {
1050
+ lv_textarea_selection_stop (obj );
1051
+ }
1052
+ }
1053
+
1004
1054
if (code == LV_EVENT_FOCUSED ) {
1005
1055
start_cursor_blink (obj );
1006
1056
}
1007
1057
else if (code == LV_EVENT_KEY ) {
1008
1058
uint32_t c = * ((uint32_t * )lv_event_get_param (e )); /*uint32_t because can be UTF-8*/
1009
1059
if (c == LV_KEY_SELECT_ALL )
1010
1060
lv_textarea_selection_all (obj );
1061
+ else if (c == LV_KEY_SELECT_RIGHT ) {
1062
+ lv_textarea_selection_start (obj );
1063
+ lv_textarea_cursor_right (obj );
1064
+ lv_textarea_selection_continue (obj );
1065
+ }
1066
+ else if (c == LV_KEY_SELECT_LEFT ) {
1067
+ lv_textarea_selection_start (obj );
1068
+ lv_textarea_cursor_left (obj );
1069
+ lv_textarea_selection_continue (obj );
1070
+ }
1071
+ else if (c == LV_KEY_SELECT_UP ) {
1072
+ lv_textarea_selection_start (obj );
1073
+ lv_textarea_cursor_up (obj );
1074
+ lv_textarea_selection_continue (obj );
1075
+ }
1076
+ else if (c == LV_KEY_SELECT_DOWN ) {
1077
+ lv_textarea_selection_start (obj );
1078
+ lv_textarea_cursor_down (obj );
1079
+ lv_textarea_selection_continue (obj );
1080
+ }
1011
1081
else if (c == LV_KEY_RIGHT )
1012
1082
lv_textarea_cursor_right (obj );
1013
1083
else if (c == LV_KEY_LEFT )
0 commit comments