Feature request - Left cursor movement to stop at left margin
Nice summary of the setup. I would suggest not letting conflicts persist in the Shortcut Mapper as a “best practice”.
Fair point. In this case I couldn’t find any way to attach the script to the left key without the ‘Conflict’ warning appearing.
So far it has been ok. I guess the [left] key is only going to be used to move left.
Well, when you have conflicts, Notepad++'s Shortcut Mapper will turn the conflicts red. It is just a matter of scrolling through the list until you see the other red one. Additionally, the box near the bottom (just above the buttons) of the Shortcut Mapper window will show the conflicts for the current item. I find a quick scroll through looking for the other red one is faster than reading the box and figuring out where to move to, although the text certainly gives you a push in the direction of the correct tab the conflict is on.
And to be specific, you’ll find that the conflict you created is almost certainly going to be matched on Line 33 of the “Scintilla commands” tab.
Thanks for the comments Scott. I’ve followed that through and Line 33 of the “Scintilla commands” tab seems to just be activating a move left. I’m not sure how Scintilla responds to the conflict and I may have expected two move lefts but that is not happening so hopefully it is ok.
What it is actually doing (I think) is finding the definition for the Pythonscript tie to the shortcut key FIRST when it is trying to figure out what to do when you press that key. So, yes, Scintilla command 33 is a “move left” but the key point is that this move left is NEVER HAPPENING because the Pythonscript that runs your new functionality is being run INSTEAD (NOT in addition to!).
Conflicts are bad because you can’t predict this “which-will-get-run” behavior, in general. However, it should always act the same way when a given conflict exists. So in our example here, the Pythonscript always runs and the Scintilla move-left never does.
These are all general conclusions based upon what I’m taking from your experience. I don’t let conflicts persist in my setup, so I don’t have extensive time studying this and its effects.
The best thing to do in your case is to change the shortcut key for Scintilla’s move-left to “None”. If you bring up the window that allows you to change the key combination for that entry, the dropdown box will have “None” as the first entry at the top. It would be nicer to not have to select None this way, but rather have a “Remove shortcut” button, but this is not the case.
I hope this helps clarify…
The above is NOT based upon the most current Notepad++ as of this writing (7.3.3) simply because I like to lag a bit behind the bleeding edge (I’m using 7.2.2). 7.3.3 (and possibly slighter earlier) has a “Clear” button (which sounds useful!) but there is some indication that it is buggy; see https://notepad-plus-plus.org/community/topic/13687/bug-unable-to-clear-or-remove-shortcuts-for-scintilla-commands
Thanks Scott, it makes total sense to avoid the conflict and remove the original [left] key Scintilla command 33 response. I have done that and added it to the Install summary.
For those that want to implement this Stop Left Wrap function here is a summary of the install process discussed above.
All credits to Scott-Sumner.
Version 2 - added remove original [left] move response.
Summary below applies to Notepad++ V3.3.3 (32 bit)
Stop Left Cursor Wrap to previous line:
Install Python Script Plugin
- Plugins -> Plugin Manager -> Show Plugin Manager -> [Available]
- Tick ‘Python Script’ and [install]
Write ‘Stop Left Wrap’ Script
- Plugins -> Python Script -> New Script
- Add “Stop Left Wrap” File name for Script and [Save]
- This will open a new blank text file page
- Copy this Python Script code to the new file and [Save]
curr_pos = editor.getCurrentPos()
if curr_pos != editor.positionFromLine(editor.lineFromPosition(curr_pos)): editor.charLeft()
if editor.getSelectionNAnchorVirtualSpace(0) > 0: editor.charLeft()
- Plugins -> Python Script -> Configuration
- Select ‘Stop Left Wrap’ and push [Add] to Menu Items and [OK]
Attach Shortcut to ‘left’ key
- Run -> Modify Shortcut/Delete Command -> [Plugin Commands]
- scroll down and click select ‘Stop Left Wrap’
- select [Modify] and scroll down to Select ‘left’ key
- A Conflict warning will appear. Still say [OK]
Remove Original ‘left’ key Response
- Select [Scintilla Commands] tab
- scroll down to Highlighted command 33 SCI_CHARLEFT and select
- select [Modify] and scroll up to Select ‘none’
- select [Apply] to remove original response
- select [OK] conflict warning Highlight should now be gone
- [Close] Should be operating now, so no more wrap on left margin.
Rod T last edited by Rod T
Minor correction to above.
The Version of Notepad that the procedure applies to is V7.3.3 not V3.3.3
Another correction to the above setup.
Symptom: When ‘Virtual Space’ mode is enabled the cursor can move left by two places not one as expected.
The problem occurs only when ‘Virtual Space’ mode is enabled. ie the ability to move the cursor beyond the end of the line.
This is now quite easy to enable with the Python Plugin installed as it is one of the example scripts which can be activated with an icon in the toolbar.
When moving the cursor left within the ‘Virtual Space’ area of a line with existing characters, the cursor moves left by two positions not one as expected.
This happens because in this situation both of the conditions in the script for activating a charLeft () are met so it moves twice.
The fix is simple, make the second ‘if’ an ‘elif’ (else if ) so either one of the conditions can activate a charLeft () but not both.
The last line of the script now becomes:
elif editor.getSelectionNAnchorVirtualSpace(0) > 0: editor.charLeft()
Rod T last edited by Rod T
Simplified script with console display option.
In order to better understand how the script was working and to help debug a couple of quirks I simplified the code by breaking it down to individual steps and then arranged for the values of the variables to be displayed on the console. It has an identical function to the original script used above and can be used as a direct replacement. I have included it here for anyone who may find it helpful.
To display the console select
Plugins -> Python Script -> ‘Show Console’
The script file itself can be viewed and edited
Plugins -> Python Script -> [Control] plus left click ‘Stop Left Wrap’
Replace the original script with the following…
n1 = editor.getCurrentPos() # Get the position of the cursor from the start of the document n2 = editor.lineFromPosition(n1) # Retrieve the line number of the current (n1) position n3 = editor.positionFromLine(n2) # Retrieve the position of the start of the current (n2) line n4 = editor.getSelectionNAnchorVirtualSpace(0) # Retrieve the number of virtual spaces to the left of the cursor if n1 != n3: editor.charLeft() # if current position is not the start of a line then 'move left' elif n4 > 0: editor.charLeft() # else if the number of virtual spaces to the left of the cursor # is greater than zero then 'move left' # The following allows all the variables to be written to the Console # It doesn't effect the operation of the script and can be deleted or commented out with a '#' if not required console.write("Variables:\n") console.write("n1 = %d\n" % n1) console.write("n2 = %d\n" % n2) console.write("n3 = %d\n" % n3) console.write("n4 = %d\n" % n4) console.write("\n")
dinkumoil last edited by
I wrote a plugin that can be used to configure left cursor movement to stop at left margin. Since this relies on a Scintilla setting you have to use at least Notepad++ v7.7. Untick option
Wrap cursor at line start. The plugin’s name is ExtSettings. You can download it >>> here <<<. It will also be available soon via PluginsAdmin.