mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-27 15:54:17 +02:00
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:
parent
a7e2faf868
commit
2ed30a53ee
@ -3224,32 +3224,25 @@ bool NppParameters::exportUDLToFile(size_t langIndex2export, const std::wstring&
|
|||||||
|
|
||||||
LangType NppParameters::getLangFromExt(const wchar_t *ext)
|
LangType NppParameters::getLangFromExt(const wchar_t *ext)
|
||||||
{
|
{
|
||||||
int i = getNbLang();
|
// first check a user defined extensions for styles
|
||||||
i--;
|
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)
|
while (i >= 0)
|
||||||
{
|
{
|
||||||
Lang *l = getLangFromIndex(i--);
|
Lang *l = getLangFromIndex(i--);
|
||||||
|
|
||||||
const wchar_t *defList = l->getDefaultExtList();
|
const wchar_t *defList = l->getDefaultExtList();
|
||||||
const wchar_t *userList = NULL;
|
|
||||||
|
|
||||||
LexerStylerArray &lsa = getLStylerArray();
|
if (defList && isInList(ext, defList))
|
||||||
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()))
|
|
||||||
return l->getLangID();
|
return l->getLangID();
|
||||||
}
|
}
|
||||||
return L_TEXT;
|
return L_TEXT;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user