commit 644bbf2dae1187a43a79eda1aec0e6da2ef9243e
Author: Elvis Stansvik <elvstone@gmail.com>
Date:   Thu Aug 18 22:41:41 2011 +0200

    Fix crash / no initial cursor dilemma bug:
    
    The PageItem::lastInFrame() function will return -1 when:
    
    1) The frame is empty (no text).
    2) The frame is so small that no text is visible (overflowing).
    
    This led to a crash in CanvasMode::commonDrawTextCursor(...) which tried
    to use this -1 as a parameter to StoryText::item(...). The old "fix"
    that was in place for this in the edit canvas mode was to simply not
    paint the cursor when lastInFrame() returns < 0. This fixed the crash
    but had the unwanted side effect that no cursor was painted when
    activating the edit mode on an empty frame.
    
    This new fix instead changes CanvasMode::commonDrawTextCursor(...) to
    still paint the cursor, but also make sure that it's never using a < 0
    index.
    
    (Note: CanvasMode::commonDrawTextCursor(...) is called
    CanvasMode_Edit::drawTextCursor(...) in 1.5svn. It was moved/renamed in
    my tables repository)

diff --git a/Scribus/scribus/canvasmode.cpp b/Scribus/scribus/canvasmode.cpp
index 51b0bbc..28a94cb 100644
--- a/Scribus/scribus/canvasmode.cpp
+++ b/Scribus/scribus/canvasmode.cpp
@@ -756,7 +756,7 @@ void CanvasMode::commonDrawTextCursor(QPainter* p, PageItem_TextFrame* textframe
 	{
 		// Happens often when typing directly into frame.
 		// And the cursor curses nothing, vertigo.
-		textCursorPos = textframe->lastInFrame();
+		textCursorPos = qMax(0, textframe->lastInFrame());
 		QChar textCursorChar = textframe->itemText.text(textCursorPos);
 		if (textCursorChar == SpecialChars::PARSEP || textCursorChar == SpecialChars::LINEBREAK)
 		{
diff --git a/Scribus/scribus/canvasmode_edit.cpp b/Scribus/scribus/canvasmode_edit.cpp
index b29a729..2c6f5f2 100644
--- a/Scribus/scribus/canvasmode_edit.cpp
+++ b/Scribus/scribus/canvasmode_edit.cpp
@@ -206,10 +206,6 @@ void CanvasMode_Edit::drawControls(QPainter* p)
 
 void CanvasMode_Edit::drawTextCursor ( QPainter *p, PageItem_TextFrame* textframe )
 {
-	//CB: If we have this test in we get no initial cursor placed for a new text frame
-	// but if we do, we crash when we resize.. #9886
-	if(textframe->lastInFrame() < 0)
-		return;
 	if ((!m_longCursorTime && m_blinkTime.elapsed() > qApp->cursorFlashTime() / 2 ) ||
 		(m_longCursorTime && m_blinkTime.elapsed() > qApp->cursorFlashTime() )
 		)
diff --git a/Scribus/scribus/canvasmode_edittable.cpp b/Scribus/scribus/canvasmode_edittable.cpp
index 4b7c467..63002e8 100644
--- a/Scribus/scribus/canvasmode_edittable.cpp
+++ b/Scribus/scribus/canvasmode_edittable.cpp
@@ -337,16 +337,6 @@ void CanvasMode_EditTable::handleMouseDrag(QMouseEvent* event)
 
 void CanvasMode_EditTable::drawTextCursor(QPainter* p)
 {
-	if (m_table->activeCell().textFrame()->lastInFrame() < 0)
-	{
-		/*
-		 * Happens when a single-line text frame overflows and going
-		 * further will the call to commonDrawTextCursor(...) below
-		 * would result in a crash, so we just return instead.
-		 */
-		return;
-	}
-
 	if ((!m_longBlink && m_blinkTime.elapsed() > qApp->cursorFlashTime() / 2)
 		|| (m_longBlink && m_blinkTime.elapsed() > qApp->cursorFlashTime()))
 	{