On 7/3/07, Abdelrazak Younes <[EMAIL PROTECTED]> wrote:
Bo Peng wrote:
>> Yes, that's exactly what I proposed in my solution 2. Hopefully for
>> 1.5.1. I mean, 1.5.0 was supposed to be released yesterday...
>
> It should not be that hard,

Be my guest ;-)

Abdel,

Could you please test the attached patch? It limits the copied
paragraphs to 10 so the cost of copySelection is constant when
selecting large pieces of texts.

Cheers,
Bo
Index: src/CutAndPaste.cpp
===================================================================
--- src/CutAndPaste.cpp	(revision 18975)
+++ src/CutAndPaste.cpp	(working copy)
@@ -353,7 +353,7 @@
 
 void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
 	pit_type startpit, pit_type endpit,
-	int start, int end, textclass_type tc, CutStack & cutstack)
+	int start, int end, textclass_type tc, CutStack & cutstack, int sizelimit = 0)
 {
 	BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
 	BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
@@ -361,7 +361,10 @@
 
 	// Clone the paragraphs within the selection.
 	ParagraphList copy_pars(boost::next(pars.begin(), startpit),
-				boost::next(pars.begin(), endpit + 1));
+				boost::next(pars.begin(), 
+				sizelimit > 0 ? std::min(endpit + 1, startpit + sizelimit) : endpit + 1));
+	if (sizelimit > 0 && endpit + 1 > startpit + sizelimit)
+		end = copy_pars.back().size();
 
 	// Remove the end of the last paragraph; afterwards, remove the
 	// beginning of the first paragraph. Keep this order - there may only
@@ -596,7 +599,7 @@
 
 namespace {
 
-void copySelectionToStack(Cursor & cur, CutStack & cutstack)
+void copySelectionToStack(Cursor & cur, CutStack & cutstack, int sizelimit = 0)
 {
 	// this doesn't make sense, if there is no selection
 	if (!cur.selection())
@@ -622,7 +625,7 @@
 			++pos;
 
 		copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(),
-			pos, cur.selEnd().pos(), cur.buffer().params().textclass, cutstack);
+			pos, cur.selEnd().pos(), cur.buffer().params().textclass, cutstack, sizelimit);
 		dirtyTabularStack(false);
 	}
 
@@ -676,15 +679,14 @@
 	       << to_utf8(cur.selectionAsString(true)) << "'."
 	       << endl;
 
-	// FIXME: The two lines below would allow middle-mouse 
-	// pasting that preserves the LyX formatting when the selection
-	// is internal. They would also allow to use the feature on
-	// Windows and Mac. In the future, we may want to optionally enable
-	// this feature via a rc setting.
-	/*
+	// Copy selection to an internal buffer can be a big burden to lyx when
+	// the selection is large (bug 3877). This is why we only save the 
+	// first 10 paragraphs of the selected text. This is not a problem when
+	// this feature is used normally (mouse-select small pieces of 
+	// text and middle button paste) and is consistent with other applications
+	// (e.g. select a large piece of text from firefox and paste). 
 	if (cur.selection())
-		copySelectionToStack(cur, selectionBuffer);
-	*/
+		copySelectionToStack(cur, selectionBuffer, 10);
 
 	// tell X whether we now have a valid selection
 	theSelection().haveSelection(cur.selection());

Reply via email to