desjarlais/Scintilla.NET

Function segmentation and Accolade

Void-Spce opened this issue · 19 comments

If I want to segment a part of the code between two brackets or a function, is there a Regex or Property that I can set? And is it the same in different lexers?
Also, how can I close automatically when a bracket, parenthesis, brace, tag is written in html and xml?

Untitled

There are a couple questions here, for the sake of this post, I'll stick to the first, which is "to segment a part of the code between two brackets or a function...?"

Where are you expecting the segmenting to happen, immediately after the first bracket? Also, what is the intent of the line that essentially the white space after it does not provide?

The last question is different, but the first and second questions are also complementary because the BackEnd codes are different from the FrontEnd, I want this division to be done on the opened accolade because I want the function name, but in Xml or Html on the first tag opened in Wherever this division is done.
Can I ask the last question in another question?

I would add the last question in a separate issue.

As for the original questions, are you looking for a visible segmentation? Can you provide repro steps for what you are seeing?

Untitled Untitled2 Untitled3 Untitled5 Untitled6 Untitled7

In the images above, the codes are normal and summarized, can this division be done like the Visual Studio environment, or does it put a horizontal line under all the segments?

What is the code you are using to setup the fold and margins? I don't repro this issue.

scintilla.IndentationGuides = IndentView.LookBoth;
scintilla.Styles[Style.BraceLight].BackColor = Color.LightGray;
scintilla.Styles[Style.BraceLight].ForeColor = Color.Black;
scintilla.ExtraAscent = 10;
scintilla.ExtraDescent = 10;
scintilla.TabIndents = true;
scintilla.Margins[0].Width = 30;
scintilla.Margins[1].Width = 40;
scintilla.AutomaticFold = AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change;
scintilla.SetFoldFlags(FoldFlags.LineBeforeExpanded);

I use these settings but there is no fold

result:
Untitled

I don't see the horizontal line in your screenshot, I'm confused about what you are trying to accomplish. I thought you were asking how to remove it?

My question is how do I fold the code in Scintilla since there is no code folding square in the settings I made for the library?
Is it possible to customize the appearance of code folding to look like Visual Studio?
If you look carefully, in the 6 images I sent you, you can see how to fold the codes in Visual Studio and Notepad 3. I think the Notepad3 program used your library and the folded code looks primitive. Can I change its appearance?
For now, I just want the codes to be folded.

result:
295491424-75048f88-20f6-43d1-8d1b-840b07828dd0

This gives the same result. I want there to be + and - signs for nested tags so that I can, for example, by pressing the - sign, a tag will be closed with internal tags, and that sign will change to +, then by pressing the + sign again, all View tags.

What I want is the following and it happens in all Lexers:

Rec 0001

I'm not sure how you are modifying it, but they are not the same result and it does get you closer from what I can tell. If you literally copy and paste from the link I sent, you should get this:

image

This will get you the + and -, look at the comment "// Style the folder markers" and you likely only need to add the ascent from your earlier question.

So the only thing missing is showing the end tag with the start tag in an enclosed textbox when collapsed, correct?

I use your code with some changes in the settings in this way, is there a problem with these settings, it means that these settings must be done in the form of the code you wrote:

scintilla.StyleResetDefault();
scintilla.Styles[Style.Default].Size = 12;
scintilla.IndentationGuides = IndentView.LookBoth;
scintilla.Styles[Style.BraceLight].BackColor = Color.LightGray;
scintilla.Styles[Style.BraceLight].ForeColor = Color.Black;
scintilla.ExtraAscent = 10;
scintilla.ExtraDescent = 10;
scintilla.TabIndents = true;
            
scintilla.SetProperty("fold", "1");
scintilla.SetProperty("fold.compact", "1");
scintilla.SetProperty("fold.html", "1");
scintilla.Margins[0].Width = 100;
scintilla.Margins[1].Width = 20;
scintilla.Margins[2].Width = 30;
scintilla.Margins[2].Type = MarginType.Symbol;
scintilla.Margins[2].Mask = Marker.MaskFolders;
scintilla.Margins[2].Sensitive = true;
            
for (int i = Marker.FolderEnd; i <= Marker.FolderOpen; i++)
{
       scintilla.Markers[i].SetForeColor(SystemColors.ControlLightLight);
       scintilla.Markers[i].SetBackColor(SystemColors.ControlDark);
}

