From a53a72044ce1b867dff622b512b5b600153c2cee Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 25 Jun 2024 08:39:54 +0200 Subject: [PATCH] TextEditor: Allow to open all files with the text editor Sometimes the mime detection returns unexpected results and defines a textfile based on the ending as a binary file. We should at least make it possible for the user to open those files in the plain text editor. Fixes: QTCREATORBUG-31116 Change-Id: I3139a1013be9fa6f28654434229c62f7a8e79d21 Reviewed-by: Christian Stenger --- src/plugins/coreplugin/editormanager/ieditorfactory.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plugins/coreplugin/editormanager/ieditorfactory.cpp b/src/plugins/coreplugin/editormanager/ieditorfactory.cpp index 74c35a7b5ca..0c0fc17a204 100644 --- a/src/plugins/coreplugin/editormanager/ieditorfactory.cpp +++ b/src/plugins/coreplugin/editormanager/ieditorfactory.cpp @@ -4,6 +4,7 @@ #include "ieditorfactory.h" #include "ieditorfactory_p.h" #include "editormanager.h" +#include "../coreconstants.h" #include #include @@ -36,6 +37,14 @@ static void mimeTypeFactoryLookup(const Utils::MimeType &mimeType, } return true; // continue }); + // Always offer the plain text editor as a fallback for the case that the mime type + // is not detected correctly. + if (auto plainTextEditorFactory = Utils::findOrDefault( + allFactories, + Utils::equal(&IEditorFactory::id, Utils::Id(Constants::K_DEFAULT_TEXT_EDITOR_ID)))) { + if (!matches.contains(plainTextEditorFactory)) + list->append(plainTextEditorFactory); + } } /*!