Issue 45248

Summary: Undo for enhanced Paste Special of Unformatted Text
Product: Calc Reporter: naveen_kv <hi.naveen.kv>
Component: editingAssignee: ooo
Status: CLOSED DUPLICATE QA Contact: issues@sc <issues>
Severity: Trivial    
Priority: P3 CC: issues, jody, mmeeks, muthusuba, stx123
Version: OOo 2.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Issue Type: PATCH Latest Confirmation in: ---
Developer Difficulty: ---

Description naveen_kv 2005-03-17 07:57:08 UTC
The problem was,

Description of Problem:
When you copy formatted text from another source (say, text displayed in a
browser window) and then go into Calc and select Edit | Paste Special, and
then select "Unformatted Text", once the paste operation is completed, it
does not display the text. 

Sometimes, it displays parts of the text but often it doesn't display anything.

If you flip to another application and then flip back to Calc, you see the
text, so it's "there", but it's not initially.


Steps to reproduce the problem:
1. Copy some formatted text from another source.
2. Create a new spreadsheet
3. Place your cursor into a cell
4. Select Edit | Paste Special
5. Select the "Unformatted Text" option
6. Accept the defaults in the "Text Import" dialog that's shown
7. Notice that some (most or all, most commonly) text is not visible.

Actual Results:
You can't see all of the pasted text.

Expected Results:
To see all of the pasted text.

How often does this happen? 
All the time when I do the Paste Special option as described above.


Patch To this problem:

this problem can be solved with the following patch. it also solves the problem 
of undo with paste special.

here is the patch :


--- impex.cxx.orig	2005-03-12 16:16:33.215914400 +0530
+++ impex.cxx	2005-03-12 16:19:00.531519024 +0530
@@ -1070,6 +1072,8 @@
 	if (!pExtOptions)
 		return Text2Doc( rStrm );
 
+	StartPaste();	// Undo & others are taken care, fix for #65217
+
 	ULONG nOldPos = rStrm.Tell();
 	rStrm.Seek( STREAM_SEEK_TO_END );
 	ScProgress aProgress( pDocSh, ScGlobal::GetRscString( STR_LOAD_DOC ), 
rStrm.Tell() - nOldPos );
@@ -1084,6 +1088,8 @@
 	SCCOL nStartCol = aRange.aStart.Col();
 	SCROW nStartRow = aRange.aStart.Row();
 	SCTAB nTab = aRange.aStart.Tab();
+	SCCOL nEndCol = aRange.aEnd.Col();	// fix for #65217
+	SCROW nEndRow = aRange.aEnd.Row();	// fix for #65217
 
 	BOOL	bFixed			= pExtOptions->IsFixedLen();
 	const String& rSeps     = pExtOptions->GetFieldSeps();
@@ -1190,6 +1196,10 @@
 			bOverflow = TRUE;			// beim Import 
Warnung ausgeben
 			break;
 		}
+
+		// Find the correct End Col and End Row, fix for #65217
+		if(nCol>nEndCol) nEndCol=nCol;
+		if(nRow>nEndRow) nEndRow=nRow;
 	}
 
 	ScColumn::bDoubleAlloc = bOld;
@@ -1198,6 +1208,11 @@
     delete pEnglishTransliteration;
 	delete pEnglishCalendar;
Comment 1 frank 2005-03-17 09:04:44 UTC
Hi Niklas,

please have a look at this one.

Frank
Comment 2 niklas.nebel 2005-03-21 17:11:28 UTC
Something is missing at the end of the patch. But i don't see how this is
supposed to work, as the initial StartPaste copies only the first cell.

The whole problem doesn't occur in official builds (issue 15509 is still open),
so it's no urgent issue, and I'll set the target to "later".
Comment 3 muthusuba 2005-04-27 07:20:55 UTC
oops sorry for the partial patch (on behalf of naveen_kv).

here's a proper one:
Comment 4 muthusuba 2005-04-27 07:27:01 UTC
oops, sorry for the partial patch (on behalf of naveen_kv)

here's the complete one:

--- sc/source/ui/docshell/impex.cxx	2005-03-12 16:16:33.215914400 +0530
+++ sc/source/ui/docshell/impex.cxx	2005-03-12 16:19:00.531519024 +0530
@@ -1070,6 +1072,8 @@
 	if (!pExtOptions)
 		return Text2Doc( rStrm );
 
+	StartPaste();	// Undo & others are taken care
+
 	ULONG nOldPos = rStrm.Tell();
 	rStrm.Seek( STREAM_SEEK_TO_END );
 	ScProgress aProgress( pDocSh, ScGlobal::GetRscString( STR_LOAD_DOC ),
rStrm.Tell() - nOldPos );
@@ -1084,6 +1088,8 @@
 	SCCOL nStartCol = aRange.aStart.Col();
 	SCROW nStartRow = aRange.aStart.Row();
 	SCTAB nTab = aRange.aStart.Tab();
+	SCCOL nEndCol = aRange.aEnd.Col();
+	SCROW nEndRow = aRange.aEnd.Row();
 
 	BOOL	bFixed			= pExtOptions->IsFixedLen();
 	const String& rSeps     = pExtOptions->GetFieldSeps();
@@ -1190,6 +1196,10 @@
 			bOverflow = TRUE;			// beim Import Warnung ausgeben
 			break;
 		}
+
+		// Find the correct End Col and End Row
+		if( nCol>nEndCol ) nEndCol = nCol;
+		if( nRow>nEndRow ) nEndRow = nRow;
 	}
 
 	ScColumn::bDoubleAlloc = bOld;
