Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#8655 from AvaloniaUI/use-correct-toggle…
Browse files Browse the repository at this point in the history
…Modifier-for-treeView-on-macOS-with-multiselection

Use correct ToggleModifier in TreeView multiselection on MacOS
  • Loading branch information
Takoooooo authored and grokys committed Aug 3, 2022
1 parent fb607cc commit 765c4d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/TreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
e.Source,
true,
e.KeyModifiers.HasAllFlags(KeyModifiers.Shift),
e.KeyModifiers.HasAllFlags(KeyModifiers.Control),
e.KeyModifiers.HasAllFlags(AvaloniaLocator.Current.GetRequiredService<PlatformHotkeyConfiguration>().CommandModifiers),
point.Properties.IsRightButtonPressed);
}
}
Expand Down
38 changes: 21 additions & 17 deletions tests/Avalonia.Controls.UnitTests/TreeViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Avalonia.Styling;
using Avalonia.UnitTests;
using JetBrains.Annotations;
using Moq;
using Xunit;

namespace Avalonia.Controls.UnitTests
Expand Down Expand Up @@ -856,28 +857,31 @@ public void Pressing_SelectAll_Gesture_With_Upward_Range_Selected_Should_Select_
[Fact]
public void Right_Click_On_SelectedItem_Should_Not_Clear_Existing_Selection()
{
var tree = CreateTestTreeData();
var target = new TreeView
using (UnitTestApplication.Start())
{
Template = CreateTreeViewTemplate(),
Items = tree,
SelectionMode = SelectionMode.Multiple,
};

var visualRoot = new TestRoot();
visualRoot.Child = target;
var tree = CreateTestTreeData();
var target = new TreeView
{
Template = CreateTreeViewTemplate(),
Items = tree,
SelectionMode = SelectionMode.Multiple,
};
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
var visualRoot = new TestRoot();
visualRoot.Child = target;

CreateNodeDataTemplate(target);
ApplyTemplates(target);
target.ExpandSubTree((TreeViewItem)target.Presenter.Panel.Children[0]);
target.SelectAll();
CreateNodeDataTemplate(target);
ApplyTemplates(target);
target.ExpandSubTree((TreeViewItem)target.Presenter.Panel.Children[0]);
target.SelectAll();

AssertChildrenSelected(target, tree[0]);
Assert.Equal(5, target.SelectedItems.Count);
AssertChildrenSelected(target, tree[0]);
Assert.Equal(5, target.SelectedItems.Count);

_mouse.Click((Interactive)target.Presenter.Panel.Children[0], MouseButton.Right);
_mouse.Click((Interactive)target.Presenter.Panel.Children[0], MouseButton.Right);

Assert.Equal(5, target.SelectedItems.Count);
Assert.Equal(5, target.SelectedItems.Count);
}
}

[Fact]
Expand Down

0 comments on commit 765c4d7

Please sign in to comment.