Skip to content

Instantly share code, notes, and snippets.

@tsekityam
Last active November 2, 2016 10:14
Show Gist options
  • Save tsekityam/14336c7bbee30f05c4c8b2aca700b5ee to your computer and use it in GitHub Desktop.
Save tsekityam/14336c7bbee30f05c4c8b2aca700b5ee to your computer and use it in GitHub Desktop.
Scintilla / Bugs / #1879 weird background colour of line with a marker on a zero width margin
  • How to reproduce:

    1. Add the following code to ScintilaTest xcode project, AppController.mm, - (void) setupEditor method.

// Marker setup. [mEditor setGeneralProperty: SCI_SETMARGINWIDTHN parameter: 1 value: 0]; [mEditor setGeneralProperty: SCI_MARKERDEFINEPIXMAP parameter: 0 value: (sptr_t)box_xpm]; [mEditor setGeneralProperty: SCI_MARKERADD parameter: 0 value: 0];

1. Run the project


* What do I see:

The first line has red bacground


* What do I expect:

The first line has white background, and there is no margin for the marker I added.
i.e. no visual diff between this program and the original program.


* What do I find

In `ViewStyle::CalculateMarginWidthAndMask()`, the bitwise operations on maskInLine will be skipped for margin with zero width. 

if (ms[margin].width > 0) maskInLine &= ~ms[margin].mask;


However, in `ViewStyle::Background(int marksOfLine, bool caretActive, bool lineContainsCaret)`, we will use maskInLine to do a checking. 

If these bitwise operations are skipped, the checking pass and the original background colour, white in this case, will be overwritten. 

int marksMasked = marksOfLine & maskInLine; if (marksMasked) { for (int markBit = 0; (markBit < 32) && marksMasked; markBit++) { if ((marksMasked & 1) && (markers[markBit].alpha == SC_ALPHA_NOALPHA)) { background = ColourOptional(markers[markBit].back, true); } marksMasked >>= 1; } }



* Possible fix

remove `if (ms[margin].width > 0)` from `ViewStyle::CalculateMarginWidthAndMask()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment