From 4aca8240e5ed3b3fef006948cdcc51f1d5aa3324 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Thu, 6 Jun 2019 22:09:45 +0200 Subject: [PATCH 1/4] implement ^W and ^U in the console --- apps/openmw/mwgui/console.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index 705e28138..cc900350d 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -229,7 +229,27 @@ namespace MWGui MyGUI::KeyCode key, MyGUI::Char _char) { - if( key == MyGUI::KeyCode::Tab) + if(MyGUI::InputManager::getInstance().isControlPressed()) + { + if(key == MyGUI::KeyCode::W) + { + std::string text = mCommandLine->getCaption(); + if(text.empty()) + return; + size_t max = text.size(); + while(max > 0 && (text[max - 1] == ' ' || text[max - 1] == '\t' || text[max - 1] == '>')) + max--; + while(max > 0 && text[max - 1] != ' ' && text[max - 1] != '\t' && text[max - 1] != '>') + max--; + text.resize(max); + mCommandLine->setCaption(text); + } + else if(key == MyGUI::KeyCode::U) + { + mCommandLine->setCaption(""); + } + } + else if(key == MyGUI::KeyCode::Tab) { std::vector matches; listNames(); From 67fb19c2b925b54af18080ecf4c4f7294ceab466 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Fri, 7 Jun 2019 18:41:35 +0200 Subject: [PATCH 2/4] fix deletion when not at end of line and implement ^LEFT and ^RIGHT --- apps/openmw/mwgui/console.cpp | 53 +++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index cc900350d..c3ec52039 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -225,6 +225,11 @@ namespace MWGui resetReference(); } + bool isWhitespace(char c) + { + return c == ' ' || c == '\t'; + } + void Console::keyPress(MyGUI::Widget* _sender, MyGUI::KeyCode key, MyGUI::Char _char) @@ -233,20 +238,52 @@ namespace MWGui { if(key == MyGUI::KeyCode::W) { - std::string text = mCommandLine->getCaption(); - if(text.empty()) + const auto& caption = mCommandLine->getCaption(); + if(caption.empty()) return; - size_t max = text.size(); - while(max > 0 && (text[max - 1] == ' ' || text[max - 1] == '\t' || text[max - 1] == '>')) + size_t max = mCommandLine->getTextCursor(); + while(max > 0 && (isWhitespace(caption[max - 1]) || caption[max - 1] == '>')) max--; - while(max > 0 && text[max - 1] != ' ' && text[max - 1] != '\t' && text[max - 1] != '>') + while(max > 0 && !isWhitespace(caption[max - 1]) && caption[max - 1] != '>') max--; - text.resize(max); - mCommandLine->setCaption(text); + size_t length = mCommandLine->getTextCursor() - max; + if(length > 0) + { + std::string text = caption; + text.erase(max, length); + mCommandLine->setCaption(text); + mCommandLine->setTextCursor(max); + } } else if(key == MyGUI::KeyCode::U) { - mCommandLine->setCaption(""); + if(mCommandLine->getTextCursor() > 0) + { + std::string text = mCommandLine->getCaption(); + text.erase(0, mCommandLine->getTextCursor()); + mCommandLine->setCaption(text); + mCommandLine->setTextCursor(0); + } + } + else if(key == MyGUI::KeyCode::ArrowRight) + { + const auto& caption = mCommandLine->getCaption(); + size_t pos = mCommandLine->getTextCursor(); + while(pos < caption.size() && (isWhitespace(caption[pos]) || caption[pos] == '-')) + pos++; + while(pos < caption.size() && !isWhitespace(caption[pos]) && caption[pos] != '-') + pos++; + mCommandLine->setTextCursor(pos); + } + else if(key == MyGUI::KeyCode::ArrowLeft) + { + const auto& caption = mCommandLine->getCaption(); + size_t pos = mCommandLine->getTextCursor(); + while(pos > 0 && (isWhitespace(caption[pos - 1]) || caption[pos - 1] == '>')) + pos--; + while(pos > 0 && !isWhitespace(caption[pos - 1]) && caption[pos - 1] != '>') + pos--; + mCommandLine->setTextCursor(pos); } } else if(key == MyGUI::KeyCode::Tab) From cb4664b31bacccf78c1c8e24a2d7cbeb299e3887 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Wed, 3 Jul 2019 22:38:07 +0200 Subject: [PATCH 3/4] Remove arrow key behaviour as it's in MyGUI now --- apps/openmw/mwgui/console.cpp | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index 9c7d1d594..df4bdec5b 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -1,6 +1,7 @@ #include "console.hpp" #include +#include #include #include @@ -264,26 +265,6 @@ namespace MWGui mCommandLine->setTextCursor(0); } } - else if(key == MyGUI::KeyCode::ArrowRight) - { - const auto& caption = mCommandLine->getCaption(); - size_t pos = mCommandLine->getTextCursor(); - while(pos < caption.size() && (isWhitespace(caption[pos]) || caption[pos] == '-')) - pos++; - while(pos < caption.size() && !isWhitespace(caption[pos]) && caption[pos] != '-') - pos++; - mCommandLine->setTextCursor(pos); - } - else if(key == MyGUI::KeyCode::ArrowLeft) - { - const auto& caption = mCommandLine->getCaption(); - size_t pos = mCommandLine->getTextCursor(); - while(pos > 0 && (isWhitespace(caption[pos - 1]) || caption[pos - 1] == '>')) - pos--; - while(pos > 0 && !isWhitespace(caption[pos - 1]) && caption[pos - 1] != '>') - pos--; - mCommandLine->setTextCursor(pos); - } } else if(key == MyGUI::KeyCode::Tab) { From fb9b4a79c12b87197e32f13652da4bcadf1ffc51 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 14 Jul 2019 20:52:36 +0200 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ba7febd1..69311c748 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -145,6 +145,7 @@ Feature #5036: Allow scripted faction leaving Feature #5046: Gamepad thumbstick cursor speed Feature #5051: Provide a separate textures for scrollbars + Feature #5094: Unix like console hotkeys Task #4686: Upgrade media decoder to a more current FFmpeg API Task #4695: Optimize Distant Terrain memory consumption Task #4789: Optimize cell transitions