Skip to content
Browse files

Don't save duplicate consecutive commands to history

If the entered command is the same as the last command, don't save
it to history.
  • Loading branch information...
1 parent 04266ee commit aedc76b50ef1de3a64ab6010b4b9b2f3ad6b8a0a @DanielGibson DanielGibson committed Sep 16, 2012
Showing with 10 additions and 3 deletions.
  1. +10 −3 neo/framework/Console.cpp
View
13 neo/framework/Console.cpp
@@ -631,10 +631,17 @@ void idConsoleLocal::KeyDownEvent( int key ) {
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, consoleField.GetBuffer() ); // valid command
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "\n" );
- // copy line to history buffer
- historyEditLines[nextHistoryLine % COMMAND_HISTORY] = consoleField;
- nextHistoryLine++;
+ // copy line to history buffer, if it isn't the same as the last command
+ if ( idStr::Cmp( consoleField.GetBuffer(),
+ historyEditLines[(nextHistoryLine + COMMAND_HISTORY - 1) % COMMAND_HISTORY].GetBuffer()) != 0 )
+ {
+ historyEditLines[nextHistoryLine % COMMAND_HISTORY] = consoleField;
+ nextHistoryLine++;
+ }
+
historyLine = nextHistoryLine;
+ // clear the next line from old garbage, else the oldest history entry turns up when pressing DOWN
+ historyEditLines[nextHistoryLine % COMMAND_HISTORY].Clear();
consoleField.Clear();
consoleField.SetWidthInChars( LINE_WIDTH );

0 comments on commit aedc76b

Please sign in to comment.
Something went wrong with that request. Please try again.