From 07cc38e9cbd3dafe1373fa59aedbe7fb868cfd68 Mon Sep 17 00:00:00 2001
From: Oz Linden <oz@lindenlab.com>
Date: Fri, 9 Nov 2012 15:12:15 -0500
Subject: [PATCH] STORM-1855: Improve performance of pasting large blocks of
 text in the script editor

---
 doc/contributions.txt       |  3 +++
 indra/llui/lltexteditor.cpp | 24 ++++++++++++++++--------
 indra/llui/lltexteditor.h   |  2 +-
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/doc/contributions.txt b/doc/contributions.txt
index e20b7b83c5e..39d4ea269ee 100644
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -496,6 +496,8 @@ Ima Mechanique
 	STORM-959
 	STORM-1175
 	STORM-1708
+	STORM-1855
+	VWR-20553
 Imnotgoing Sideways
 Inma Rau
 Innula Zenovka
@@ -1031,6 +1033,7 @@ Satanello Miami
 Satomi Ahn
 	STORM-501
 	STORM-229
+	VWR-20553
 	VWR-24502
 Scrim Pinion
 Scrippy Scofield
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index 144b6960a1b..1e3a99c0883 100644
--- a/indra/llui/lltexteditor.cpp
+++ b/indra/llui/lltexteditor.cpp
@@ -1095,7 +1095,8 @@ void LLTextEditor::addChar(llwchar wc)
 
 	setCursorPos(mCursorPos + addChar( mCursorPos, wc ));
 }
-void LLTextEditor::addLineBreakChar()
+
+void LLTextEditor::addLineBreakChar(BOOL group_together)
 {
 	if( !getEnabled() )
 	{
@@ -1113,7 +1114,7 @@ void LLTextEditor::addLineBreakChar()
 	LLStyleConstSP sp(new LLStyle(LLStyle::Params()));
 	LLTextSegmentPtr segment = new LLLineBreakTextSegment(sp, mCursorPos);
 
-	S32 pos = execute(new TextCmdAddChar(mCursorPos, FALSE, '\n', segment));
+	S32 pos = execute(new TextCmdAddChar(mCursorPos, group_together, '\n', segment));
 	
 	setCursorPos(mCursorPos + pos);
 }
@@ -1436,21 +1437,28 @@ void LLTextEditor::pasteHelper(bool is_primary)
 	std::basic_string<llwchar>::size_type start = 0;
 	std::basic_string<llwchar>::size_type pos = clean_string.find('\n',start);
 	
-	while(pos!=-1)
+	while((pos != -1) && (pos != clean_string.length() -1))
 	{
 		if(pos!=start)
 		{
 			std::basic_string<llwchar> str = std::basic_string<llwchar>(clean_string,start,pos-start);
-			setCursorPos(mCursorPos + insert(mCursorPos, str, FALSE, LLTextSegmentPtr()));
+			setCursorPos(mCursorPos + insert(mCursorPos, str, TRUE, LLTextSegmentPtr()));
 		}
-		addLineBreakChar();
-		
+		addLineBreakChar(TRUE);			// Add a line break and group with the next addition.
+
 		start = pos+1;
 		pos = clean_string.find('\n',start);
 	}
 
-	std::basic_string<llwchar> str = std::basic_string<llwchar>(clean_string,start,clean_string.length()-start);
-	setCursorPos(mCursorPos + insert(mCursorPos, str, FALSE, LLTextSegmentPtr()));
+	if (pos != start)
+	{
+		std::basic_string<llwchar> str = std::basic_string<llwchar>(clean_string,start,clean_string.length()-start);
+		setCursorPos(mCursorPos + insert(mCursorPos, str, FALSE, LLTextSegmentPtr()));
+	}
+	else
+	{
+		addLineBreakChar(FALSE);		// Add a line break and end the grouping.
+	}
 
 	deselect();
 
diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h
index 40821ae9fbc..7d2dd09a284 100644
--- a/indra/llui/lltexteditor.h
+++ b/indra/llui/lltexteditor.h
@@ -239,7 +239,7 @@ class LLTextEditor :
 	// Undoable operations
 	void			addChar(llwchar c); // at mCursorPos
 	S32				addChar(S32 pos, llwchar wc);
-	void			addLineBreakChar();
+	void			addLineBreakChar(BOOL group_together = FALSE);
 	S32				overwriteChar(S32 pos, llwchar wc);
 	void			removeChar();
 	S32 			removeChar(S32 pos);
-- 
GitLab