From a41e20a5de7de9df72e4775f80f12aa38e6e6562 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 3 Jul 2024 13:53:03 +0200 Subject: [PATCH] Do not show empty items in editor history menus The menus that are available from the back and forward buttons in the editor toolbar could show empty items, because some editors are not backed by files. When they are closed, they are no longer available. For example: open a file, trigger a git diff (regardless of whether that is empty), switch a fill times between file and diff to fill up some history, close the diff. Just do not show history items with empty display names. Change-Id: If7e966e55ada407ed03069027b352d12f053751f Reviewed-by: Alessandro Portale --- .../coreplugin/editormanager/editorview.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp index 42ad07d2498..21146d47b45 100644 --- a/src/plugins/coreplugin/editormanager/editorview.cpp +++ b/src/plugins/coreplugin/editormanager/editorview.cpp @@ -534,29 +534,27 @@ void EditorView::cutForwardNavigationHistory() void EditorView::updateNavigatorActions() { static const int MAX_ITEMS = 20; - FilePath last; + QString lastDisplay; m_backMenu->clear(); int count = 0; for (int i = m_currentNavigationHistoryPosition - 1; i >= 0; i--) { const EditLocation &loc = m_navigationHistory.at(i); - if (loc.filePath != last) { - m_backMenu->addAction(loc.displayName(), this, [this, i] { goToNavigationHistory(i); }); - last = loc.filePath; + if (!loc.displayName().isEmpty() && loc.displayName() != lastDisplay) { + lastDisplay = loc.displayName(); + m_backMenu->addAction(lastDisplay, this, [this, i] { goToNavigationHistory(i); }); ++count; if (count >= MAX_ITEMS) break; } } - last = {}; + lastDisplay.clear(); m_forwardMenu->clear(); count = 0; for (int i = m_currentNavigationHistoryPosition + 1; i < m_navigationHistory.size(); i++) { const EditLocation &loc = m_navigationHistory.at(i); - if (loc.filePath != last) { - m_forwardMenu->addAction(loc.displayName(), this, [this, i] { - goToNavigationHistory(i); - }); - last = loc.filePath; + if (!loc.displayName().isEmpty() && loc.displayName() != lastDisplay) { + lastDisplay = loc.displayName(); + m_forwardMenu->addAction(lastDisplay, this, [this, i] { goToNavigationHistory(i); }); ++count; if (count >= MAX_ITEMS) break;