diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index fa0c509569f..eea4ed27e06 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -975,26 +975,23 @@ void MainWindow::toggleFullscreen() */ void MainWindow::refocus() { - QList editors; - editors - << getGUI()->songEditor()->parentWidget() - << getGUI()->patternEditor()->parentWidget() - << getGUI()->pianoRoll()->parentWidget() - << getGUI()->automationEditor()->parentWidget(); - - bool found = false; - QList::Iterator editor; - for( editor = editors.begin(); editor != editors.end(); ++editor ) - { - if( ! (*editor)->isHidden() ) { - (*editor)->setFocus(); - found = true; - break; + const auto gui = getGUI(); + + // Attempt to set the focus on the first of these editors that is not hidden... + const std::vector editorParents = { gui->songEditor()->parentWidget(), gui->patternEditor()->parentWidget(), + gui->pianoRoll()->parentWidget(), gui->automationEditor()->parentWidget() }; + + for (auto editorParent : editorParents) + { + if(!editorParent->isHidden()) + { + editorParent->setFocus(); + return; } } - if( ! found ) - this->setFocus(); + // ... otherwise set the focus on the main window. + this->setFocus(); }