diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index b1ce7061..cc40bc8b 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -527,13 +527,17 @@ void MenuStateJoinGame::keyDown(SDL_KeyboardEvent key) { Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); - //if(key == vkBack) { - if(isKeyPressed(SDLK_BACKSPACE,key) == true) { + string text = labelServerIp.getText(); + if(isKeyPressed(SDLK_BACKSPACE,key) == true && text.length() > 0) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - string text= labelServerIp.getText(); - - if(text.size() > 1) { - text.erase(text.end()-2); + size_t found = text.find_last_of("_"); + if (found == string::npos) { + text.erase(text.end() - 1); + } + else { + if(text.size() > 1) { + text.erase(text.end() - 2); + } } labelServerIp.setText(text); diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index dee16902..c6f17cae 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -941,12 +941,18 @@ bool MenuStateOptions::isInSpecialKeyCaptureEvent() { void MenuStateOptions::keyDown(SDL_KeyboardEvent key) { if(activeInputLabel != NULL) { - //if(key == vkBack) { - if(isKeyPressed(SDLK_BACKSPACE,key) == true) { - string text= activeInputLabel->getText(); - if(text.size() > 1) { - text.erase(text.end()-2); + string text= activeInputLabel->getText(); + if(isKeyPressed(SDLK_BACKSPACE,key) == true && text.length() > 0) { + size_t found = text.find_last_of("_"); + if (found == string::npos) { + text.erase(text.end() - 1); } + else { + if(text.size() > 1) { + text.erase(text.end() - 2); + } + } + activeInputLabel->setText(text); } }