From ccfd472a8cd17bd5050f9fcf369ee8c3101306d1 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 20 Sep 2022 13:39:36 +0200 Subject: [PATCH] Generic highlighter: Try mime type aliases when looking for definitions For example the yaml highlighting file declares text/yaml as the supported mime type, but that is not the canonical name, which is application/x-yaml. Change-Id: If9e3f5e31bc5593a82cbbdac916ef41b0d23de7c Reviewed-by: Reviewed-by: David Schulz --- src/plugins/texteditor/highlighter.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugins/texteditor/highlighter.cpp b/src/plugins/texteditor/highlighter.cpp index 7e3235370ef..3546a27e1da 100644 --- a/src/plugins/texteditor/highlighter.cpp +++ b/src/plugins/texteditor/highlighter.cpp @@ -119,8 +119,15 @@ Highlighter::Definitions Highlighter::definitionsForDocument(const TextDocument } if (definitions.isEmpty()) { const MimeType &mimeType = Utils::mimeTypeForName(document->mimeType()); - if (mimeType.isValid()) - definitions = definitionsForMimeType(mimeType.name()); + if (mimeType.isValid()) { + // highlight definitions might not use the canonical name but an alias + const QStringList names = QStringList(mimeType.name()) + mimeType.aliases(); + for (const QString &name : names) { + definitions = definitionsForMimeType(name); + if (!definitions.isEmpty()) + break; + } + } } return definitions;