From 01871fdfff9363af3a90959650ef20ab9276c464 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sun, 21 Aug 2022 19:17:26 +0200 Subject: [PATCH] Even more tweaks to opening "text" files BUGS: 430538 BUGS: 456434 --- part/part.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/part/part.cpp b/part/part.cpp index 0ac6aca04..0a5aaf336 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -1578,10 +1578,19 @@ bool Part::openFile() mimes << pathMime << argMime; } + // text is super annoying because it always succeeds when opening so try to make sure + // that we don't set it as first mime unless we're really sure it is that. + // If it could be something else based on the content we try that first but only if that content itself + // is not text or if it's a supported text child like markdown if (mimes[0].inherits(QStringLiteral("text/plain"))) { const QMimeType contentMime = db.mimeTypeForFile(fileNameToOpen, QMimeDatabase::MatchContent); - if (contentMime.name() != QLatin1String("text/plain")) { + if (!contentMime.inherits(QStringLiteral("text/plain"))) { mimes.prepend(contentMime); + } else if (contentMime.name() != QLatin1String("text/plain")) { + const QStringList supportedMimes = m_document->supportedMimeTypes(); + if (supportedMimes.contains(contentMime.name())) { + mimes.prepend(contentMime); + } } } } else {