Browse Source

Merge branch 'master' into optimize-selectors

pull/3073/head
Dariusz Komosiński 7 years ago
committed by GitHub
parent
commit
562c3d3888
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  2. 5
      src/Avalonia.Controls/TreeView.cs
  3. 41
      tests/Avalonia.Controls.UnitTests/TreeViewTests.cs

2
src/Avalonia.Controls/Presenters/TextPresenter.cs

@ -244,7 +244,7 @@ namespace Avalonia.Controls.Presenters
var rect = FormattedText.HitTestTextPosition(caretIndex); var rect = FormattedText.HitTestTextPosition(caretIndex);
this.BringIntoView(rect); this.BringIntoView(rect);
}, },
DispatcherPriority.Normal); DispatcherPriority.Render);
} }
} }
} }

5
src/Avalonia.Controls/TreeView.cs

@ -1,3 +1,4 @@
// Copyright (c) The Avalonia Project. All rights reserved. // Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
@ -470,7 +471,7 @@ namespace Avalonia.Controls
if (index > 0) if (index > 0)
{ {
var previous = (TreeViewItem)parentGenerator.ContainerFromIndex(index - 1); var previous = (TreeViewItem)parentGenerator.ContainerFromIndex(index - 1);
result = previous.IsExpanded ? result = previous.IsExpanded && previous.ItemCount > 0 ?
(TreeViewItem)previous.ItemContainerGenerator.ContainerFromIndex(previous.ItemCount - 1) : (TreeViewItem)previous.ItemContainerGenerator.ContainerFromIndex(previous.ItemCount - 1) :
previous; previous;
} }
@ -482,7 +483,7 @@ namespace Avalonia.Controls
break; break;
case NavigationDirection.Down: case NavigationDirection.Down:
if (from.IsExpanded && intoChildren) if (from.IsExpanded && intoChildren && from.ItemCount > 0)
{ {
result = (TreeViewItem)from.ItemContainerGenerator.ContainerFromIndex(0); result = (TreeViewItem)from.ItemContainerGenerator.ContainerFromIndex(0);
} }

41
tests/Avalonia.Controls.UnitTests/TreeViewTests.cs

@ -14,6 +14,7 @@ using Avalonia.Input;
using Avalonia.Input.Platform; using Avalonia.Input.Platform;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.LogicalTree; using Avalonia.LogicalTree;
using Avalonia.Styling;
using Avalonia.UnitTests; using Avalonia.UnitTests;
using Xunit; using Xunit;
@ -892,6 +893,46 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(2, GetItem(target, 0, 1, 0).Level); Assert.Equal(2, GetItem(target, 0, 1, 0).Level);
} }
[Fact]
public void Auto_Expanding_In_Style_Should_Not_Break_Range_Selection()
{
/// Issue #2980.
using (UnitTestApplication.Start(TestServices.RealStyler))
{
var target = new DerivedTreeView
{
Template = CreateTreeViewTemplate(),
SelectionMode = SelectionMode.Multiple,
Items = new List<Node>
{
new Node { Value = "Root1", },
new Node { Value = "Root2", },
},
};
var visualRoot = new TestRoot
{
Styles =
{
new Style(x => x.OfType<TreeViewItem>())
{
Setters =
{
new Setter(TreeViewItem.IsExpandedProperty, true),
},
},
},
Child = target,
};
CreateNodeDataTemplate(target);
ApplyTemplates(target);
_mouse.Click(GetItem(target, 0));
_mouse.Click(GetItem(target, 1), modifiers: InputModifiers.Shift);
}
}
private void ApplyTemplates(TreeView tree) private void ApplyTemplates(TreeView tree)
{ {
tree.ApplyTemplate(); tree.ApplyTemplate();

Loading…
Cancel
Save