mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:53:52 +00:00
fix deletion when not at end of line and implement ^LEFT and ^RIGHT
This commit is contained in:
parent
4aca8240e5
commit
67fb19c2b9
1 changed files with 45 additions and 8 deletions
|
@ -225,6 +225,11 @@ namespace MWGui
|
||||||
resetReference();
|
resetReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isWhitespace(char c)
|
||||||
|
{
|
||||||
|
return c == ' ' || c == '\t';
|
||||||
|
}
|
||||||
|
|
||||||
void Console::keyPress(MyGUI::Widget* _sender,
|
void Console::keyPress(MyGUI::Widget* _sender,
|
||||||
MyGUI::KeyCode key,
|
MyGUI::KeyCode key,
|
||||||
MyGUI::Char _char)
|
MyGUI::Char _char)
|
||||||
|
@ -233,20 +238,52 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
if(key == MyGUI::KeyCode::W)
|
if(key == MyGUI::KeyCode::W)
|
||||||
{
|
{
|
||||||
std::string text = mCommandLine->getCaption();
|
const auto& caption = mCommandLine->getCaption();
|
||||||
if(text.empty())
|
if(caption.empty())
|
||||||
return;
|
return;
|
||||||
size_t max = text.size();
|
size_t max = mCommandLine->getTextCursor();
|
||||||
while(max > 0 && (text[max - 1] == ' ' || text[max - 1] == '\t' || text[max - 1] == '>'))
|
while(max > 0 && (isWhitespace(caption[max - 1]) || caption[max - 1] == '>'))
|
||||||
max--;
|
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--;
|
max--;
|
||||||
text.resize(max);
|
size_t length = mCommandLine->getTextCursor() - max;
|
||||||
|
if(length > 0)
|
||||||
|
{
|
||||||
|
std::string text = caption;
|
||||||
|
text.erase(max, length);
|
||||||
mCommandLine->setCaption(text);
|
mCommandLine->setCaption(text);
|
||||||
|
mCommandLine->setTextCursor(max);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(key == MyGUI::KeyCode::U)
|
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)
|
else if(key == MyGUI::KeyCode::Tab)
|
||||||
|
|
Loading…
Reference in a new issue