[v.7.8.6] Vertical Edge Settings no longer works with Split Lines (Ctrl-I)



  • @Michael-Alden

    Thanks for your contribution.
    It is a Lua variation on @Michael-Vincent 's original NppExec solution.
    There hasn’t been a Pythonscript implementation, so I’ll add that now:

    editor.setEdgeMode(1)
    editor.setEdgeColumn(80)
    


  • @Alan-Kilborn said in [v.7.8.6] Vertical Edge Settings no longer works with Split Lines (Ctrl-I):

    Pythonscript implementation

    And of course “PerlScript”:

        editor->setEdgeMode( $SC_EDGEMODE{EDGE_LINE} );
        editor->setEdgeColumn(80);
    

    Cheers.





  • @Matthew-Au @rd4gh @Alan-Kilborn @Michael-Vincent and all

    Since this is the older thread I will drop my two cents here.

    Notepad++ v7.8.6 introduced support for drawing multiple vertical lines (also called “edges”) inside of an editor window. But this new feature is not simply an extension of the old well-known single-edge-line feature, instead it is a completely new edge mode that replaced the old one. Unfortunately this broke the ability to word-wrap a document’s content at such an edge line (using the standard keyboard shortcut Ctrl+I).

    In the following I provide some scripts for the NppExec plugin to get back the old single-edge-line feature and being able to control it. Additionally I provide a fixed implementation of the related “word-wrap at single-edge-line” feature. That’s because I became aware that Notepad++'s internal implementation of this feature has two bugs:

    1. If the font size of the line numbers margin is set to a different value than the font size for documents, the “word-wrap at single-edge-line” code calculates a wrong wrapping position. This position has to be provided in pixels. To calculate this pixel value, a Scintilla function has to be called that calculates the width in pixels of a provided string from a provided text style. It seems like Notepad++'s internal code erroneously takes the text style of the line numbers margin font when calling this Scintilla function.

    2. To generate the template string for the pixel calculation mentioned above, it is necessary to query the set column number of the single-edge-line. Since column numbers in Scintilla are 0-based, the retrieved result has to be incremented by 1 to get the required length of the template string. It seems Notepad++'s internal code doesn’t do that because when word-wrapping a line that has a word boundary exactly at the single-edge-line it wraps this line at the beginning of that word instead at its end.

    Here are the scripts. Most of them could be assigned to a keyboard shortcut using Shortcut Mapper.

    Initialize Single-Edge-Line Mode

    ::SetSingleEdgeLine
    npp_console keep
    sci_sendmsg SCI_SETEDGECOLUMN 80
    sci_sendmsg SCI_SETEDGEMODE EDGE_LINE
    

    This script is intended to be used as a NppExec startup-script. It sets the single-edge-line column to column 80 and activates single-edge-line mode. It is able to override a multiple-edge-line or background-color-edge mode set in Notepad++ preferences dialog.

    Change Single-Edge-Line Column

    ::ConfigSingleEdgeLine
    npp_console keep
    sci_sendmsg SCI_GETEDGECOLUMN
    inputbox "Input edge column" : "Edge column" : $(MSG_RESULT)
    sci_sendmsg SCI_SETEDGECOLUMN $(INPUT)
    sci_sendmsg SCI_SETEDGEMODE EDGE_LINE
    

    This script opens an input box where users can change the single-edge-line column. The current column is shown as default value. When the user closes the box, the provided value is set as the new column and single-edge-line mode is activated.

    Turn on Single-Edge-Line Mode

    ::SingleEdgeLineOn
    npp_console keep
    sci_sendmsg SCI_SETEDGEMODE EDGE_LINE
    

    This script activates single-edge-line mode with its current settings.

    Turn on Multiple-Edge-Line Mode

    ::MultipleEdgeLinesOn
    npp_console keep
    sci_sendmsg SCI_SETEDGEMODE EDGE_MULTILINE
    

    This script activates multiple-edge-line mode with its current settings.

    Turn on Backgound-Color-Edge Mode

    ::BackgroundEdgeOn
    npp_console keep
    sci_sendmsg SCI_SETEDGEMODE EDGE_BACKGROUND
    

    This script activates background-color-edge mode with its current settings.

    Turn all Edges off

    ::EdgesOff
    npp_console keep
    sci_sendmsg SCI_SETEDGEMODE EDGE_NONE
    

    This script deactivates all edges.

    Word-Wrap Selected Text at Single-Edge-Line

    ::WrapSelectedLinesAtEdge
    npp_console keep
    
    set local $(EdgeModeSingleLine) ~ EDGE_LINE
    sci_sendmsg SCI_GETEDGEMODE
    
    if $(MSG_RESULT) != $(EdgeModeSingleLine) then
      set local $(LinePixelWidth) = 0
      goto :DoWrap
    endif
      
    sci_sendmsg SCI_GETEDGECOLUMN
    set local $(LineCharWidth) ~ $(MSG_RESULT) + 1
    
    set local $(TemplateStr) = W
    set local $(Cnt) = 2
    
    :ForLoopStart
      if $(Cnt) > $(LineCharWidth) goto :ForLoopEnd
      set local $(TemplateStr) = $(TemplateStr)W
      set local $(Cnt) ~ $(Cnt) + 1
    goto :ForLoopStart
    
    :ForLoopEnd
    sci_sendmsg SCI_TEXTWIDTH STYLE_DEFAULT "$(TemplateStr)"
    set local $(LinePixelWidth) = $(MSG_RESULT)
    
    :DoWrap
    sci_sendmsg SCI_TARGETFROMSELECTION
    sci_sendmsg SCI_LINESSPLIT $(LinePixelWidth)
    

    This script provides a fixed version of the “word-wrap at single-edge-line” feature. As the original one, it word-wraps at the right edit window border if edge mode is not set to single line. This script could be assigned to the Ctrl+I keyboard shortcut in order to replace the buggy built-in version of Notepad++.



  • Hello, @dinkumoil and All,

    Very interesting insight and solutions about the new multiple vertical edges and word-wrapping at a specific position …and, incidentally, some good and short examples of the NppExec scripting language ;-))

    One question :

    When trying to find out a regex emulation of the Ctrl + I feature, some months ago, I realized that some mandatory conditions were needed to get the expected behaviour. Refer to the middle part of this post

    • So, did you verify the behaviour of your last ::WrapSelectedLinesAtEdge script in these three cases :

    • A proportional font is used instead of the monospaced one ?

    • The EOL symbol is displayed, with the View > Show Symbol > Show End of Line or View > Show Symbol > Show All Characters options

    • The current file contains some tabulation characters, as the number of pixels used by a TAB char is generally different from the space character !

    Indeed, the Ctrl + I behaviour, with a single edge, seemed broken when one of these cases occur !

    Best Regards,

    guy038



  • @guy038

    Of course, I had not tested the behaviour of my WrapSelectedLinesAtEdge script in conjunction with a proportional font before you asked me because it makes no sense. ;-) Besides that, I’m sure it will not work .

    After testing I can say: I got the expected results.

    When using a proportional font, the edge line is still drawn as a straight vertical line and when moving the cursor up and down along this line, the Col : field of the status bar shows different values in every single line, depending on the crrent line’s content - obiously because the font is proportional and the characters have different widths. And when running my script, Scintilla does the word-wrap at totally wrong positions.

    An edge line simply makes no sense when using proportional fonts, thus my script makes no sense as well in this case. That’s the reason why I have not tested it and why I don’t care that it doesn’t work. :-)

    BTW: When I activated the proportional font in style configurator, Notepad++ immediately turned off the single-edge-line.



  • @dinkumoil said in [v.7.8.6] Vertical Edge Settings no longer works with Split Lines (Ctrl-I):

    If the font size of the line numbers margin is set to a different value than the font size for documents

    In experimenting with this, I think I discovered a hidden “feature”.
    It has been asked before how to get increased vertical spacing between lines in a document (visually only, of course).
    This seems to be another method:

    • Go into Style Configurator and set the Font size of the Line number margin to a large number, e.g. 28:
      Imgur

    The effect:

    Imgur

    OK, the line numbers are really large, but you could always turn them off (in which case the vertical spacing remains, even after restart of N++).

    Note: Regarding @dinkumoil 's comment, my new technique could really cause line-splitting with Ctrl+i to yield some wrong/undesired results!!



  • @Alan-Kilborn said in [v.7.8.6] Vertical Edge Settings no longer works with Split Lines (Ctrl-I):

    It has been asked before how to get increased vertical spacing between lines in a document (visually only, of course).

    Can you just use SCI_SETEXTRAASCENT and SCI_SETEXTRADESCENT?

    In NppExec:

    SCI_SENDMSG SCI_SETEXTRADESCENT 2
    

    I actually use the value of 1 in my startup script.

    Cheers.



  • @Michael-Vincent said in [v.7.8.6] Vertical Edge Settings no longer works with Split Lines (Ctrl-I):

    Can you just use SCI_SETEXTRAASCENT and SCI_SETEXTRADESCENT?

    Well, yes… I was just showing another way of doing it, and an interesting way at that. :-)

    And of course, there’s a leap to using NppExec (or the other usual suspect: PythonScript) that some people are unable/afraid to take.



  • @Alan-Kilborn

    Yes, I discovered that already in the past. Increasing inter-line spacing is also possible with other styles, for example the Brace highlight style.


Log in to reply