From ad0496343157bb3bfe8ea90e4d0a9a5fb069e602 Mon Sep 17 00:00:00 2001
From: Leon Styhre <leon@leonstyhre.com>
Date: Sat, 27 Mar 2021 12:06:37 +0100
Subject: [PATCH] Fixed an issue where custom collections 'Jump to game' caused
 multiple mCursorStackHistory entries.

---
 es-app/src/views/gamelist/ISimpleGameListView.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/es-app/src/views/gamelist/ISimpleGameListView.cpp b/es-app/src/views/gamelist/ISimpleGameListView.cpp
index 436a0c648..6aca442c4 100644
--- a/es-app/src/views/gamelist/ISimpleGameListView.cpp
+++ b/es-app/src/views/gamelist/ISimpleGameListView.cpp
@@ -214,6 +214,18 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
             // Jump to the randomly selected game.
             if (mRandomGame) {
                 NavigationSounds::getInstance()->playThemeNavigationSound(SCROLLSOUND);
+                // If there is already an mCursorStackHistory entry for the collection, then
+                // remove it so we don't get multiple entries.
+                std::vector<FileData*> listEntries =
+                        mRandomGame->getSystem()->getRootFolder()->getChildrenListToDisplay();
+                for (auto it = mCursorStackHistory.begin();
+                        it != mCursorStackHistory.end(); it++) {
+                    if (std::find(listEntries.begin(), listEntries.end(), *it) !=
+                            listEntries.end()) {
+                        mCursorStackHistory.erase(it);
+                        break;
+                    }
+                }
                 setCursor(mRandomGame);
                 updateHelpPrompts();
             }