Commit 098f435f authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Fix lru tab switching when there are widgets

parent 34bb6dca
......@@ -369,9 +369,12 @@ void KateViewSpace::removeView(KTextEditor::View *v)
// (last element could well be v->document() being removed here)
bool shown = false;
for (auto rit = m_registeredDocuments.rbegin(); rit != m_registeredDocuments.rend(); ++rit) {
auto it = m_docToView.find(*rit);
if (it != m_docToView.end()) {
shown = showView(*rit);
if (auto doc = rit->doc()) {
shown = showView(doc);
break;
} else if (auto wid = rit->widget()) {
activateWidget(wid);
shown = true;
break;
}
}
......@@ -742,10 +745,26 @@ void KateViewSpace::closeTabRequest(int idx)
QMetaObject::invokeMethod(widget, "shouldClose", Q_RETURN_ARG(bool, shouldClose));
if (shouldClose) {
stack->removeWidget(widget);
m_registeredDocuments.removeOne(widget);
m_tabBar->blockSignals(true);
m_tabBar->removeTab(idx);
m_tabBar->blockSignals(false);
widget->deleteLater();
Q_EMIT m_viewManager->mainWindow()->widgetRemoved(widget);
// switch to most recently used doc
for (auto rit = m_registeredDocuments.rbegin(); rit != m_registeredDocuments.rend(); ++rit) {
if (auto doc = rit->doc()) {
showView(doc);
break;
} else if (auto wid = rit->widget()) {
activateWidget(wid);
break;
}
}
// if this was the last doc, let viewManager know we are empty
if (m_registeredDocuments.isEmpty() && m_tabBar->count() == 0) {
Q_EMIT viewSpaceEmptied(this);
......@@ -792,6 +811,7 @@ void KateViewSpace::addWidgetAsTab(QWidget *widget)
stack->addWidget(widget);
m_tabBar->setCurrentWidget(widget);
stack->setCurrentWidget(widget);
m_registeredDocuments.append(widget);
}
bool KateViewSpace::hasWidgets() const
......@@ -844,6 +864,9 @@ bool KateViewSpace::activateWidget(QWidget *widget)
for (int i = 0; i < m_tabBar->count(); ++i) {
if (m_tabBar->tabData(i).value<QWidget *>() == widget) {
m_tabBar->setCurrentIndex(i);
m_registeredDocuments.removeOne(widget);
m_registeredDocuments.append(widget);
return true;
}
}
......
......@@ -298,13 +298,35 @@ private:
std::vector<Location> m_locations;
size_t currentLocation = 0;
struct DocOrWidget : public std::variant<KTextEditor::Document *, QWidget *> {
using variant::variant;
auto *doc() const
{
return std::holds_alternative<KTextEditor::Document *>(*this) ? std::get<KTextEditor::Document *>(*this) : nullptr;
}
auto widget() const
{
return std::holds_alternative<QWidget *>(*this) ? std::get<QWidget *>(*this) : nullptr;
}
bool operator==(KTextEditor::Document *doc) const
{
return this->doc() == doc;
}
bool operator==(QWidget *w) const
{
return this->widget() == w;
}
};
/**
* all documents this view space is aware of
* depending on the limit of tabs, not all will have a corresponding
* tab in the KateTabBar
* these are stored in used order (MRU last)
*/
QVector<KTextEditor::Document *> m_registeredDocuments;
QVector<DocOrWidget> m_registeredDocuments;
// the list of views that are contained in this view space,
// mapped through a hash from Document to View.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment