moveToPost('prev') does not work across duplicate article id

Development-related discussion, including bundled plugins
User avatar
gmargo
Bear Rating Disaster
Bear Rating Disaster
Posts: 62
Joined: 08 Jan 2012, 22:33
Location: Silicon Valley

moveToPost('prev') does not work across duplicate article id

Postby gmargo » 11 Mar 2012, 20:47

If the preferences are set to "Allow duplicate posts", then when reading a category or virtual feed, there may occur adjacent identical article ids. The keystroke logic handling the 'previous article' request does not back up the list correctly.

The following patch fixes this. It also eliminates unnecessary calls to get{First,Last}VisibleHeadlineId().

Code: Select all

diff --git a/js/viewfeed.js b/js/viewfeed.js
index 880abc6..7ab7f80 100644
--- a/js/viewfeed.js
+++ b/js/viewfeed.js
@@ -493,13 +493,23 @@ function moveToPost(mode) {
       }
 
       if (active_post_id == false) {
-         next_id = getFirstVisibleHeadlineId();
-         prev_id = getLastVisibleHeadlineId();
+         next_id = rows[0];
+         prev_id = rows[rows.length-1];
       } else {
          for (var i = 0; i < rows.length; i++) {
             if (rows[i] == active_post_id) {
-               prev_id = rows[i-1];
-               next_id = rows[i+1];
+               // Account for adjacent identical article ids.
+
+               if (i > 0)
+                  prev_id = rows[i-1];
+
+               for (var j = i+1; j < rows.length; j++) {
+                  if (rows[j] != active_post_id) {
+                     next_id = rows[j];
+                     break;
+                  }
+               }
+               break;
             }
          }
       }

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: moveToPost('prev') does not work across duplicate articl

Postby fox » 12 Mar 2012, 13:54

Thanks for the patch. One thing though, in the future please don't inline patches in the post, because tab information is lost and I have to apply everything by hand.

User avatar
gmargo
Bear Rating Disaster
Bear Rating Disaster
Posts: 62
Joined: 08 Jan 2012, 22:33
Location: Silicon Valley

Re: moveToPost('prev') does not work across duplicate articl

Postby gmargo » 12 Mar 2012, 17:29

fox wrote:please don't inline patches in the post, because tab information is lost


I did not know that; I will attach patches instead. Thanks.


Return to “Development”

Who is online

Users browsing this forum: No registered users and 1 guest