Sintax highlighting breaks when switching between languages

Feb 22, 2010 at 4:46 PM

Hello!

There's a problem with scintilla control. When I switch between languages (js and mssql for example), using

 this.scintilla1.ConfigurationManager.Language = "js"; //or = "mssql"

code line, syntax highlighting of text in the control gets broken (colors of highlighting are wrong and folding remains unchanged from previous language).

Looks like it is a bug of the scintilla control.

If I type any character in the document after this, the highlighting is fixed in all the document below the position where the character was typed.

Taking this into account, could anyone prompt me any workarounds for this bug? Maybe sending some messages directly to control after language switching or something like this. Or maybe it can be avoided with just adjusting some settings of the control.

Thanks a lot for any advice. I can send a test project and some screenshots of the bug reproducing if it helps.

Coordinator
Feb 23, 2010 at 2:20 AM

I think all that is needed is to "restyle" the contents once you've made the change. You could try:

this.scintilla.Lexing.Colorize();

 

Thanks,
Jacob

Mar 27, 2010 at 11:23 PM

I have the same problem and scintilla.Lexing.Colorize(); does not help.

Below I attache part of  test code I'm using.

First I'm highlighting XML code. Then I change to HTML language. This is ok.

If I switch to XML now, text is highlighted as HTML.

I'm using Windows Vista 64 bit.

Project is build for x86 platform.

 

Do you have such problems?

May be I do something wrong?

 

 

bool change = false;

private void ChangeLanguage()
{
	if (change)
	{
		LoadHtml();
	}
	else
	{
		LoadXml();
	}
	scintilla1.Lexing.Colorize();

	change = ! change;
}

private void LoadHtml()
{
	scintilla1.ConfigurationManager.Language = "html";

	scintilla1.Text = "<html>\r\n"+
	"<body>\r\n" +
	"Hello World !!! <input name=\"testId\" />\r\n" +
	"</body>\r\n" +
	"</html>";	
}

private void LoadXml()
{
	scintilla1.ConfigurationManager.Language = "xml";

	scintilla1.Text = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
	"<element>\r\n" +
	"   <first>\r\n" +
	"      <value>Hello World</value>\r\n" +
	"   </first>\r\n" +
	"</element>\r\n";	
}

Coordinator
Apr 7, 2010 at 5:21 PM

This is a configuration bug with xml. Easiest way to work around it is

 

scintilla1.Lexing.SetKeywords(0, string.Empty);

It was still thinking that it needed to highlight only certain elements leftover from html. Html and Xml both use the same lexer.