Commit f05eebc1 authored by Eugene Popov's avatar Eugene Popov 🇺🇦 Committed by Christoph Cullmann
Browse files

Improve handling of reducing the tab limit

Currently, reducing the tab limit just closes the N tabs on the right, even if the current tab is among them. This MR makes it close the N least used tabs instead.
parent af837868
Pipeline #223026 passed with stage
in 7 minutes and 19 seconds
......@@ -67,8 +67,25 @@ void KateTabBar::readConfig()
KConfigGroup cgGeneral = KConfigGroup(config, "General");
// 0 == unlimited, normalized other inputs
const int tabCountLimit = cgGeneral.readEntry("Tabbar Tab Limit", 0);
m_tabCountLimit = (tabCountLimit <= 0) ? 0 : tabCountLimit;
const int tabCountLimit = std::max(cgGeneral.readEntry("Tabbar Tab Limit", 0), 0);
if (m_tabCountLimit != tabCountLimit) {
m_tabCountLimit = tabCountLimit;
const QVector<KTextEditor::Document*> docList = documentList();
if (m_tabCountLimit > 0 && docList.count() > m_tabCountLimit) {
// close N least used tabs
QMap<quint64, KTextEditor::Document*> lruDocs;
for (KTextEditor::Document *doc : docList) {
lruDocs[m_docToLruCounterAndHasTab[doc].first] = doc;
}
int toRemove = docList.count() - m_tabCountLimit;
for (KTextEditor::Document *doc : lruDocs) {
if (toRemove-- == 0) {
break;
}
removeTab(documentIdx(doc));
}
}
}
// use scroll buttons if we have no limit
setUsesScrollButtons(m_tabCountLimit == 0 || cgGeneral.readEntry("Allow Tab Scrolling", true));
......@@ -76,22 +93,6 @@ void KateTabBar::readConfig()
// elide if requested, this is independent of the limit, just honor the users wish
setElideMode(cgGeneral.readEntry("Elide Tab Text", false) ? Qt::ElideMiddle : Qt::ElideNone);
const std::vector<int> documentTabIndexes = this->documentTabIndexes();
// if we enforce a limit: purge tabs that violate it
if (m_tabCountLimit > 0 && ((int)documentTabIndexes.size() > m_tabCountLimit)) {
// just purge last X tabs, this isn't that clever but happens only on config changes!
size_t toRemove = documentTabIndexes.size() - (size_t)m_tabCountLimit;
size_t removed = 0;
for (auto rit = documentTabIndexes.rbegin(); rit != documentTabIndexes.rend(); ++rit) {
if (removed == toRemove)
break;
removeTab(*rit);
removed++;
}
setCurrentIndex(0);
}
// handle tab close button and expansion
setExpanding(cgGeneral.readEntry("Expand Tabs", false));
setTabsClosable(cgGeneral.readEntry("Show Tabs Close Button", true));
......
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