-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
Description of the Issue
The new NPPM_SETLINENUMBERWIDTHMODE message for v7.9.2 has a bug in its implementation, and returns false (without changing the setting) no matter what the lParam value.
Discovered when trying to SendMessage from an external process, but confirmed same buggy behavior using a standard plugin interface (npp_sendmsg from known-working NppExec).
Steps to Reproduce the Issue
For context, and a test script in either NppExec (SendMessage from a plugin) or using my external Perl module to do the SendMessage, see https://community.notepad-plus-plus.org/topic/20541/v7-9-2-nppm_setlinenumberwidthmode
But, in brief:
- Set Settings > Preferences > Margins/Border/Edge > Line Number to either Dynamic (0) or Constant (1)
- do a send message NPPM_SETLINENUMBERWIDTHMODE(0,0) or NPPM_SETLINENUMBERWIDTHMODE(0,1) -- for example, using the NppExec script shown in the community forum post, and quoted here:
cls
echo get original setting:
npp_sendmsg 2124 0 0
echo $(MSG_RESULT)
echo ---------------------
echo try to set to 0
npp_sendmsg 2123 0 0
echo $(MSG_RESULT)
echo and readback what I set
npp_sendmsg 2124 0 0
echo $(MSG_RESULT)
echo The 2123 (set) failed, and 2124 stayed with original value
echo ---------------------
echo try to set to 1
npp_sendmsg 2123 0 1
echo $(MSG_RESULT)
echo and readback what I set
npp_sendmsg 2124 0 0
echo $(MSG_RESULT)
echo The 2123 (set) failed, and 2124 stayed with original value
Expected Behavior
The NPPM_SETLINENUMBERWIDTHMODE (2123) SendMessage should return a True (1) on the calls with lParam=0 or lParam=1, and the NPPM_GETLINENUMBERWIDTHMODE (2124) SendMessage should return the most-recently set value.
Actual Behavior
the SET message always returns False (0) no matter what lParam is set, and the GET messsage always returns whatever you set in the preferences, even when the SET message should have changed it
Debug Information
Notepad++ v7.9.2 (64-bit)
Build time : Dec 31 2020 - 04:01:34
Path : C:\usr\local\apps\npp\npp.7.9.2.portable.x64\notepad++.exe
Admin mode : OFF
Local Conf mode : ON
OS Name : Windows 10 Home (64-bit)
OS Version : 2004
OS Build : 19041.685
Current ANSI codepage : 1252
Plugins : mimeTools.dll NppConverter.dll NppExec.dll NppExport.dll
Probable Cause
@Ekopalypse was able to dig into the code and found the likely culprit:
NppBigSwitch.cpp#L2127-L2137:
case NPPM_SETLINENUMBERWIDTHMODE: { if (lParam != LINENUMWIDTH_DYNAMIC || lParam != LINENUMWIDTH_CONSTANT) return FALSE; ScintillaViewParams &svp = const_cast<ScintillaViewParams &>(nppParam.getSVP()); svp._lineNumberMarginDynamicWidth = lParam == LINENUMWIDTH_DYNAMIC; ::SendMessage(hwnd, WM_COMMAND, IDM_VIEW_LINENUMBER, 0); return TRUE; }
The if statement will always be true; any integer value of lParam is either !=0 (DYNAMIC) or !=1 (CONSTANT). Since the if is true, the big switch always returns false and does nothing. The logic operator should be && instead of ||.