Skip to content

Commit

Permalink
Don't destroy the new command being entered in ConsoleView
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LBPHacker committed Sep 14, 2019
1 parent 0e237a1 commit 66ef37e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/gui/console/ConsoleView.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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()));
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/console/ConsoleView.h
Expand Up @@ -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;
Expand Down

0 comments on commit 66ef37e

Please sign in to comment.