Community
    • Login

    Feature request - Left cursor movement to stop at left margin

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    25 Posts 4 Posters 17.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Rod TR
      Rod T @Scott Sumner
      last edited by

      @Scott-Sumner

      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()

      Configure Shortcut

      • 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 TR 1 Reply Last reply Reply Quote 1
      • Rod TR
        Rod T @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

        1 Reply Last reply Reply Quote 0
        • Rod TR
          Rod T
          last edited by

          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()

          1 Reply Last reply Reply Quote 1
          • Rod TR
            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")
            
            1 Reply Last reply Reply Quote 1
            • dinkumoilD
              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.

              1 Reply Last reply Reply Quote 1
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors