mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 09:15:29 +01:00 
			
		
		
		
	Chat: Remove prompt history duplicates (#6762)
This commit is contained in:
		
							
								
								
									
										17
									
								
								src/chat.cpp
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								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();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user