Bookmarks: Improve behavior of "Previous Bookmark"

If the text cursor is currently not at the "current bookmark", it is
more intuitive and useful if "Previous Bookmark" first moves to the
current bookmark, instead of jumping to the one before that.
That solves two issues:
- creating a bookmark, jumping somewhere else, and then going back to
  that bookmark
- deleting a bookmark, and then going to the previous one

Task-number: QTCREATORBUG-20061
Change-Id: I6dbb8c94f4d50ae4cc36e52808029e685be11069
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-04-30 15:39:10 +02:00
parent 80b9f047f6
commit 658d5b5d2c
2 changed files with 14 additions and 1 deletions

View File

@@ -603,7 +603,8 @@ void BookmarkManager::prev()
QModelIndex current = selectionModel()->currentIndex(); QModelIndex current = selectionModel()->currentIndex();
if (!current.isValid()) if (!current.isValid())
return; return;
if (!isAtCurrentBookmark() && gotoBookmark(bookmarkForIndex(current)))
return;
int row = current.row(); int row = current.row();
while (true) { while (true) {
if (row == 0) if (row == 0)
@@ -806,6 +807,17 @@ void BookmarkManager::loadBookmarks()
updateActionStatus(); updateActionStatus();
} }
bool BookmarkManager::isAtCurrentBookmark() const
{
Bookmark *bk = bookmarkForIndex(selectionModel()->currentIndex());
if (!bk)
return true;
IEditor *currentEditor = EditorManager::currentEditor();
return currentEditor
&& currentEditor->document()->filePath() == Utils::FileName::fromString(bk->fileName())
&& currentEditor->currentLine() == bk->lineNumber();
}
// BookmarkViewFactory // BookmarkViewFactory
BookmarkViewFactory::BookmarkViewFactory(BookmarkManager *bm) BookmarkViewFactory::BookmarkViewFactory(BookmarkManager *bm)

View File

@@ -105,6 +105,7 @@ signals:
private: private:
void updateActionStatus(); void updateActionStatus();
void loadBookmarks(); void loadBookmarks();
bool isAtCurrentBookmark() const;
void documentPrevNext(bool next); void documentPrevNext(bool next);