Skip to content

Commit 6e5109f

Browse files
authoredDec 14, 2017
Chat: Remove prompt history duplicates (#6762)
1 parent 551c123 commit 6e5109f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed
 

Diff for: ‎src/chat.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1818
*/
1919

2020
#include "chat.h"
21-
#include "debug.h"
22-
#include "config.h"
23-
#include "util/strfnd.h"
21+
22+
#include <algorithm>
2423
#include <cctype>
2524
#include <sstream>
25+
26+
#include "config.h"
27+
#include "debug.h"
28+
#include "util/strfnd.h"
2629
#include "util/string.h"
2730
#include "util/numeric.h"
2831

@@ -403,8 +406,14 @@ void ChatPrompt::input(const std::wstring &str)
403406

404407
void ChatPrompt::addToHistory(std::wstring line)
405408
{
406-
if (!line.empty())
409+
if (!line.empty() &&
410+
(m_history.size() == 0 || m_history.back() != line)) {
411+
// Remove all duplicates
412+
m_history.erase(std::remove(m_history.begin(), m_history.end(),
413+
line), m_history.end());
414+
// Push unique line
407415
m_history.push_back(line);
416+
}
408417
if (m_history.size() > m_history_limit)
409418
m_history.erase(m_history.begin());
410419
m_history_index = m_history.size();

0 commit comments

Comments
 (0)