From b0506e8ade466a3d2603dec5aa2defe37f8f8d07 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Fri, 19 Feb 2016 19:59:46 -0500 Subject: [PATCH] fix clear on key-return with inputbox ui elements --- src/missionui/chatbox.cpp | 11 ++++++----- src/ui/inputbox.cpp | 9 ++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/missionui/chatbox.cpp b/src/missionui/chatbox.cpp index eda9473..f5dd2a1 100644 --- a/src/missionui/chatbox.cpp +++ b/src/missionui/chatbox.cpp @@ -720,10 +720,8 @@ void chatbox_autosplit_line() send_game_chat_packet(Net_player, msg, MULTI_MSG_ALL,NULL); chatbox_add_line(msg, MY_NET_PLAYER_NUM); - if ( remainder ) { - // display any remainder of text on the next line - Chat_inputbox.set_text(remainder); - } + // display any remainder of text on the next line + Chat_inputbox.set_text(remainder); } else if((Chat_inputbox.pressed() && (strlen(msg) > 0)) || (strlen(msg) >= CHATBOX_MAX_LEN)) { // tack on the null terminator in the boundary case int x = strlen(msg); @@ -733,7 +731,10 @@ void chatbox_autosplit_line() // if I'm the server, then broadcast the packet chatbox_recall_add(msg); send_game_chat_packet(Net_player, msg, MULTI_MSG_ALL,NULL); - chatbox_add_line(msg, MY_NET_PLAYER_NUM); + chatbox_add_line(msg, MY_NET_PLAYER_NUM); + + // display any remainder of text on the next line + Chat_inputbox.set_text(remainder); } } diff --git a/src/ui/inputbox.cpp b/src/ui/inputbox.cpp index bdbbcb6..eae93ad 100644 --- a/src/ui/inputbox.cpp +++ b/src/ui/inputbox.cpp @@ -660,7 +660,14 @@ void UI_INPUTBOX::get_text(char *out) void UI_INPUTBOX::set_text(const char *in) { int in_length; - + + if (in == NULL) { + SDL_strlcpy(text, "", length+1); + position = 0; + + return; + } + in_length = strlen(in); if (in_length > length) SDL_assert(0); // tried to force text into an input box that won't fit into allocated memory -- 2.39.2