scintilla.Markers[Marker.Folder].Symbol = MarkerSymbol.BoxPlus;
scintilla.Markers[Marker.Folder].SetBackColor(SystemColors.ControlText);
scintilla.Markers[Marker.FolderOpen].Symbol = MarkerSymbol.BoxMinus;
scintilla.Markers[Marker.FolderEnd].Symbol = MarkerSymbol.BoxPlusConnected;
scintilla.Markers[Marker.FolderEnd].SetBackColor(SystemColors.ControlText);
scintilla.Markers[Marker.FolderMidTail].Symbol = MarkerSymbol.TCorner;
scintilla.Markers[Marker.FolderOpenMid].Symbol = MarkerSymbol.BoxMinusConnected;
scintilla.Markers[Marker.FolderSub].Symbol = MarkerSymbol.VLine;
scintilla.Markers[Marker.FolderTail].Symbol = MarkerSymbol.LCorner;

scintilla.AutomaticFold = AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change;

switch (extFile.Replace(".", "").ToLower())
{
          case "xml":
                    scintilla.LexerName = "xml";

                    scintilla.Styles[Style.Xml.Tag].ForeColor = Color.LightCoral;
                    scintilla.Styles[Style.Xml.Comment].ForeColor = Color.DarkCyan;
                    scintilla.Styles[Style.Xml.Attribute].ForeColor = Color.RoyalBlue;
                    scintilla.Styles[Style.Xml.Entity].ForeColor = Color.RoyalBlue;
                    scintilla.Styles[Style.Xml.DoubleString].ForeColor = Color.Gray;
                    scintilla.Styles[Style.Xml.SingleString].ForeColor = Color.Gray;
               break;
}

Is that closer to what you are looking for, with the only difference being the collapsed textbox showing "Start Tag ... End Tag"?

I have even put

scintilla.Styles[Style.Xml.XmlStart].ForeColor = Color.Blue;
scintilla.Styles[Style.Xml.TagEnd].ForeColor = Color.Blue;

but the + and - signs are still not added. I am using Scintilla.NET version 5.3.2.9 in .net core 7 Is it possible that the problem is with the library version?

Possibly, use the Scintilla5.NET package from nuget, which should be up to date.

scintilla.StyleResetDefault();
scintilla.Styles[Style.Default].Size=12;
scintilla.IndentationGuides=IndentView.LookBoth;
scintilla.Styles[Style.BraceLight].BackColor=Color.LightGray;
scintilla.Styles[Style.BraceLight].ForeColor=Color.Black;
scintilla.ExtraAscent=10;
scintilla.ExtraDescent=10;
scintilla.TabIndents=true;
scintilla.SetProperty("fold","1");
scintilla.SetProperty("fold.compact","1");
scintilla.SetProperty("fold.html","1");
scintilla.Margins[0].Width=100;
scintilla.Margins[1].Width=20;
scintilla.Margins[2].Width=30;
scintilla.Margins[2].Type=MarginType.Symbol;
scintilla.Margins[2].Mask=Marker.MaskFolders;
scintilla.Margins[2].Sensitive=true;

for(inti=Marker.FolderEnd;i<=Marker.FolderOpen;i++)
{
    scintilla.Markers[i].SetForeColor(SystemColors.ControlLightLight);
    scintilla.Markers[i].SetBackColor(SystemColors.ControlDark);
}

scintilla.Markers[Marker.Folder].Symbol=MarkerSymbol.BoxPlus;
scintilla.Markers[Marker.Folder].SetBackColor(SystemColors.ControlText);
scintilla.Markers[Marker.FolderOpen].Symbol=MarkerSymbol.BoxMinus;
scintilla.Markers[Marker.FolderEnd].Symbol=MarkerSymbol.BoxPlusConnected;
scintilla.Markers[Marker.FolderEnd].SetBackColor(SystemColors.ControlText);
scintilla.Markers[Marker.FolderMidTail].Symbol=MarkerSymbol.TCorner;
scintilla.Markers[Marker.FolderOpenMid].Symbol=MarkerSymbol.BoxMinusConnected;
scintilla.Markers[Marker.FolderSub].Symbol=MarkerSymbol.VLine;
scintilla.Markers[Marker.FolderTail].Symbol=MarkerSymbol.LCorner;

scintilla.AutomaticFold=AutomaticFold.Show|AutomaticFold.Click|AutomaticFold.Change;

