Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scintilla Command "NewLine" inside a macro not working anymore #5571

Closed
hatyzak opened this issue Apr 23, 2019 · 3 comments
Closed

Scintilla Command "NewLine" inside a macro not working anymore #5571

hatyzak opened this issue Apr 23, 2019 · 3 comments
Assignees
Labels

Comments

@hatyzak
Copy link

hatyzak commented Apr 23, 2019

Description of the Issue

Scintilla Command "NewLine" used inside a macro does not work (nothing happens). This is new in v7.6.4, it worked OK in prior versions.

Steps to Reproduce the Issue

  1. Edit user config file "shortcuts.xml". It is in two locations - first in the installation directory and second in %APPDATA%\Notepad++ directory. I edited the latter one, but probably it does not matter which one you choose.
  2. Add the following three lines to the <Macros> section:
        <Macro name="Enter" Ctrl="yes" Alt="no" Shift="no" Key="123">
            <Action type="0" message="2329" wParam="0" lParam="0" sParam="" />
        </Macro>
  1. Save the file and restart Notepad++.
  2. While editing something, press Ctrl+F12. That is the keyboard shortcut defined by the three lines above. It does not matter what key it is defined to, the action of the macro is what matters.

Expected Behavior

New line is inserted in the edited file.

Actual Behavior

Nothing happens.

Notes

  • This bug is new in 7.6.4. It was working OK in 7.6.3. Looking at the list of new features introduced in 7.6.4, this item seems to be the culprit very likely:
    11. Ensure each recorded command is playable before playing to avoid exploit in hacking. (EURO-FOSSA)
  • The action of the macro is defined as a scintilla command 2329, which is NewLine. See list of available commands here:
    https://www.scintilla.org/CommandValues.html
  • The motivation behind such macro is as follows: When pressing Enter in Notepad++ editor, the default behaviour is to insert a new line with auto-indent. This is what I like and use. Now I do not mean "smart auto-indent" that is present when editing a source code (like C/C++). I mostly use Notepad++ to edit plain text files (I am also writing this post in it :) ). In plain text files, auto-indent simply indents the new line the same way as the previous line. This is expected and desirable behaviour most of the time. But sometimes I need to insert a new line without an indentation. For this, I use the macro above and I map it to Ctrl+Enter. This way I can easily choose the right new line behaviour according to my needs. In the instructions above I chose shortcut Ctrl+F12, simply because Ctrl+Enter is conflicting in default Notepad++ setup, but as I said before, the keyboard shortcut does not matter.
  • My first idea how to bypass the problem was to change the macro action to something else with the same effect. This attempt failed, because I just reinvented why I coded that macro the way I did long ago. At first sight, recording of a single Enter keypress and then replaying it seems to do the trick (yes, interestingly pressing Enter during macro recording does the indentation, but it does NOT do the indentation when replaying the macro). There is one serious problem with it, however. In shortcuts.xml, the recorded macro has the following action:
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000A;" />

This means that 0x0D 0x0A is always inserted and that is a big problem if the currently edited file is not CRLF. The macro that I used (the one which does not work now) does not have this problem. It always inserts correct new line (CRLF/CR/LF) based on what is used by the currently edited file.

  • This is a showstopper for me, I downgraded to 7.6.3.

Possible solutions

  1. Improve security measures introduced in 7.6.4 to allow the affected macro as valid.
  2. Make the security measure responsible for the bug optional.
  3. In the shortcut mapper, under scintilla commands, there is actually scintilla NewLine command and it is mapped to Enter and Shift+Enter. However, this always respects auto-indent. Make it not respect it as it is when that scintilla command is in a macro. Keyboard shortcuts would need to be changed too so that plain Enter still indents.
  4. Introduce a new function "Insert new line without indentation" - it would fit nicely somewhere under Edit menu. Then also make it available through the shortcut mapper. This solution would be my vote.
SinghRajenM referenced this issue Apr 28, 2019
…ded macro

Such situation can happen via the manual modification of shortcut.xml by hackers.
@SinghRajenM
Copy link
Contributor

case SCI_NEWLINE: is blocked here. @donho any comment here?

case SCI_NEWLINE:
default:
return false;

Allowing SCI_NEWLINE fixes this issue.

@hatyzak
Copy link
Author

hatyzak commented Apr 29, 2019

Hi Singh

Thank you for finding the code responsible for this. The comment above it says:

// Filter out all others like display changes. Also, newlines are redundant
// with char insert messages.

It is true that new line can be recorded as a char insert, but as I mentioned before only SCI_NEWLINE is context-sensitive and inserts the correct newline, i.e. CRLF, CR or LF. Let's see what the author thinks.

I came up with a solution (5), which would be ideal:
Besides allowing SCI_NEWLINE inside a macro, teach the macro recorder to correctly translate "Enter" to SCI_NEWLINE. This way, there will be no need to fiddle with shortcuts.xml.

@hatyzak
Copy link
Author

hatyzak commented Mar 14, 2020

@donho are there any plans to fix this?
Any answer is appreciated.
Thanks

@donho donho self-assigned this Mar 16, 2020
@donho donho added the accepted label Nov 8, 2020
@donho donho closed this as completed in d17c303 Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants