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

Fix showing document prefix in document switcher

Retrieve the longest common prefix only for 2 or more paths, otherwise the prefix will be empty.
parent 5cfd3b76
Pipeline #223683 passed with stage
in 8 minutes and 20 seconds
......@@ -67,4 +67,11 @@ void KateTabSwitcherTest::testLongestCommonPrefix_data()
strs.push_back(QStringLiteral("/home/autolink"));
strs.push_back(QStringLiteral("/home/async"));
QTest::newRow("find correct path prefix") << strs << QStringLiteral("/home/");
strs.clear();
QTest::newRow("empty list") << strs << QString();
strs.clear();
strs.push_back(QStringLiteral("/home/a"));
QTest::newRow("list with one item") << strs << QString();
}
......@@ -40,18 +40,15 @@ QString FilenameListItem::fullPath() const
}
/**
* Note that if strs contains the empty string, the result will be ""
* Note that if strs contains less than 2 items, the result will be an empty string.
*/
QString longestCommonPrefix(std::vector<QString> const &strs)
{
if (strs.empty()) {
// only 2 or more items can have a common prefix
if (strs.size() < 2) {
return QString();
}
if (strs.size() == 1) {
return strs.front();
}
// get the min length
auto it = std::min_element(strs.begin(), strs.end(), [](const QString &lhs, const QString &rhs) {
return lhs.size() < rhs.size();
......
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