desjarlais / Scintilla.NET

A Windows Forms control, wrapper, and bindings for the Scintilla text editor.
MIT License
107 stars 25 forks source link

Adding functions to StyleNeeded with LexerName #127

Closed latafy closed 5 months ago

latafy commented 5 months ago

Is there any way to add functions to the StyleNeeded event when there is a LexerName such as "python" present? It seems to be possible to add multiple functions for this event when there is no lexer being used, but it does not work no matter what I tried if there is a built in lexer being used already.

desjarlais commented 5 months ago

Can you provide a sample showing the problem behavior?

latafy commented 5 months ago

this is a sample showing the StyleNeeded with multiple functions, even after the first function finishes the styling. Setting the scintilla.LexerName to a valid lexer such as "python" will not allow you to run the added functions anymore on a styleneeded event.

scintilla.LexerName = string.Empty; //replace with python and below functions are obsolete
scintilla.StyleNeeded += (s, se) =>
{
    var startPos = scintilla.GetEndStyled();
    var endPos = se.Position;
    Debug.WriteLine("first" + startPos.ToString() + " " + endPos.ToString());
    //can do whatever here
    scintilla.StartStyling(endPos + 1);
};
scintilla.StyleNeeded += (s, se) =>
{
    var startPos = scintilla.GetEndStyled(); //this should already be the end 
    var endPos = se.Position;
    Debug.WriteLine("second " + startPos.ToString() + " " + endPos.ToString());
    //can do whatever here
    //scintilla.StartStyling(endPos + 1); //dont need

};
desjarlais commented 5 months ago

Thank you for the sample, I will look into this and let you know what I can figure out.

desjarlais commented 5 months ago

I'm pretty sure StyleNeeded only works with an empty container, so this seems by design and setting the LexerName to anything else will cause the event to stop being used.

https://www.scintilla.org/ScintillaDoc.html#SCN_STYLENEEDED

desjarlais commented 5 months ago

Closing for now, but if this does not answer your question, re-activate the issue.