@@ -1198,6 +1208,11 @@
     delete pEnglishTransliteration;
 	delete pEnglishCalendar;
 
+	// Set End Row and End Col so that the page is refreshed correctly
+	aRange.aEnd.SetCol( nEndCol );
+	aRange.aEnd.SetRow( nEndRow );
+	EndPaste();		// Paste was successful, refresh, etc.
+
 	return TRUE;
 }
 
Comment 5 niklas.nebel 2005-05-02 17:11:47 UTC
Undo doesn't work if the range wasn't empty before, because StartPaste, which
copies the cells for undo, is called before the range size is known (the end
column and row are off by 1, too).
Comment 6 muthusuba 2005-05-03 06:05:47 UTC
heres (my) updated version:
this would actually iterate twice: once without actual paste, to find the range
and the next time - to paste.

--- sc/source/ui/docshell/impex.cxx	2005-04-14 09:50:04.000000000 +0530
+++ sc/source/ui/docshell/impex.cxx	2005-05-03 10:29:04.727361887 +0530
@@ -1084,6 +1084,8 @@ BOOL ScImportExport::ExtText2Doc( SvStre
 	SCCOL nStartCol = aRange.aStart.Col();
 	SCROW nStartRow = aRange.aStart.Row();
 	SCTAB nTab = aRange.aStart.Tab();
+	SCCOL nEndCol = aRange.aEnd.Col();
+	SCROW nEndRow = aRange.aEnd.Row();
 
 	BOOL	bFixed			= pExtOptions->IsFixedLen();
 	const String& rSeps     = pExtOptions->GetFieldSeps();
@@ -1127,6 +1129,14 @@ BOOL ScImportExport::ExtText2Doc( SvStre
 		if ( rStrm.IsEof() )
 			break;
 	}
+
+	bool bGetRange = FALSE;
+	nOldPos = rStrm.Tell();
+
+	do
+	{
+	bGetRange = !bGetRange;	// Toggle
+
 	for( ;; )
 	{
 		rStrm.ReadCsvLine( aLine, !bFixed, rSeps, cStr);
@@ -1144,9 +1154,12 @@ BOOL ScImportExport::ExtText2Doc( SvStre
 				{
 					xub_StrLen nStart = pColStart[i];
 					xub_StrLen nNext = ( i+1 < nInfoCount ) ? pColStart[i+1] : nLineLen;
-					aCell = lcl_GetFixed( aLine, nStart, nNext );
-					bMultiLine |= lcl_PutString( pDoc, nCol, nRow, nTab, aCell, pColFormat[i],
-                        aTransliteration, aCalendar, pEnglishTransliteration,
pEnglishCalendar );
+					if( !bGetRange )
+					{
+						aCell = lcl_GetFixed( aLine, nStart, nNext );
+						bMultiLine |= lcl_PutString( pDoc, nCol, nRow, nTab, aCell, pColFormat[i],
+	                    aTransliteration, aCalendar, pEnglishTransliteration,
pEnglishCalendar );
+					}
 					++nCol;
 				}
 			}
@@ -1172,7 +1185,8 @@ BOOL ScImportExport::ExtText2Doc( SvStre
 				}
 				if ( nFmt != SC_COL_SKIP )
 				{
-					bMultiLine |= lcl_PutString( pDoc, nCol, nRow, nTab, aCell, nFmt,
+					if( !bGetRange )
+						bMultiLine |= lcl_PutString( pDoc, nCol, nRow, nTab, aCell, nFmt,
                         aTransliteration, aCalendar, pEnglishTransliteration,
pEnglishCalendar );
 					++nCol;
 				}
@@ -1190,7 +1204,24 @@ BOOL ScImportExport::ExtText2Doc( SvStre
 			bOverflow = TRUE;			// beim Import Warnung ausgeben
 			break;
 		}
+
+		// Find the correct End Col and End Row
+		if( bGetRange )
+		{
+			if(nCol>nEndCol) nEndCol=nCol;
+			if(nRow>nEndRow) nEndRow=nRow;
+		}
 	}
+		if( bGetRange )
+		{
+			aRange.aEnd.SetCol( nEndCol - 1 );
+			aRange.aEnd.SetRow( nEndRow - 1 );
+			StartPaste();		// Start the Paste, in the next iteration the actual paste is 
+								// performed.
+			rStrm.Seek( nOldPos );
+			nRow = nStartRow;
+		}
+	} while(bGetRange);
 
 	ScColumn::bDoubleAlloc = bOld;
 	pDoc->DoColResize( nTab, 0, MAXCOL, 0 );
@@ -1198,6 +1229,8 @@ BOOL ScImportExport::ExtText2Doc( SvStre
     delete pEnglishTransliteration;
 	delete pEnglishCalendar;
 
+	EndPaste();		// Paste was successful, refresh, etc.
+
 	return TRUE;
 }
 
Comment 7 stx123 2006-03-15 16:34:20 UTC
Let's reconsider the target. Niklas would you have a look at the revised patch.
Comment 8 niklas.nebel 2006-09-15 16:48:38 UTC
Eike, you should keep this in mind (Undo) when handling issue 15509.
Comment 9 ooo 2006-09-25 12:56:05 UTC
Accepted.
Comment 10 ooo 2006-09-28 14:10:52 UTC
Aligning target with issue 15509.
Comment 11 ooo 2006-10-05 23:43:41 UTC
Implemented with slight corrections with issue 15509.

*** This issue has been marked as a duplicate of 15509 ***
Comment 12 ooo 2006-10-05 23:44:04 UTC
Closing.