From e7dd71528943ebcac405c9b3e65350152ff22c19 Mon Sep 17 00:00:00 2001 From: MuddledBox <101580720+MuddledBox@users.noreply.github.com> Date: Sun, 20 Mar 2022 06:25:08 -0500 Subject: [PATCH] Keyboard enhance shift (#1042) --- applications/gui/modules/text_input.c | 39 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/applications/gui/modules/text_input.c b/applications/gui/modules/text_input.c index d42f9dcf..9390fa7c 100755 --- a/applications/gui/modules/text_input.c +++ b/applications/gui/modules/text_input.c @@ -131,7 +131,11 @@ static const bool char_is_lowercase(char letter) { } static const char char_to_uppercase(const char letter) { - return (letter - 0x20); + if(isalpha(letter)) { + return (letter - 0x20); + } else { + return letter; + } } static void text_input_backspace_cb(TextInputModel* model) { @@ -305,12 +309,16 @@ static void text_input_handle_right(TextInput* text_input) { }); } -static void text_input_handle_ok(TextInput* text_input) { +static void text_input_handle_ok(TextInput* text_input, bool shift) { with_view_model( text_input->view, (TextInputModel * model) { char selected = get_selected_char(model); uint8_t text_length = strlen(model->text_buffer); + if(shift) { + selected = char_to_uppercase(selected); + } + if(selected == ENTER_KEY) { if(model->validator_callback && (!model->validator_callback( model->text_buffer, @@ -343,7 +351,7 @@ static bool text_input_view_input_callback(InputEvent* event, void* context) { furi_assert(text_input); bool consumed = false; - if(event->type == InputTypeShort || event->type == InputTypeRepeat) { + if(event->type == InputTypeShort) { with_view_model( text_input->view, (TextInputModel * model) { if(model->valadator_message_visible) { @@ -372,7 +380,7 @@ static bool text_input_view_input_callback(InputEvent* event, void* context) { consumed = true; break; case InputKeyOk: - text_input_handle_ok(text_input); + text_input_handle_ok(text_input, false); consumed = true; break; default: @@ -395,6 +403,29 @@ static bool text_input_view_input_callback(InputEvent* event, void* context) { consumed = true; } + // Allow shift key on long press + if(event->type == InputTypeLong && event->key == InputKeyOk) { + with_view_model( + text_input->view, (TextInputModel * model) { + if(model->valadator_message_visible) { + if(event->key == InputKeyBack) { + consumed = true; + } + } + model->valadator_message_visible = false; + return false; + }); + + switch(event->key) { + case InputKeyOk: + text_input_handle_ok(text_input, true); + consumed = true; + break; + default: + break; + } + } + return consumed; }