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

Allow / separated pattern to filter same filename across different directories

Suppose you have the following dir structure:

abc/main.cpp
def/main.cpp

Using quickopen it is very difficult to find the main.cpp that you want.
This is because we remove the filename from the path so the filter
doesn't work if you try for e.g "ab/ma".

For now, I have made it so that the filename is always present in the
path but is removed during display. This allows for more flexible
filtering.
parent e3afb5d9
......@@ -137,6 +137,8 @@ public:
QString name = namePath.at(0);
QString path = namePath.at(1);
path.remove(QStringLiteral("/") + name);
const QString nameColor = option.palette.color(QPalette::Link).name();
if (mode == FilterMode::FilterByName) {
......@@ -144,7 +146,17 @@ public:
} else if (mode == FilterMode::FilterByPath) {
kfts::to_fuzzy_matched_display_string(m_filterString, path, QStringLiteral("<b>"), QStringLiteral("</b>"));
} else {
kfts::to_fuzzy_matched_display_string(m_filterString, name, QStringLiteral("<b style=\"color:%1;\">").arg(nameColor), QStringLiteral("</b>"));
// check if there's a / separtion in filter string
// if there is, we use the last part to highlight the
// filename
int pos = m_filterString.lastIndexOf(QLatin1Char('/'));
if (pos > -1) {
++pos;
auto pattern = m_filterString.midRef(pos);
kfts::to_fuzzy_matched_display_string(pattern, name, QStringLiteral("<b style=\"color:%1;\">").arg(nameColor), QStringLiteral("</b>"));
} else {
kfts::to_fuzzy_matched_display_string(m_filterString, name, QStringLiteral("<b style=\"color:%1;\">").arg(nameColor), QStringLiteral("</b>"));
}
kfts::to_fuzzy_matched_display_string(m_filterString, path, QStringLiteral("<b>"), QStringLiteral("</b>"));
}
......
......@@ -91,18 +91,18 @@ void KateQuickOpenModel::refresh()
size_t sort_id = static_cast<size_t>(-1);
for (auto *view : qAsConst(sortedViews)) {
auto doc = view->document();
allDocuments.push_back({doc->url(), doc->documentName(), doc->url().toDisplayString(QUrl::NormalizePathSegments | QUrl::PreferLocalFile).remove(projectBase).remove(QStringLiteral("/") + doc->documentName()), true, sort_id--, -1});
allDocuments.push_back({doc->url(), doc->documentName(), doc->url().toDisplayString(QUrl::NormalizePathSegments | QUrl::PreferLocalFile).remove(projectBase), true, sort_id--, -1});
}
for (auto *doc : qAsConst(openDocs)) {
const auto normalizedUrl = doc->url().toString(QUrl::NormalizePathSegments | QUrl::PreferLocalFile).remove(projectBase).remove(QStringLiteral("/") + doc->documentName());
const auto normalizedUrl = doc->url().toString(QUrl::NormalizePathSegments | QUrl::PreferLocalFile).remove(projectBase);
allDocuments.push_back({doc->url(), doc->documentName(), normalizedUrl, true, 0, -1});
}
for (const auto &file : qAsConst(projectDocs)) {
QFileInfo fi(file);
const auto localFile = QUrl::fromLocalFile(fi.absoluteFilePath());
allDocuments.push_back({localFile, fi.fileName(), fi.filePath().remove(projectBase).remove(QStringLiteral("/") + fi.fileName()), false, 0, -1});
allDocuments.push_back({localFile, fi.fileName(), fi.filePath().remove(projectBase), false, 0, -1});
}
/** Sort the arrays by filePath. */
......
Markdown is supported
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