switch(extFile.Replace(".","").ToLower())
{
    case"xml":
      scintilla.LexerName="xml";
      scintilla.Lexer=Lexer.Xml;
      scintilla.Styles[Style.Xml.Tag].ForeColor=Color.LightCoral;
      scintilla.Styles[Style.Xml.Comment].ForeColor=Color.DarkCyan;
      scintilla.Styles[Style.Xml.Attribute].ForeColor=Color.RoyalBlue;
      scintilla.Styles[Style.Xml.Entity].ForeColor=Color.RoyalBlue;
      scintilla.Styles[Style.Xml.DoubleString].ForeColor=Color.Gray;
      scintilla.Styles[Style.Xml.SingleString].ForeColor=Color.Gray;
      scintilla.Styles[Style.Xml.XmlStart].ForeColor=Color.Blue;
      scintilla.Styles[Style.Xml.TagEnd].ForeColor=Color.Blue;
   break;
}

result:
Untitled

library:
Untitled2

Now, if you do the same code in the same way, what result will it give you? in .net core

Another point is that, I make scintilla as Runtime and do not bring it in Design Mode, that is, when the user clicks on a file, I bring scintilla as follows:

var txtIde = new Scintilla()
{
                     Text = File.ReadAllText($@"Path"),
                     Dock = DockStyle.Fill
};
Controls.Add(txtIde);

The runtime isn't the problem, when you set the following appears to be the problem:

scintilla.LexerName = "xml";

move that call to the beginning of your code to set the style/props:

scintilla.LexerName="xml";
scintilla.StyleResetDefault();
scintilla.Styles[Style.Default].Size=12;
scintilla.IndentationGuides=IndentView.LookBoth;
scintilla.Styles[Style.BraceLight].BackColor=Color.LightGray;
scintilla.Styles[Style.BraceLight].ForeColor=Color.Black;
scintilla.ExtraAscent=10;
scintilla.ExtraDescent=10;
scintilla.TabIndents=true;
scintilla.SetProperty("fold","1");
scintilla.SetProperty("fold.compact","1");
scintilla.SetProperty("fold.html","1");
scintilla.Margins[0].Width=100;
scintilla.Margins[1].Width=20;
scintilla.Margins[2].Width=30;
scintilla.Margins[2].Type=MarginType.Symbol;
scintilla.Margins[2].Mask=Marker.MaskFolders;
scintilla.Margins[2].Sensitive=true;

for(inti=Marker.FolderEnd;i<=Marker.FolderOpen;i++)
{
scintilla.Markers[i].SetForeColor(SystemColors.ControlLightLight);
scintilla.Markers[i].SetBackColor(SystemColors.ControlDark);
}

scintilla.Markers[Marker.Folder].Symbol=MarkerSymbol.BoxPlus;
scintilla.Markers[Marker.Folder].SetBackColor(SystemColors.ControlText);
scintilla.Markers[Marker.FolderOpen].Symbol=MarkerSymbol.BoxMinus;
scintilla.Markers[Marker.FolderEnd].Symbol=MarkerSymbol.BoxPlusConnected;
scintilla.Markers[Marker.FolderEnd].SetBackColor(SystemColors.ControlText);
scintilla.Markers[Marker.FolderMidTail].Symbol=MarkerSymbol.TCorner;
scintilla.Markers[Marker.FolderOpenMid].Symbol=MarkerSymbol.BoxMinusConnected;
scintilla.Markers[Marker.FolderSub].Symbol=MarkerSymbol.VLine;
scintilla.Markers[Marker.FolderTail].Symbol=MarkerSymbol.LCorner;

scintilla.AutomaticFold=AutomaticFold.Show|AutomaticFold.Click|AutomaticFold.Change;

switch(extFile.Replace(".","").ToLower())
{
case"xml":
scintilla.Styles[Style.Xml.Tag].ForeColor=Color.LightCoral;
scintilla.Styles[Style.Xml.Comment].ForeColor=Color.DarkCyan;
scintilla.Styles[Style.Xml.Attribute].ForeColor=Color.RoyalBlue;
scintilla.Styles[Style.Xml.Entity].ForeColor=Color.RoyalBlue;
scintilla.Styles[Style.Xml.DoubleString].ForeColor=Color.Gray;
scintilla.Styles[Style.Xml.SingleString].ForeColor=Color.Gray;
scintilla.Styles[Style.Xml.XmlStart].ForeColor=Color.Blue;
scintilla.Styles[Style.Xml.TagEnd].ForeColor=Color.Blue;
break;
}

Thank you
What should be done just to make the size + and - smaller, because it is big?

Can the folding be customized, that is, it can be done in Visual Studio.

Untitled

Try a smaller margin 2 width:

scintilla.Margins[2].Width=15;