]> git.sesse.net Git - vlc/commitdiff
Qt4_message: when the cursor it at the end, scroll down automatically.
authorRémi Duraffort <ivoire@videolan.org>
Mon, 12 Jan 2009 16:14:55 +0000 (17:14 +0100)
committerRémi Duraffort <ivoire@videolan.org>
Mon, 12 Jan 2009 16:19:38 +0000 (17:19 +0100)
modules/gui/qt4/dialogs/messages.cpp

index 538de9479585a6099e07ec65ed8627a736f178bf..48d4b674a0b5e1f93db5752353d0e686e15af48f 100644 (file)
@@ -182,6 +182,8 @@ void MessagesDialog::sinkMessage (msg_item_t *item, unsigned)
     int endPos = messages->textCursor().selectionEnd();
 
     messages->moveCursor( QTextCursor::End );
+    if( startPos == endPos && messages->textCursor().selectionEnd() == endPos )
+        endPos = 0;
     messages->setFontItalic( true );
     messages->setTextColor( "darkBlue" );
     messages->insertPlainText( qfu( item->psz_module ) );
@@ -215,11 +217,18 @@ void MessagesDialog::sinkMessage (msg_item_t *item, unsigned)
     messages->ensureCursorVisible();
 
     // Restoring saved cursor selection
-    QTextCursor cur = messages->textCursor();
-    cur.movePosition( QTextCursor::Start );
-    cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, startPos );
-    cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, endPos - startPos );
-    messages->setTextCursor( cur );
+    // If the cursor was at this end, put it at the end,
+    // so we don't need to scroll down.
+    if( endPos == 0 )
+        messages->moveCursor( QTextCursor::End );
+    else
+    {
+        QTextCursor cur = messages->textCursor();
+        cur.movePosition( QTextCursor::Start );
+        cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, startPos );
+        cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, endPos - startPos );
+        messages->setTextCursor( cur );
+    }
 }
 void MessagesDialog::customEvent( QEvent *event )
 {