From cbc681ddcad9108501098243f7517697acad6f22 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 18 Sep 2011 10:12:34 +0200 Subject: [PATCH] Fixed to try to stay in the current expanded group. --- src/calibre/gui2/tag_browser/model.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index caf55230a5..b01ca60a82 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -1034,10 +1034,19 @@ class TagsModel(QAbstractItemModel): # {{{ def index_for_path(self, path): parent = QModelIndex() - for i in path: - parent = self.index(i, 0, parent) - if not parent.isValid(): - return QModelIndex() + for idx,v in enumerate(path): + tparent = self.index(v, 0, parent) + if not tparent.isValid(): + if v > 0 and idx == len(path) - 1: + # Probably the last item went away. Use the one before it + tparent = self.index(v-1, 0, parent) + if not tparent.isValid(): + # Not valid. Use the last valid index + break + else: + # There isn't one before it. Use the last valid index + break + parent = tparent return parent def index(self, row, column, parent):