Commit 04969887 authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

quickopen: avoid unfortunate or inadvertent string removal

... such as when removing all / in a path, or when another string might
happen to occur more than only at start or end.
parent 9b9b5605
......@@ -145,7 +145,11 @@ public:
QString name = index.data(KateQuickOpenModel::FileName).toString();
QString path = index.data(KateQuickOpenModel::FilePath).toString();
path.remove(QStringLiteral("/") + name);
// only remove suffix, not where it might occur elsewhere
const QString suffix = QStringLiteral("/") + name;
if (path.endsWith(suffix)) {
path.chop(suffix.size());
}
const QString nameColor = option.palette.color(QPalette::Link).name();
......
......@@ -48,8 +48,11 @@ QVariant KateQuickOpenModel::data(const QModelIndex &idx, int role) const
case Qt::DisplayRole:
case Role::FileName:
return entry.fileName;
case Role::FilePath:
return QString(entry.filePath).remove(m_projectBase);
case Role::FilePath: {
// no .remove since that might remove all occurrence in rare cases
const auto &path = entry.filePath;
return path.startsWith(m_projectBase) ? path.mid(m_projectBase.size()) : path;
}
case Qt::FontRole: {
if (entry.bold) {
QFont font;
......@@ -93,6 +96,10 @@ void KateQuickOpenModel::refresh(KateMainWindow *mainWindow)
if (!ret.endsWith(QLatin1Char('/'))) {
ret.append(QLatin1Char('/'));
}
// avoid strip of a single leading /
if (ret == QStringLiteral("/")) {
ret.clear();
}
return ret;
}();
......
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