// Modified by:
 // Created:     15.09.00
 // RCS-ID:      $Id$
-// Copyright:   (c) 2000 Vadim Zeitlin
+// Copyright:   (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
 // Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 #endif
 
 #include "wx/clipbrd.h"
+
 #include "wx/textfile.h"
 
 #include "wx/caret.h"
     }
     else // valid sel range
     {
+        // remember the 'to' position as the current position, used to move the
+        // caret there later
+        wxTextPos toOrig = to;
+
         OrderPositions(from, to);
 
         wxCHECK_RET( to <= GetLastPosition(),
         }
         //else: nothing to do
 
-        // the insertion point is put at the end of selection
-        DoSetInsertionPoint(to);
+        // the insertion point is put at the location where the caret was moved
+        DoSetInsertionPoint(toOrig);
     }
 }
 
 wxTextCoord wxTextCtrl::GetRowCount() const
 {
     wxTextCoord count = GetLineCount();
+    if (count == 0)
+        return 0;
     if ( WrapLines() )
     {
         count = GetFirstRowOfLine(count - 1) +