Fix the extension defined by user not override language default extension

Check user defined extensions for styles first when detecting lang from extension.

Fix #8035, fix #8304, fix #15826, fix #10609, close #15888
This commit is contained in:
pawelzwronek 2024-11-30 17:48:39 +01:00 committed by Don Ho
parent a7e2faf868
commit 2ed30a53ee

View File

@ -3224,32 +3224,25 @@ bool NppParameters::exportUDLToFile(size_t langIndex2export, const std::wstring&
LangType NppParameters::getLangFromExt(const wchar_t *ext)
{
int i = getNbLang();
i--;
// first check a user defined extensions for styles
LexerStylerArray &lexStyleList = getLStylerArray();
for (size_t i = 0 ; i < lexStyleList.getNbLexer(); ++i)
{
LexerStyler &styler = lexStyleList.getLexerFromIndex(i);
const wchar_t *extList = styler.getLexerUserExt();
if (isInList(ext, extList))
return getLangIDFromStr(styler.getLexerName());
}
// then check languages extensions
int i = getNbLang() - 1;
while (i >= 0)
{
Lang *l = getLangFromIndex(i--);
const wchar_t *defList = l->getDefaultExtList();
const wchar_t *userList = NULL;
LexerStylerArray &lsa = getLStylerArray();
const wchar_t *lName = l->getLangName();
LexerStyler *pLS = lsa.getLexerStylerByName(lName);
if (pLS)
userList = pLS->getLexerUserExt();
std::wstring list;
if (defList)
list += defList;
if (userList)
{
list += L" ";
list += userList;
}
if (isInList(ext, list.c_str()))
if (defList && isInList(ext, defList))
return l->getLangID();
}
return L_TEXT;