summaryrefslogtreecommitdiff
path: root/src/chat.cpp
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2017-12-14 19:47:29 +0100
committerGitHub <noreply@github.com>2017-12-14 19:47:29 +0100
commit6e5109fd46fa93335aa8bc7d5e3edb738980241f (patch)
tree03d7d0e379cb45ecb3b2c401c9743fb0996750f5 /src/chat.cpp
parent551c12391a4ee1ab55fedd92433f740c4a0e2dec (diff)
downloadminetest-6e5109fd46fa93335aa8bc7d5e3edb738980241f.tar.gz
minetest-6e5109fd46fa93335aa8bc7d5e3edb738980241f.tar.bz2
minetest-6e5109fd46fa93335aa8bc7d5e3edb738980241f.zip
Chat: Remove prompt history duplicates (#6762)
Diffstat (limited to 'src/chat.cpp')
-rw-r--r--src/chat.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/chat.cpp b/src/chat.cpp
index a5d82a649..818e261d7 100644
--- a/src/chat.cpp
+++ b/src/chat.cpp
@@ -18,11 +18,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "chat.h"
-#include "debug.h"
-#include "config.h"
-#include "util/strfnd.h"
+
+#include <algorithm>
#include <cctype>
#include <sstream>
+
+#include "config.h"
+#include "debug.h"
+#include "util/strfnd.h"
#include "util/string.h"
#include "util/numeric.h"
@@ -403,8 +406,14 @@ void ChatPrompt::input(const std::wstring &str)
void ChatPrompt::addToHistory(std::wstring line)
{
- if (!line.empty())
+ if (!line.empty() &&
+ (m_history.size() == 0 || m_history.back() != line)) {
+ // Remove all duplicates
+ m_history.erase(std::remove(m_history.begin(), m_history.end(),
+ line), m_history.end());
+ // Push unique line
m_history.push_back(line);
+ }
if (m_history.size() > m_history_limit)
m_history.erase(m_history.begin());
m_history_index = m_history.size();