Is there an existing issue for this?
Description of the Issue
As noted in the downstream issue that prompted #16460, external lexers sometimes have 2 entries in the indentation menu's language listbox:
The faulty code path seems to follow this call stack:
As there will most likely still be room in NppParameters::_langList, and NppParameters::feedKeyWordsParameters does not check for duplicates, executing this sequence multiple times will add every external lexer again.
Steps To Reproduce
- Install at least one lexer plugin, e.g. CSVLint
- Click the "Follow Windows" radio button at Settings > Prefernces... > Dark Mode
- Restart Notepad++
- Open the indent settings menu at Settings > Prefernces... > Indentation
- Scroll to the bottom of the language name listbox.
- See double entries for each external lexer
Current Behavior
Duplicate entries for each external lexer whenever the "Follow Windows" dark mode option is enabled.
Expected Behavior
A single entry for each external lexer.
Debug Information
Notepad++ v8.8 RC1 (64-bit)
Build time : Apr 22 2025 - 18:20:44
Scintilla/Lexilla included : 5.5.6/5.4.4
Boost Regex included : 1_85
Path : C:\Users\Public\git\npp.8.8.portable.x64\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : ON
Cloud Config : OFF
Periodic Backup : ON
Placeholders : OFF
Scintilla Rendering Mode : SC_TECHNOLOGY_DIRECTWRITE (1)
Multi-instance Mode : monoInst
File Status Auto-Detection : cdEnabledNew (for current file/tab only)
Dark Mode : ON
OS Name : Windows 10 Pro (64-bit)
OS Version : 22H2
OS Build : 19045.5737
Current ANSI codepage : 1252
Plugins :
CSVLint (0.4.6.8)
mimeTools (3.1)
NppConverter (4.6)
NppExport (0.4)
NPPFSIPlugin (0.2.3.1)
Anything else?
I think if NppParameters::_langList were an STL container instead of a C-style array, something like this might fix it, barring any regressions:
diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp
index 0d50ef3db..44c31be25 100644
--- a/PowerEditor/src/Parameters.cpp
+++ b/PowerEditor/src/Parameters.cpp
@@ -4724,6 +4724,12 @@ void NppParameters::feedKeyWordsParameters(TiXmlNode *node)
const wchar_t* name = element->Attribute(L"name");
if (name)
{
+ auto it = _langList.cbegin();
+ while (*it)
+ {
+ if (std::wcscmp(name, (*it++)->_langName.c_str()) == 0)
+ return;
+ }
_langList[_nbLang] = new Lang(getLangIDFromStr(name), name);
_langList[_nbLang]->setDefaultExtList(element->Attribute(L"ext"));
_langList[_nbLang]->setCommentLineSymbol(element->Attribute(L"commentLine"));
diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h
index ba0614681..d4c6f9872 100644
--- a/PowerEditor/src/Parameters.h
+++ b/PowerEditor/src/Parameters.h
@@ -1938,7 +1938,7 @@ private:
NppGUI _nppGUI;
ScintillaViewParams _svp;
- Lang* _langList[NB_LANG] = { nullptr };
+ std::array<Lang*, NB_LANG> _langList;
int _nbLang = 0;
// Recent File History
Is there an existing issue for this?
Description of the Issue
As noted in the downstream issue that prompted #16460, external lexers sometimes have 2 entries in the indentation menu's language listbox:
The faulty code path seems to follow this call stack:
Notepad_plus::refreshDarkModeNppParameters::reloadStylersNppParameters::getExternalLexerFromXmlTreeNppParameters::feedKeyWordsParametersAs there will most likely still be room in
NppParameters::_langList, andNppParameters::feedKeyWordsParametersdoes not check for duplicates, executing this sequence multiple times will add every external lexer again.Steps To Reproduce
Current Behavior
Duplicate entries for each external lexer whenever the "Follow Windows" dark mode option is enabled.
Expected Behavior
A single entry for each external lexer.
Debug Information
Anything else?
I think if
NppParameters::_langListwere an STL container instead of a C-style array, something like this might fix it, barring any regressions: