Menu

#2335 Selections use bug colour when format range is used

Bug
closed-fixed
nobody
5
2022-08-27
2022-06-09
No

Selections end up being drawn in bug colour when used SCI_FORMATRANGE when hideSelection is false. Fix is probably to hide selections and doing that before format range is called works.

Discussion

  • Neil Hodgson

    Neil Hodgson - 2022-06-09

    There was a similar case addressed with [ce4227]. Possibly reuse that approach.

     

    Related

    Commit: [ce4227]

  • John Ehresman

    John Ehresman - 2022-06-10

    Does that work when single phase drawing is used?

     
  • Neil Hodgson

    Neil Hodgson - 2022-06-10

    In SciTE the main selection is OK but additional selections are bug colour. Secondary selections on Unix could be an issue.

    PDF print of selections

     
  • John Ehresman

    John Ehresman - 2022-06-10

    I'm reasonably sure that setting all of the selection backgrounds elements to have an alpha of 0 would work for multi-phase drawing, but what about single phase? I just switched to using multi-phase to get alpha values to work -- the colors are always opaque in single-phase. Or, does format range always use multi-phase?

     
    • Neil Hodgson

      Neil Hodgson - 2022-06-10

      Or, does format range always use multi-phase?

      It uses the same phasesDraw as the screen which can be One (0 = single-phase) as in the image. On Win32, printing always uses GDI (Technology::Default) instead of DirectDraw and GDI does not implement alpha for all methods.

       
  • Neil Hodgson

    Neil Hodgson - 2022-06-17
    • labels: Scintilla --> Scintilla, printing
    • status: open --> open-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2022-06-17

    Fixed with [fc46d7].

     

    Related

    Commit: [fc46d7]

  • Neil Hodgson

    Neil Hodgson - 2022-07-09
    • status: open-fixed --> closed-fixed
     
  • rdipardo

    rdipardo - 2022-07-13

    This bug continues to bedevil Notepad++, despite the application of both [ce4227] and [fc46d7]: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/11911

    I suspect something application-specific, as wscite prints exactly what is expected with print.colour.mode=2. By trial and error, I found that executing SCI_SETSELECTIONLAYER with SC_LAYER_UNDER_TEXTwas necessary to make the (inactive) style of the selected region transparent, but the chief maintainer prefers to hear it from the horse's mouth, and it seems his SF credentials have lapsed.

     

    Related

    Commit: [ce4227]
    Commit: [fc46d7]


    Last edit: rdipardo 2022-07-13
    • Neil Hodgson

      Neil Hodgson - 2022-07-14

      Here is a potential fix: the problem was that layer 0 drawing is stripping the alpha so uses the colour fully opaque. The patch uses the StyleMain background colour (for layer 0) and fully transparent (for other layers). Since it uses StyleMain, it has to be moved after the PrintOption handling as that may choose a different background colour.

       
  • Neil Hodgson

    Neil Hodgson - 2022-07-14
    • status: closed-fixed --> open-accepted
     
  • rdipardo

    rdipardo - 2022-07-14

    The latest patch appears to let the colour scheme's background show through. OK when it happens to be solid white, but "Vim Dark Blue" obscures the text with its namesake colour:

    npp-8-4-3-print-sel

    npp-8-4-3-print-sel-rendered

    As before, a preemptive call to SCI_SETSELECTIONLAYER with SC_LAYER_UNDER_TEXT before the range is formatted appears to be an effective workaround. Still no clue why that may be.

     
    • Neil Hodgson

      Neil Hodgson - 2022-07-14

      This likely needs a different approach like forcing hideSelection on during FormatRange or moving it to ViewStyle so it can be always on for vsPrint.

       
  • rdipardo

    rdipardo - 2022-07-15

    I should've mentioned that Notepad++ has only partly adopted the SCI_SETELEMENTCOLOUR APIs, and only in cases where the v4 APIs fail to produce the accustomed result (*1). Of the four element styles that [fc46d7] addressed, the editor only sets one of them explicitly (possibly two, if SCI_SETSELBACK has any influence on Element::SelectionBack):

    // PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
    
    execute(SCI_SETSELBACK, 1, selectColorBack);
    execute(SCI_SETELEMENTCOLOUR, SC_ELEMENT_SELECTION_INACTIVE_BACK, selectColorBack);
    

    Grepping the application code for SC_ELEMENT_SELECTION_(SECONDARY_|ADDITIONAL_|)BACK currently returns nothing.

    Unfortunately the maintainer still thinks an upstream solution is forthcoming. Maybe some kind of illustrated tutorial on how selection styles work in v5 would help.


    (*1) https://github.com/notepad-plus-plus/notepad-plus-plus/commit/b6efff4157dd1176e2763af94555af16a13cbc48

     

    Related

    Commit: [fc46d7]

    • Neil Hodgson

      Neil Hodgson - 2022-07-15

      There'll probably be a hideSelection change at some point but other things have higher priority.

      For now, the app may be able to work around this by hiding the selection before calling FormatRange then restoring its preference.

       
  • Neil Hodgson

    Neil Hodgson - 2022-07-18

    Here's a potential fix that adds a selection.visible field to ViewStyle that is set false on the printing ViewStyle. Its meaning is inverted as the selection is normally visible and most uses of hideSelection were negated. Also adds a SCI_GETSELECTIONHIDDEN API for symmetry and testing.

     
  • rdipardo

    rdipardo - 2022-07-21

    The latest patch seems to resolve the issue with Notepad++. Also tried it with SciTE and noticed one minor quirk. When the system's print dialog launches, the selection style completely disappears from SciTE's edit view until the range format is completed. In N++ it's visible throughout, but I think that can be set down to the latter's continued preference for v4's APIs. The series of patches beginning with [ce4227] assume a graphics device supporting alpha channels, but a glance at N++'s code finds nothing but 24-bit COLORREFs.

     

    Related

    Commit: [ce4227]

  • Neil Hodgson

    Neil Hodgson - 2022-07-22
    • status: open-accepted --> open-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2022-07-22

    Fixed with [ac7c97] and [3a40bb].

     

    Related

    Commit: [3a40bb]
    Commit: [ac7c97]

  • Neil Hodgson

    Neil Hodgson - 2022-08-27
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB