Bug 245279 - History (back button) in documentation viewer doesn't work properly
Summary: History (back button) in documentation viewer doesn't work properly
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Documentation viewer (show other bugs)
Version: 4.0.0
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: 4.0.1
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-21 05:47 UTC by Nicolás Alvarez
Modified: 2010-08-02 17:57 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolás Alvarez 2010-07-21 05:47:26 UTC
Version:           4.0.0 (using KDE 4.4.4) 
OS:                Linux

Page history in the Documentation toolview doesn't work the way one would usually expect, and the way web browsers and other programs work. Going back and switching to another page just adds the new page at the end of the history list, without removing items that followed the current history location, so going back again doesn't take you to the page you were viewing before switching pages.


Reproducible: Always

Steps to Reproduce:
- Open documentation for QWidget.
- Click on QAbstractButton from inheritance list. The QAbstractButton page loads.
- Click the Back button. You return to QWidget.
- Click on QDialog from inheritance list. The QDialog page loads.
- Click the Back button. I'd expect to return to QWidget, but I'm taken to QAbstractButton instead.



(Mostly note to self in case I get around to fixing it myself.) The fix would be in DocumentationView::addHistory in kdevplatform shell/documentationview.cpp. Probably clearing mHistory items between mCurrent and mHistory.end(). Watch out for off-by-one when doing that. Also should investigate if it's possible to write tests.

By the way, the bugzilla component "documentation viewer" is in the kdevelop product, however it's actually part of kdevplatform.
Comment 1 Nicolás Alvarez 2010-07-26 22:22:32 UTC
commit 9611a4c2ad0f5430f2fa4a69e53e389458426b35
Author: Nicolás Alvarez <nicolas.alvarez@gmail.com>
Date:   Fri Jul 23 21:08:55 2010 -0300

    Fix behavior of page history in the documentation viewer.
    
    BUG:245279

diff --git a/shell/documentationview.cpp b/shell/documentationview.cpp
index fe4e0e1..71486f3 100644
--- a/shell/documentationview.cpp
+++ b/shell/documentationview.cpp
@@ -180,6 +180,15 @@ void DocumentationView::addHistory(KSharedPtr< KDevelop::IDocumentation > doc)
 {
     mBack->setEnabled( !mHistory.isEmpty() );
     mForward->setEnabled(false);
+
+    // clear all history following the current item, unless we're already
+    // at the end (otherwise this code crashes when history is empty, which
+    // happens when addHistory is first called on startup to add the
+    // homepage)
+    if (mCurrent+1 < mHistory.end()) {
+        mHistory.erase(mCurrent+1, mHistory.end());
+    }
+
     mHistory.append(doc);
     mCurrent=mHistory.end()-1;
 }
Comment 2 Nicolás Alvarez 2010-07-27 22:01:45 UTC
commit 776ebc2360fb54d5f2e3aed75ff7be9b7527e07b
Author: Nicolás Alvarez <nicolas.alvarez@gmail.com>
Date:   Fri Jul 23 21:08:55 2010 -0300

    backport to stable: Fix behavior of page history in the documentation viewer.
    
    BUG:245279

diff --git a/shell/documentationview.cpp b/shell/documentationview.cpp
index fe4e0e1..71486f3 100644
--- a/shell/documentationview.cpp
+++ b/shell/documentationview.cpp
@@ -180,6 +180,15 @@ void DocumentationView::addHistory(KSharedPtr< KDevelop::IDocumentation > doc)
 {
     mBack->setEnabled( !mHistory.isEmpty() );
     mForward->setEnabled(false);
+
+    // clear all history following the current item, unless we're already
+    // at the end (otherwise this code crashes when history is empty, which
+    // happens when addHistory is first called on startup to add the
+    // homepage)
+    if (mCurrent+1 < mHistory.end()) {
+        mHistory.erase(mCurrent+1, mHistory.end());
+    }
+
     mHistory.append(doc);
     mCurrent=mHistory.end()-1;
 }
Comment 3 Nicolás Alvarez 2010-08-02 17:57:34 UTC
commit 88171a9a7e301406567dde04ebe6237d5d4d4d17
Author: Nicolás Alvarez <nicolas.alvarez@gmail.com>
Date:   Fri Jul 23 21:08:55 2010 -0300

    Fix behavior of page history in the documentation viewer.
    
    BUG:245279

diff --git a/shell/documentationview.cpp b/shell/documentationview.cpp
index fe4e0e1..71486f3 100644
--- a/shell/documentationview.cpp
+++ b/shell/documentationview.cpp
@@ -180,6 +180,15 @@ void DocumentationView::addHistory(KSharedPtr< KDevelop::IDocumentation > doc)
 {
     mBack->setEnabled( !mHistory.isEmpty() );
     mForward->setEnabled(false);
+
+    // clear all history following the current item, unless we're already
+    // at the end (otherwise this code crashes when history is empty, which
+    // happens when addHistory is first called on startup to add the
+    // homepage)
+    if (mCurrent+1 < mHistory.end()) {
+        mHistory.erase(mCurrent+1, mHistory.end());
+    }
+
     mHistory.append(doc);
     mCurrent=mHistory.end()-1;
 }