diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -465,20 +465,17 @@ { TabbedViewContainer *container = createContainer(); - // iterate over each session which has a view in the current active - // container and create a new view for that session in a new container - for(int i = 0, end = _viewSplitter->activeContainer()->count(); i < end; i++) { - auto view = _viewSplitter->activeContainer()->widget(i); - Session *session = _sessionMap[qobject_cast(view)]; - TerminalDisplay *display = createTerminalDisplay(session); - const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); - applyProfileToView(display, profile); - ViewProperties *properties = createController(session, display); - - _sessionMap[display] = session; - - container->addView(display, properties); - session->addView(display); + if (_viewSplitter->activeContainer()->count()) { + // get the currently applied profile and use it to create the new tab. + auto *activeContainer= _viewSplitter->activeContainer(); + auto *currentDisplay = qobject_cast(activeContainer->currentWidget()); + auto profile = SessionManager::instance()->sessionProfile(_sessionMap[currentDisplay]); + + // Create a new session with the selected profile. + auto *session = SessionManager::instance()->createSession(profile); + session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); + + createView(session, container, 0); } _viewSplitter->addContainer(container, orientation); @@ -638,12 +635,7 @@ index = _viewSplitter->activeContainer()->currentIndex() + 1; } - // iterate over the view containers owned by this view manager - // and create a new terminal display for the session in each of them, along with - // a controller for the session/display pair - foreach (TabbedViewContainer *container, _viewSplitter->containers()) { - createView(session, container, index); - } + createView(session, _viewSplitter->activeContainer(), index); } TabbedViewContainer *ViewManager::createContainer() @@ -693,19 +685,8 @@ } // do not move the last tab in a split view. - if (sourceTabbedContainer != nullptr) { - QPointer sourceContainer = qobject_cast(sourceTabbedContainer); - - if (_viewSplitter->containers().contains(sourceContainer)) { - return; - } else { - ViewManager *sourceViewManager = sourceTabbedContainer->connectedViewManager(); - - // do not remove the last tab on the window - if (qobject_cast(sourceViewManager->widget())->containers().size() > 1) { - return; - } - } + if (sourceTabbedContainer != nullptr && sourceTabbedContainer->count() <= 1) { + return; } createView(controller->session(), container, index);