Hidden/invisible lines in TextEditor example request

Is there any example about implementing hidden lines in TextEditor? This feature was mentioned in release notes for 6 version.
Hello Alex,
This feature has been implemented. Here's example of code:
syntaxEdit1.DisplayLines.AllowHiddenLines = true;
int[] idx = new int[] { };//line numbers to hide.
syntaxEdit1.Source.SetLineHidden(idx, true);
Regards,
Andrew
I am trying to show just the body a method in a class file.
To do this I hide all the lines from the method signature and up. and All the lines from the last } down.
However when trying this out I discovered that a CTRL+SHIFT HOME / END appears to select the hidden lines. This means that pressing delete at this point results in the hidden lines being removed.
Is there a Hidden and ReadOnly feature on the cards?
Hello Rob,
This looks like a bug, we will fix it ASAP.
You can certainly mark these lines as hidden and readonly at the same time, so they will not be removed, however the proper fix would be to not select them in a first place.
Regards,
Andrew
Hello Rob,
Regarding your post about invisible lines in the editor:
For now you can subclass SyntaxEdit and override Selection method SelectAll like this:
public class SyntaxEditEx : SyntaxEdit
{
public SyntaxEditEx(System.ComponentModel.IContainer container)
: base(container)
{
}
protected override ISelection CreateSelection()
{
return new SelectionEx(this);
}
}
public class SelectionEx : Alternet.Editor.Selection
{
public SelectionEx(ISyntaxEdit owner)
: base(owner)
{
}
public override void SelectAll()
{
if (Owner.Lines.Count > 0)
{
SelStart = Owner.Position;
var firstLine = 0;
var lastLine = Owner.Lines.Count - 1;
if (Owner.DisplayLines.AllowHiddenLines)
{
while (firstLine <= lastLine && Owner.LineIsHidden(firstLine))
firstLine++;
while (lastLine >= firstLine && Owner.LineIsHidden(lastLine))
lastLine--;
}
if (firstLine <= lastLine)
SetSelection(SelectionType.Stream, new Rectangle(0, firstLine, Owner.Lines.GetLength(lastLine), lastLine));
}
}
}
This way Ctrl + A will select only lines being visible in the editor.
There might be few other places that would allow selecting invisible lines (like when you press Ctrl + Shift + Home), we will review them as well.
I would recommend to mark invisible lines as read-only as well, as this will prohibit any operations with them (such as deleting text to the left of the first character of first visible line)
Regards,
Andrew
Hi Andrew, Thanks for this. How do I go about making the lines read-only?
I should really think before hitting submit! 😅
syntaxEdit.Source.SetLineReadonly(index, isReadOnly)
Enhancement Request: Create an overload for the Hidden and Readonly methods -> SetLine*(int startIndex, int endIndex, readonly) to easily be able to mark blocks of code as readonly / hidden.
Hello Rob,
Thank you for you your suggestion, we will add such a method in the next release.
For now you can use the following code to set/remove lines to be readonly and hidden at the same time:
using Alternet.Editor.TextSource;
using Alternet.Syntax;

var indexes = new int[]{ 1, 2, 3 };
var source = syntaxEdit1.Source;
source.BeginUpdate(UpdateReason.Other);
try
{
foreach (var index in indexes)
{
var item = source.Lines.GetItem(index);
if (item != null)
{
item.State |= (ItemState.Hidden | ItemState.ReadOnly);
source.LinesChanged(index, index);
}
}
source.State |= NotifyState.Outline | NotifyState.BlockChanged;
}
finally
{
source.EndUpdate();
}
}
Regards,
Andrew