From d6b1b57cb7ca9cb8ff6a83290831d74b91c31ccb Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Sat, 3 Aug 2024 22:25:33 +0200 Subject: [PATCH] BookmarksToolbar: Fix drag and drop - Fix crash - Fix bookmark final position Cherry Picked from: 06ea9c6b9cee5037794cfd948ed61ffc1e97386e Signed-off-by: Juraj Oravec --- src/lib/bookmarks/bookmarkstoolbar.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/bookmarks/bookmarkstoolbar.cpp b/src/lib/bookmarks/bookmarkstoolbar.cpp index 294f524de..2d5429b9f 100644 --- a/src/lib/bookmarks/bookmarkstoolbar.cpp +++ b/src/lib/bookmarks/bookmarkstoolbar.cpp @@ -269,10 +269,15 @@ void BookmarksToolbar::dropEvent(QDropEvent* e) if (mime->hasFormat(BookmarksButtonMimeData::mimeType())) { const auto* bookmarkMime = static_cast(mime); bookmark = bookmarkMime->item(); - const int initialIndex = bookmark->parent()->children().indexOf(bookmark); - BookmarksToolbarButton* current = buttonAt(m_dropPos); - if (initialIndex < m_layout->indexOf(current)) { - row -= 1; + + if (row < 0) { + row = parent->children().count() - 1; + } + else { + const int initialIndex = bookmark->parent()->children().indexOf(bookmark); + if ((row > 0) && (initialIndex < row)) { + row -= 1; + } } } else { const QUrl url = mime->urls().at(0);