Merge pull request #2415 from Assumeru/unix-console

Unix console hotkeys
pull/541/head
Alexei Dobrohotov 5 years ago committed by GitHub
commit 1a2f51ef6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -149,6 +149,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

@ -1,6 +1,7 @@
#include "console.hpp"
#include <MyGUI_EditBox.h>
#include <MyGUI_InputManager.h>
#include <MyGUI_LayerManager.h>
#include <boost/filesystem.hpp>
@ -224,11 +225,48 @@ namespace MWGui
resetReference();
}
bool isWhitespace(char c)
{
return c == ' ' || c == '\t';
}
void Console::keyPress(MyGUI::Widget* _sender,
MyGUI::KeyCode key,
MyGUI::Char _char)
{
if( key == MyGUI::KeyCode::Tab)
if(MyGUI::InputManager::getInstance().isControlPressed())
{
if(key == MyGUI::KeyCode::W)
{
const auto& caption = mCommandLine->getCaption();
if(caption.empty())
return;
size_t max = mCommandLine->getTextCursor();
while(max > 0 && (isWhitespace(caption[max - 1]) || caption[max - 1] == '>'))
max--;
while(max > 0 && !isWhitespace(caption[max - 1]) && caption[max - 1] != '>')
max--;
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)
{
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::Tab)
{
std::vector<std::string> matches;
listNames();

Loading…
Cancel
Save