mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Improve chat history (#12975)
This commit is contained in:
parent
8fded9d990
commit
2f9f0c0900
2 changed files with 103 additions and 43 deletions
24
src/chat.h
24
src/chat.h
|
@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "irrlichttypes.h"
|
||||
#include "util/enriched_string.h"
|
||||
#include "util/Optional.h"
|
||||
#include "settings.h"
|
||||
|
||||
// Chat console related classes
|
||||
|
@ -172,10 +173,10 @@ public:
|
|||
void addToHistory(const std::wstring &line);
|
||||
|
||||
// Get current line
|
||||
std::wstring getLine() const { return m_line; }
|
||||
std::wstring getLine() const { return getLineRef(); }
|
||||
|
||||
// Get section of line that is currently selected
|
||||
std::wstring getSelection() const { return m_line.substr(m_cursor, m_cursor_len); }
|
||||
std::wstring getSelection() const { return getLineRef().substr(m_cursor, m_cursor_len); }
|
||||
|
||||
// Clear the current line
|
||||
void clear();
|
||||
|
@ -233,18 +234,33 @@ public:
|
|||
void cursorOperation(CursorOp op, CursorOpDir dir, CursorOpScope scope);
|
||||
|
||||
protected:
|
||||
const std::wstring &getLineRef() const;
|
||||
|
||||
std::wstring &makeLineRef();
|
||||
|
||||
// set m_view to ensure that 0 <= m_view <= m_cursor < m_view + m_cols
|
||||
// if line can be fully shown, set m_view to zero
|
||||
// else, also ensure m_view <= m_line.size() + 1 - m_cols
|
||||
void clampView();
|
||||
|
||||
private:
|
||||
struct HistoryEntry {
|
||||
std::wstring line;
|
||||
// If line is edited, saved holds the unedited version.
|
||||
Optional<std::wstring> saved;
|
||||
|
||||
HistoryEntry(const std::wstring &line): line(line) {}
|
||||
|
||||
bool operator==(const HistoryEntry &other);
|
||||
bool operator!=(const HistoryEntry &other) { return !(*this == other); }
|
||||
};
|
||||
|
||||
// Prompt prefix
|
||||
std::wstring m_prompt = L"";
|
||||
// Currently edited line
|
||||
// Non-historical edited line
|
||||
std::wstring m_line = L"";
|
||||
// History buffer
|
||||
std::vector<std::wstring> m_history;
|
||||
std::vector<HistoryEntry> m_history;
|
||||
// History index (0 <= m_history_index <= m_history.size())
|
||||
u32 m_history_index = 0;
|
||||
// Maximum number of history entries
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue