Don't destroy the new command being entered in ConsoleView

Not a perfect solution as it doesn't remember the modifications
made to previous commands, but it's more common to be concerned
about the command being entered than about the changes made to
the previous commands.
This commit is contained in:
Tamás Bálint Misius 2019-09-14 19:38:49 +02:00
parent 0e237a1f4b
commit 66ef37e778
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 16 additions and 1 deletions

View File

@ -58,6 +58,10 @@ void ConsoleView::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ct
c->NextCommand();
break;
case SDLK_UP:
if (editingNewCommand)
{
newCommand = commandField->GetText();
}
c->PreviousCommand();
break;
default:
@ -105,7 +109,16 @@ void ConsoleView::NotifyPreviousCommandsChanged(ConsoleModel * sender)
void ConsoleView::NotifyCurrentCommandChanged(ConsoleModel * sender)
{
commandField->SetText(sender->GetCurrentCommand().Command);
bool oldEditingNewCommand = editingNewCommand;
editingNewCommand = sender->GetCurrentCommandIndex() >= sender->GetPreviousCommands().size();
if (!oldEditingNewCommand && editingNewCommand)
{
commandField->SetText(newCommand);
}
else
{
commandField->SetText(sender->GetCurrentCommand().Command);
}
commandField->SetDisplayText(c->FormatCommand(commandField->GetText()));
}

View File

@ -18,6 +18,8 @@ class ConsoleView: public ui::Window
ui::Textbox * commandField;
std::vector<ui::Label*> commandList;
bool doClose = false;
String newCommand;
bool editingNewCommand = true;
public:
ConsoleView();
void OnDraw() override;