pnedev / comparePlus

Compare plugin for Notepad++
GNU General Public License v3.0
961 stars 139 forks source link

Resuming normal view clears the alpha channel from custom caret line background #356

Closed rdipardo closed 10 months ago

rdipardo commented 1 year ago

Steps to Reproduce

  1. Set the caret line background to a translucent color, e.g. 0x28FF009C; for example, by executing this NppExec script:

    SET SCI_SETELEMENTCOLOUR = 2753
    SET SCI_SETCARETLINELAYER = 2765
    SET SC_ELEMENT_CARET_LINE_BACK = 50
    SET SC_LAYER_UNDER_TEXT = 1
    SCI_SENDMSG $(SCI_SETELEMENTCOLOUR) $(SC_ELEMENT_CARET_LINE_BACK) 0x28FF009C
    SCI_SENDMSG $(SCI_SETCARETLINELAYER) $(SC_LAYER_UNDER_TEXT)
  2. Before opening the compare view, the caret line background should be translucent:

normal_view_before_compare_8 5 3

  1. Open the compare view; close it again.

  2. The caret line background is now solid:

normal_view_after_compare_npp_8 5 3

Problem code path

The setNormalView function uses a 24-bit BGR color mask that clears the top 8 alpha bits; it also sets the SC_LAYER_BASE flag, which will cancel transparency effects in any case:

https://github.com/pnedev/comparePlus/blob/64a9ee43bbda6755a0cdb784e6b1b3decdb0af6f/src/NppHelpers.cpp#L376-L382

This could be seen as a negative interaction with user scripts and other plugins that customize the caret line background. There's a least one case of a plugin developer thinking that the alpha channel was disappearing because of a bug in his own code.

Version

1.1

pnedev commented 1 year ago

@rdipardo ,

Thanks for reporting this and for the analysis. Notepad++ by default sets the caret line background color to 0xFFE8E8 and the layer used is SC_LAYER_BASE. Because in ComparePlus I'd like to make the diff color background visible when the caret is on its line and also the text should be visible (not blurred by alpha on upper layer) I change the caret line layer to SC_LAYER_UNDER_TEXT and set an alpha to the caret line background color. After compare is closed I would like to restore the view as Notepad++ has configured it.

Now if some other plugin also changes caret background color it will for sure interfere with ComparePlus.

If for example one plugin changes the color and then other plugin changes it immediately afterwards (on some event - in ComparePlus case it is notification about activation of another doc) then it is very important how the Notepad++ original setting will be restored. I will do some tests with CSVLint and ComparePlus when I get to this and will see if I can improve the things on my side.

BR

pnedev commented 10 months ago

Hi guys,

That is the best I can do : https://github.com/pnedev/comparePlus/commit/a374a82131a53f4c4e6fbc5ad397899d9cfc1091 I'm closing this issue now - please write again here if you think there is still something that can be done better.

Thanks. BR