Add ITreeViewFilter (#2599)

Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
Thomas Nind
2023-05-10 05:37:24 +01:00
committed by GitHub
parent 958a0ed3eb
commit 8f199cd765
5 changed files with 213 additions and 8 deletions

View File

@@ -908,6 +908,74 @@ namespace Terminal.Gui.ViewTests {
new [] { tv.ColorScheme.Normal, pink });
}
[Fact, AutoInitShutdown]
public void TestTreeView_Filter ()
{
var tv = new TreeView { Width = 20, Height = 10 };
var n1 = new TreeNode ("root one");
var n1_1 = new TreeNode ("leaf 1");
var n1_2 = new TreeNode ("leaf 2");
n1.Children.Add (n1_1);
n1.Children.Add (n1_2);
var n2 = new TreeNode ("root two");
tv.AddObject (n1);
tv.AddObject (n2);
tv.Expand (n1);
tv.ColorScheme = new ColorScheme ();
tv.Redraw (tv.Bounds);
// Normal drawing of the tree view
TestHelpers.AssertDriverContentsAre (
@"
├-root one
│ ├─leaf 1
│ └─leaf 2
└─root two
", output);
var filter = new TreeViewTextFilter<ITreeNode> (tv);
tv.Filter = filter;
// matches nothing
filter.Text = "asdfjhasdf";
tv.Redraw (tv.Bounds);
// Normal drawing of the tree view
TestHelpers.AssertDriverContentsAre (
@"", output);
// Matches everything
filter.Text = "root";
tv.Redraw (tv.Bounds);
TestHelpers.AssertDriverContentsAre (
@"
├-root one
│ ├─leaf 1
│ └─leaf 2
└─root two
", output);
// Matches 2 leaf nodes
filter.Text = "leaf";
tv.Redraw (tv.Bounds);
TestHelpers.AssertDriverContentsAre (
@"
├-root one
│ ├─leaf 1
│ └─leaf 2
", output);
// Matches 1 leaf nodes
filter.Text = "leaf 1";
tv.Redraw (tv.Bounds);
TestHelpers.AssertDriverContentsAre (
@"
├-root one
│ ├─leaf 1
", output);
}
[Fact, AutoInitShutdown]
public void DesiredCursorVisibility_MultiSelect ()
{