Skip to content

Commit

Permalink
Shell|Fixed: Command line widget history
Browse files Browse the repository at this point in the history
The history is now bash-like in that entries in the history can be
edited, but the edits are only remembered until Enter is pressed.
  • Loading branch information
skyjake committed Jan 25, 2013
1 parent b2b4f93 commit 644c198
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion doomsday/tools/shell/shell-text/src/commandlinewidget.cpp
Expand Up @@ -35,6 +35,7 @@ struct CommandLineWidget::Instance
struct Command
{
String text;
String original; ///< For undoing editing in history.
int cursor; ///< Index in range [0...text.size()]

Command() : cursor(0) {}
Expand Down Expand Up @@ -91,6 +92,16 @@ struct CommandLineWidget::Instance
}
return false;
}

void restoreTextsToOriginal()
{
for(int i = 0; i < history.size(); ++i)
{
Command &cmd = history[i];
cmd.text = cmd.original;
cmd.cursor = de::min(cmd.cursor, cmd.text.size());
}
}
};

CommandLineWidget::CommandLineWidget(de::String const &name)
Expand Down Expand Up @@ -133,17 +144,21 @@ bool CommandLineWidget::handleEvent(Event const *event)
// Currently back in the history; duplicate the edited entry.
d->history.append(d->command());
}

d->history.last().original = entered;

// Move on.
d->history.append(Instance::Command());
d->historyPos = d->history.size() - 1;
d->updateEditor();
d->restoreTextsToOriginal();

emit commandEntered(entered);

return true;
}

eaten = TextEditWidget::handleControlKey(ev->key());
eaten = TextEditWidget::handleEvent(event);

if(!eaten)
{
Expand Down

0 comments on commit 644c198

Please sign in to comment.