From 86db5936822e154dcca279f72801dcae7bb17ec0 Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Fri, 02 Mar 2012 13:01:53 +0000 Subject: Fix session history when the current item is at the beginning of the history Removed conditionals that were checking for back history lenght == 0 to handle the case of an empty tab, and added a proper conditional: a tab is empty if the history list has only one item and that item is None. Signed-off-by: Manuel QuiƱones Acked-by: Simon Schampijer --- (limited to 'browser.py') diff --git a/browser.py b/browser.py index 981aafe..5dea721 100644 --- a/browser.py +++ b/browser.py @@ -432,10 +432,12 @@ class Browser(WebKit.WebView): def get_history(self): """Return the browsing history of this browser.""" back_forward_list = self.get_back_forward_list() - if back_forward_list.get_back_length() == 0: - return '' - items_list = self._items_history_as_list(back_forward_list) + + # If this is an empty tab, return an empty history: + if len(items_list) == 1 and items_list[0] is None: + return [] + history = [] for item in items_list: history.append({'url': item.get_uri(), @@ -462,11 +464,10 @@ class Browser(WebKit.WebView): def set_history_index(self, index): """Go to the item in the history specified by the index.""" back_forward_list = self.get_back_forward_list() - if back_forward_list.get_back_length() != 0: - current_item = index - back_forward_list.get_back_length() - item = back_forward_list.get_nth_item(current_item) - if item is not None: - self.go_to_back_forward_item(item) + current_item = index - back_forward_list.get_back_length() + item = back_forward_list.get_nth_item(current_item) + if item is not None: + self.go_to_back_forward_item(item) def _items_history_as_list(self, history): """Return a list with the items of a WebKit.WebBackForwardList.""" -- cgit v0.9.1