From e643bcfc9825ac1880fcac822cb4bfd05fb9a392 Mon Sep 17 00:00:00 2001 From: Lirusaito Date: Fri, 18 Jan 2019 23:21:23 -0500 Subject: [PATCH] Fix the ran off segmentation end bug properly (Torric's Notes bug) Default segments are now any segment that have no distinct features, these segments can be combined into a contiguous segment to save space and to cut down on calculation complexity! --- indra/llui/lltexteditor.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index fe2a31484..d044dd560 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -661,8 +661,7 @@ void LLTextEditor::setText(const LLStringExplicit &utf8str) //LLStringUtil::removeCRLF(text); // appendText modifies mCursorPos... - LLStyleSP style(new LLStyle(TRUE, mReadOnly ? mReadOnlyFgColor : mFgColor, LLStringUtil::null)); - appendText(utf8str, false, false, style); + appendText(utf8str, false, false); // ...so move cursor to top after appending text setCursorPos(0); @@ -4439,7 +4438,8 @@ void LLTextEditor::appendAndHighlightTextImpl(const std::string& new_text, S32 h LLWString wide_text; wide_text = utf8str_to_wstring(new_text); - insertStringNoUndo(getLength(), utf8str_to_wstring(new_text)); + auto length = getLength(); + auto insert_len = length + insertStringNoUndo(length, utf8str_to_wstring(new_text)); if (stylep) { @@ -4448,6 +4448,21 @@ void LLTextEditor::appendAndHighlightTextImpl(const std::string& new_text, S32 h LLTextSegmentPtr segment = new LLTextSegment(stylep, segment_start, segment_end); mSegments.push_back(segment); } + else // If no style, still make a segment, + { + auto segment = mSegments.empty() ? nullptr : mSegments.back(); + if (!segment || !segment->getIsDefault()) + { + LLColor4& text_color = (mReadOnly ? mReadOnlyFgColor : mFgColor); + LLTextSegmentPtr segment = new LLTextSegment(text_color, length, insert_len); + segment->setIsDefault(true); // call it a default segment so we can consolidate later. + mSegments.push_back(segment); + } + else // It's later! + { + segment->setEnd(insert_len); + } + } } // Set the cursor and scroll position