Hi!
I have been reading the CPP lexer and i have noticed sometimes the author passes a new state with a flag, and after checking the definition of StyleContext I noticed that there is a parameter where you can indicate a value from where to start clearing flags off.
So I tried the following:
void SCI_METHOD Lexer::Lex(unsigned int startPos, int length, int initStyle, IDocument *pAccess)
{
LexAccessor styler(pAccess);
StyleContext sc(startPos, length, initStyle, styler, invSyntax-1);
for (; sc.More(); sc.Forward()) {
if (sc.atLineStart) {
}
// Exit current State
switch (sc.state) {
case COMMENT|fBlock:
if (sc.Match("*/")) {
sc.Forward(2);
sc.SetState(DEFAULT);
}
break;
}
// Enter a new State
if (sc.state == DEFAULT) {
if (sc.Match("/*"))
sc.SetState(COMMENT|fBlock);
}
}
sc.Complete();
}
I am sure fBlock is lower than invSyntax-1 so according to the definition that bit wont be reset and that is exactly like that when scintilla reads a whole file and renders it for the first time... as soon as one starts typing the flag is lost.
I am a bit of new on all this so please explain me why is it not working according to what i think is logical?
I know that when i start typing the Lex function gets called again and a new StyleContext object gets created but i thought that initStyle will still have the flag set and thus be passed to the new object as is!
Thanks for your support!