]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/chat.cpp
src/environment.cpp: Fix NULL pointer dereference
[dragonfireclient.git] / src / chat.cpp
index 0bd5c16709bb54565f677e7d34123cd6af173608..50391d39b0ee8abbfc07fe1ea30bdcf95be6fe90 100644 (file)
@@ -83,7 +83,7 @@ u32 ChatBuffer::getScrollback() const
 
 const ChatLine& ChatBuffer::getLine(u32 index) const
 {
-       assert(index < getLineCount());
+       assert(index < getLineCount()); // pre-condition
        return m_unformatted[index];
 }
 
@@ -107,7 +107,8 @@ void ChatBuffer::deleteOldest(u32 count)
                // keep m_formatted in sync
                if (del_formatted < m_formatted.size())
                {
-                       assert(m_formatted[del_formatted].first);
+
+                       sanity_check(m_formatted[del_formatted].first);
                        ++del_formatted;
                        while (del_formatted < m_formatted.size() &&
                                        !m_formatted[del_formatted].first)
@@ -151,7 +152,7 @@ void ChatBuffer::reformat(u32 cols, u32 rows)
        }
        else if (cols != m_cols || rows != m_rows)
        {
-               // TODO: Avoid reformatting ALL lines (even inivisble ones)
+               // TODO: Avoid reformatting ALL lines (even invisible ones)
                // each time the console size changes.
 
                // Find out the scroll position in *unformatted* lines
@@ -407,6 +408,15 @@ void ChatPrompt::input(wchar_t ch)
        m_nick_completion_end = 0;
 }
 
+void ChatPrompt::input(const std::wstring &str)
+{
+       m_line.insert(m_cursor, str);
+       m_cursor += str.size();
+       clampView();
+       m_nick_completion_start = 0;
+       m_nick_completion_end = 0;
+}
+
 std::wstring ChatPrompt::submit()
 {
        std::wstring line = m_line;
@@ -501,7 +511,7 @@ void ChatPrompt::nickCompletion(const std::list<std::string>& names, bool backwa
                {
                        std::wstring completion = narrow_to_wide(*i);
                        if (prefix_start == 0)
-                               completion += L":";
+                               completion += L": ";
                        completions.push_back(completion);
                }
        }
@@ -531,7 +541,7 @@ void ChatPrompt::nickCompletion(const std::list<std::string>& names, bool backwa
                        }
                }
        }
-       std::wstring replacement = completions[replacement_index] + L" ";
+       std::wstring replacement = completions[replacement_index];
        if (word_end < m_line.size() && isspace(word_end))
                ++word_end;
 
@@ -765,5 +775,5 @@ void ChatBackend::scrollPageDown()
 
 void ChatBackend::scrollPageUp()
 {
-       m_console_buffer.scroll(-m_console_buffer.getRows());
+       m_console_buffer.scroll(-(s32)m_console_buffer.getRows());
 }