diff --git a/src/eepp/ui/tools/uicodeeditorsplitter.cpp b/src/eepp/ui/tools/uicodeeditorsplitter.cpp index ae5657a46..eec4c48b6 100644 --- a/src/eepp/ui/tools/uicodeeditorsplitter.cpp +++ b/src/eepp/ui/tools/uicodeeditorsplitter.cpp @@ -517,6 +517,19 @@ void UICodeEditorSplitter::setCurrentEditor( UICodeEditor* editor ) { } void UICodeEditorSplitter::setCurrentWidget( UIWidget* curWidget ) { + if ( curWidget == nullptr ) { + if ( mCurEditor ) { + mCurWidget = mCurEditor; + mClient->onWidgetFocusChange( curWidget ); + } else { + // Should never happen: curWidget == nullptr is passed when a terminal is moved outside + // the splitter + auto editor = getSomeEditor(); + if ( editor ) + setCurrentWidget( editor ); + } + return; + } if ( curWidget->isType( UI_TYPE_CODEEDITOR ) ) { setCurrentEditor( curWidget->asType() ); return; diff --git a/src/tools/ecode/terminalmanager.cpp b/src/tools/ecode/terminalmanager.cpp index 8302e2bb3..b38e398a6 100644 --- a/src/tools/ecode/terminalmanager.cpp +++ b/src/tools/ecode/terminalmanager.cpp @@ -555,6 +555,11 @@ UITerminal* TerminalManager::createNewTerminal( ret.first->setIcon( mApp->findIcon( "filetype-bash" ) ); mApp->getSplitter()->removeUnusedTab( tabWidget, true, false ); + term->removeEventsOfType( Event::OnFocus ); + term->on( Event::OnFocus, [this, term]( const Event* ) { + mApp->getSplitter()->setCurrentWidget( + mApp->getSplitter()->getBaseLayout()->inParentTreeOf( term ) ? term : nullptr ); + } ); term->setTitle( title ); auto csIt = mTerminalColorSchemes.find( mTerminalCurrentColorScheme ); term->getTerm()->getTerminal()->setAllowMemoryTrimnming( true );