Skip to content

[BUG] The "Follow Windows" makes external lexers appear twice in the tab settings menu #16462

@rdipardo

Description

@rdipardo

Is there an existing issue for this?

  • I have searched the existing issues

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:

Image

The faulty code path seems to follow this call stack:

Notepad_plus::refreshDarkMode
NppParameters::reloadStylers
NppParameters::getExternalLexerFromXmlTree
NppParameters::feedKeyWordsParameters

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

  1. Install at least one lexer plugin, e.g. CSVLint
  2. Click the "Follow Windows" radio button at Settings > Prefernces... > Dark Mode
  3. Restart Notepad++
  4. Open the indent settings menu at Settings > Prefernces... > Indentation
  5. Scroll to the bottom of the language name listbox.
  6. 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
 

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions