Skip to content

Commit

Permalink
Merge branch 'stable/0.10.x' of https://github.com/AvaloniaUI/Avalonia
Browse files Browse the repository at this point in the history
…into stable/0.10.x
  • Loading branch information
Takoooooo committed May 10, 2022
2 parents fa7294a + 4f3fa13 commit 81e5fe8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/Avalonia.Base/Threading/ThreadSafeObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ namespace Avalonia.Threading
public class ThreadSafeObjectPool<T> where T : class, new()
{
private Stack<T> _stack = new Stack<T>();
private object _lock = new object();
public static ThreadSafeObjectPool<T> Default { get; } = new ThreadSafeObjectPool<T>();

public T Get()
{
lock (_lock)
lock (_stack)
{
if(_stack.Count == 0)
return new T();
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/ItemsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ protected static IInputElement GetNextControl(
}

c = result;
} while (c != null && c != from);
} while (c != null && c != from && direction != NavigationDirection.First && direction != NavigationDirection.Last);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ protected internal virtual void PointerReleased(object sender, PointerReleasedEv

protected internal virtual void MenuOpened(object sender, RoutedEventArgs e)
{
if (e.Source == Menu)
if (e.Source is Menu)
{
Menu?.MoveSelection(NavigationDirection.First, true);
}
Expand Down
1 change: 1 addition & 0 deletions src/Skia/Avalonia.Skia/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public DrawingContextImpl(CreateInfo createInfo, params IDisposable[] disposable
SKCanvas ISkiaDrawingContextImpl.SkCanvas => Canvas;
SKSurface ISkiaDrawingContextImpl.SkSurface => Surface;
GRContext ISkiaDrawingContextImpl.GrContext => _grContext;
double ISkiaDrawingContextImpl.CurrentOpacity => _currentOpacity;

/// <inheritdoc />
public void Clear(Color color)
Expand Down
1 change: 1 addition & 0 deletions src/Skia/Avalonia.Skia/ISkiaDrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public interface ISkiaDrawingContextImpl : IDrawingContextImpl
SKCanvas SkCanvas { get; }
GRContext GrContext { get; }
SKSurface SkSurface { get; }
double CurrentOpacity { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using Avalonia.Collections;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
Expand Down Expand Up @@ -1610,6 +1612,50 @@ public void MoveSelection_Wrap_Does_Not_Hang_With_No_Focusable_Controls()
target.MoveSelection(NavigationDirection.Next, true);
}

[Fact(Timeout = 2000)]
public async Task MoveSelection_Does_Not_Hang_With_No_Focusable_Controls_And_Moving_Selection_To_The_First_Item()
{
var target = new TestSelector
{
Template = Template(),
Items = new[]
{
new ListBoxItem { Focusable = false },
new ListBoxItem(),
}
};

target.Measure(new Size(100, 100));
target.Arrange(new Rect(0, 0, 100, 100));

// Timeout in xUnit doesen't work with synchronous methods so we need to apply hack below.
// https://github.com/xunit/xunit/issues/2222
await Task.Run(() => target.MoveSelection(NavigationDirection.First, true));
Assert.Equal(-1, target.SelectedIndex);
}

[Fact(Timeout = 2000)]
public async Task MoveSelection_Does_Not_Hang_With_No_Focusable_Controls_And_Moving_Selection_To_The_Last_Item()
{
var target = new TestSelector
{
Template = Template(),
Items = new[]
{
new ListBoxItem(),
new ListBoxItem { Focusable = false },
}
};

target.Measure(new Size(100, 100));
target.Arrange(new Rect(0, 0, 100, 100));

// Timeout in xUnit doesen't work with synchronous methods so we need to apply hack below.
// https://github.com/xunit/xunit/issues/2222
await Task.Run(() => target.MoveSelection(NavigationDirection.Last, true));
Assert.Equal(-1, target.SelectedIndex);
}

[Fact]
public void MoveSelection_Does_Select_Disabled_Controls()
{
Expand Down

0 comments on commit 81e5fe8

Please sign in to comment.