Blog edition accessibility
This commit is contained in:
parent
a131a6ddf8
commit
f1c23965b2
14 changed files with 656 additions and 16 deletions
241
src/PostIt/PostIt.Tests/AndroidMarkdownEditorTestActivity.cs
Normal file
241
src/PostIt/PostIt.Tests/AndroidMarkdownEditorTestActivity.cs
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
#if ANDROID
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Content.PM;
|
||||
using Android.OS;
|
||||
using Android.Views;
|
||||
using Android.Views.InputMethods;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.LogicalTree;
|
||||
using Avalonia.Threading;
|
||||
using AvaloniaEdit;
|
||||
using PostIt.Android;
|
||||
using PostIt.Controls;
|
||||
using PostIt.ViewModels;
|
||||
using PostIt.Views.Blogs;
|
||||
|
||||
namespace PostIt.Tests;
|
||||
|
||||
[Activity(Name = "fr.pschneider.postit.MarkdownEditorTestActivity", Exported = true)]
|
||||
public sealed class AndroidMarkdownEditorTestActivity : Activity
|
||||
{
|
||||
private string _stage = "startup";
|
||||
private ScreenOrientation? _previousOrientation;
|
||||
protected override async void OnCreate(Bundle? state)
|
||||
{
|
||||
base.OnCreate(state);
|
||||
var result = Path.Combine(FilesDir!.AbsolutePath, "markdown-editor-test-result.txt");
|
||||
File.WriteAllText(result, "RUNNING");
|
||||
try
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(60));
|
||||
await RunAsync(timeout.Token);
|
||||
File.WriteAllText(result, "PASS\nbounded viewport above IME,at least three visible lines,visible caret,keyboard reopen,retained focus");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
File.WriteAllText(result, $"FAIL at {_stage}\n" + ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
RunOnUiThread(Finish);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunAsync(CancellationToken ct)
|
||||
{
|
||||
if (!OperatingSystem.IsAndroidVersionAtLeast(30))
|
||||
throw new PlatformNotSupportedException("Android 11 required for keyboard visibility assertions.");
|
||||
StartActivity(new Intent(this, typeof(MainActivity)).AddFlags(ActivityFlags.NewTask));
|
||||
_stage = "waiting for main activity";
|
||||
await WaitAsync(() => MainActivity.IsForeground && (Avalonia.Application.Current as App)?.View is not null, ct);
|
||||
var root = ((App)Avalonia.Application.Current!).View!;
|
||||
if (Intent?.GetBooleanExtra("landscape", false) == true)
|
||||
{
|
||||
_previousOrientation = MainActivity.Current!.RequestedOrientation;
|
||||
MainActivity.Current.RequestedOrientation = ScreenOrientation.Landscape;
|
||||
await WaitAsync(() => TopLevel.GetTopLevel(root)!.ClientSize.Width > TopLevel.GetTopLevel(root)!.ClientSize.Height, ct);
|
||||
}
|
||||
var navigation = root.FindControl<NavigationPage>("NavRoot")!;
|
||||
BlogsPage? page = null;
|
||||
TextEditor? source = null;
|
||||
var focusLosses = 0;
|
||||
try
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(async () =>
|
||||
{
|
||||
page = new BlogsPage
|
||||
{
|
||||
DataContext = new BlogsViewModel
|
||||
{
|
||||
IsEditing = true,
|
||||
DraftTitle = "Local keyboard test",
|
||||
DraftArticle = string.Join("\n", Enumerable.Range(1, 150).Select(i => $"Line {i}: local keyboard test"))
|
||||
}
|
||||
};
|
||||
await navigation.PushAsync(page, null);
|
||||
source = page.GetLogicalDescendants().OfType<MarkdownEditorControl>().Single()
|
||||
.FindControl<TextEditor>("SourceEditor")!;
|
||||
});
|
||||
_stage = "waiting for editor layout";
|
||||
await WaitAsync(() => source!.TextArea.Bounds.Height > 0, ct);
|
||||
await Dispatcher.UIThread.InvokeAsync(() => CheckSystemBars(root));
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
if (!source!.TextArea.Focus())
|
||||
throw new InvalidOperationException("Unable to focus the mounted editor.");
|
||||
source.CaretOffset = source.Document.TextLength;
|
||||
source.TextArea.Caret.BringCaretToView();
|
||||
source.TextArea.LostFocus += (_, _) => focusLosses++;
|
||||
});
|
||||
_stage = "waiting for native input connection";
|
||||
await WaitAsync(() =>
|
||||
{
|
||||
var activity = MainActivity.Current!;
|
||||
var manager = (InputMethodManager)activity.GetSystemService(InputMethodService)!;
|
||||
return activity.CurrentFocus is { } view && view.HasWindowFocus
|
||||
&& manager.InvokeIsActive(view) && manager.IsAcceptingText;
|
||||
}, ct);
|
||||
_stage = "opening keyboard";
|
||||
await TapAsync(source!, root);
|
||||
await WaitAsync(KeyboardVisible, ct);
|
||||
await Task.Delay(500, ct);
|
||||
await Dispatcher.UIThread.InvokeAsync(() => CheckCaret(source!, root));
|
||||
var activity = MainActivity.Current!;
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
var manager = (InputMethodManager)activity.GetSystemService(InputMethodService)!;
|
||||
if (!manager.HideSoftInputFromWindow(activity.CurrentFocus!.WindowToken, HideSoftInputFlags.None))
|
||||
throw new InvalidOperationException("Keyboard hide request rejected.");
|
||||
});
|
||||
await WaitAsync(() => !KeyboardVisible(), ct);
|
||||
await Task.Delay(500, ct);
|
||||
await Dispatcher.UIThread.InvokeAsync(() => CheckSystemBars(root));
|
||||
await TapAsync(source!, root);
|
||||
_stage = "reopening keyboard";
|
||||
await WaitAsync(KeyboardVisible, ct);
|
||||
await Task.Delay(500, ct);
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
CheckCaret(source!, root);
|
||||
if (focusLosses != 0) throw new InvalidOperationException($"Editor lost focus {focusLosses} times.");
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (page is not null)
|
||||
await Dispatcher.UIThread.InvokeAsync(async () =>
|
||||
{
|
||||
if (ReferenceEquals(navigation.NavigationStack.LastOrDefault(), page))
|
||||
await navigation.PopAsync();
|
||||
});
|
||||
if (_previousOrientation is { } orientation && MainActivity.Current is { } main)
|
||||
main.RunOnUiThread(() => main.RequestedOrientation = orientation);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool KeyboardVisible()
|
||||
=> OperatingSystem.IsAndroidVersionAtLeast(30)
|
||||
&& MainActivity.Current?.Window?.DecorView?.RootWindowInsets?.IsVisible(WindowInsets.Type.Ime()) == true;
|
||||
|
||||
private static void CheckCaret(TextEditor source, Control root)
|
||||
{
|
||||
var area = source.TextArea;
|
||||
if (!area.IsFocused) throw new InvalidOperationException("Editor is not focused.");
|
||||
var rect = area.Caret.CalculateCaretRectangle();
|
||||
var view = area.TextView;
|
||||
var bottom = rect.Bottom - view.ScrollOffset.Y;
|
||||
if (rect.Top - view.ScrollOffset.Y < -1 || bottom > view.Bounds.Height + 1)
|
||||
throw new InvalidOperationException($"Caret outside viewport: bottom={bottom}, height={view.Bounds.Height}.");
|
||||
var editorBottom = source.TranslatePoint(new Point(0, source.Bounds.Height), root)!.Value.Y;
|
||||
if (editorBottom > root.Bounds.Height + 1)
|
||||
throw new InvalidOperationException($"Editor outside root: bottom={editorBottom}, height={root.Bounds.Height}.");
|
||||
if (view.Bounds.Height < view.DefaultLineHeight * 3)
|
||||
throw new InvalidOperationException($"Less than three visible lines: viewport={view.Bounds.Height}, line={view.DefaultLineHeight}.");
|
||||
if (OperatingSystem.IsAndroidVersionAtLeast(30) && KeyboardVisible())
|
||||
{
|
||||
var activity = MainActivity.Current!;
|
||||
var decor = activity.Window!.DecorView;
|
||||
var keyboardTop = decor.Height - decor.RootWindowInsets!.GetInsets(WindowInsets.Type.Ime()).Bottom;
|
||||
var location = new int[2];
|
||||
activity.CurrentFocus!.GetLocationInWindow(location);
|
||||
var topLevel = TopLevel.GetTopLevel(root)!;
|
||||
var bottomInWindow = source.TranslatePoint(new Point(0, source.Bounds.Height), topLevel)!.Value.Y
|
||||
* topLevel.RenderScaling + location[1];
|
||||
if (bottomInWindow > keyboardTop + 2)
|
||||
throw new InvalidOperationException($"Editor hidden by keyboard: bottom={bottomInWindow}, keyboardTop={keyboardTop}.");
|
||||
}
|
||||
CheckSystemBars(root);
|
||||
}
|
||||
|
||||
private static void CheckSystemBars(Control root)
|
||||
{
|
||||
if (!OperatingSystem.IsAndroidVersionAtLeast(30))
|
||||
throw new PlatformNotSupportedException("Android 11 required for native inset assertions.");
|
||||
var activity = MainActivity.Current!;
|
||||
var decor = activity.Window!.DecorView;
|
||||
var insets = decor.RootWindowInsets!;
|
||||
var bars = insets.GetInsets(WindowInsets.Type.SystemBars() | WindowInsets.Type.DisplayCutout());
|
||||
var location = new int[2];
|
||||
activity.CurrentFocus!.GetLocationInWindow(location);
|
||||
var topLevel = TopLevel.GetTopLevel(root)!;
|
||||
var navigation = root.FindControl<NavigationPage>("NavRoot")!;
|
||||
var banner = root.FindControl<PostIt.Views.SessionStatusBanner>("SessionBanner")!;
|
||||
var top = navigation.TranslatePoint(new Point(), topLevel)!.Value.Y * topLevel.RenderScaling + location[1];
|
||||
var bottom = banner.TranslatePoint(new Point(0, banner.Bounds.Height), topLevel)!.Value.Y
|
||||
* topLevel.RenderScaling + location[1];
|
||||
var visibleBottom = decor.Height - bars.Bottom;
|
||||
if (KeyboardVisible())
|
||||
visibleBottom = Math.Min(visibleBottom, decor.Height - insets.GetInsets(WindowInsets.Type.Ime()).Bottom);
|
||||
if (top < bars.Top - 2 || bottom > visibleBottom + 2 || !banner.IsVisible)
|
||||
throw new InvalidOperationException($"Controls overlap system bars: top={top}, safeTop={bars.Top}, bottom={bottom}, safeBottom={visibleBottom}, banner={banner.IsVisible}.");
|
||||
if (navigation.NavigationStack.LastOrDefault() is BlogsPage page)
|
||||
{
|
||||
var bar = NavigationPage.GetTopCommandBar(page)!;
|
||||
var shouldShowTitle = !KeyboardVisible();
|
||||
if (!bar.IsVisible || bar.Bounds.Height <= 0
|
||||
|| page.FindControl<TextBox>("DraftTitleTextBox")?.IsVisible != shouldShowTitle)
|
||||
throw new InvalidOperationException("Blog controls are unavailable.");
|
||||
if (page.FindControl<TextBox>("DraftTitleTextBox")?.Text != "Local keyboard test")
|
||||
throw new InvalidOperationException("The title changed during keyboard layout transitions.");
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task TapAsync(TextEditor source, Control root)
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
var activity = MainActivity.Current!;
|
||||
var point = source.TextArea.TranslatePoint(new Point(80, source.TextArea.Bounds.Height / 2), root)!.Value;
|
||||
var location = new int[2];
|
||||
activity.CurrentFocus!.GetLocationInWindow(location);
|
||||
var scale = TopLevel.GetTopLevel(root)!.RenderScaling;
|
||||
var x = (float)(point.X * scale + location[0]);
|
||||
var y = (float)(point.Y * scale + location[1]);
|
||||
var now = SystemClock.UptimeMillis();
|
||||
using var properties = new MotionEvent.PointerProperties { Id = 0, ToolType = MotionEventToolType.Finger };
|
||||
using var coordinates = new MotionEvent.PointerCoords { X = x, Y = y, Pressure = 1, Size = 1 };
|
||||
using var down = MotionEvent.Obtain(now, now, MotionEventActions.Down, 1,
|
||||
new[] { properties }, new[] { coordinates }, 0, 0, 1, 1, 0, 0,
|
||||
InputSourceType.Touchscreen, 0)!;
|
||||
using var up = MotionEvent.Obtain(now, now + 50, MotionEventActions.Up, 1,
|
||||
new[] { properties }, new[] { coordinates }, 0, 0, 1, 1, 0, 0,
|
||||
InputSourceType.Touchscreen, 0)!;
|
||||
activity.DispatchTouchEvent(down);
|
||||
activity.DispatchTouchEvent(up);
|
||||
});
|
||||
}
|
||||
|
||||
private static async Task WaitAsync(Func<bool> condition, CancellationToken ct)
|
||||
{
|
||||
while (!await Dispatcher.UIThread.InvokeAsync(condition))
|
||||
await Task.Delay(50, ct);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -228,7 +228,6 @@ public class BlogReaderTests
|
|||
{
|
||||
Assert.True(reader.Bounds.Right <= list.Bounds.Left);
|
||||
Assert.Equal(2, Grid.GetColumn(page.BlogsHeaderPanel));
|
||||
Assert.Equal(2, Grid.GetColumn(page.BlogsCommandBar));
|
||||
Assert.Equal(reader.Margin.Top, reader.Bounds.Top);
|
||||
Assert.Equal(page.StatusBar.Bounds.Top - reader.Margin.Bottom, reader.Bounds.Bottom);
|
||||
Assert.Equal(36, page.TranslatePoint(new Point(), nav)!.Value.Y);
|
||||
|
|
@ -237,9 +236,9 @@ public class BlogReaderTests
|
|||
{
|
||||
Assert.True(list.Bounds.Bottom <= reader.Bounds.Top);
|
||||
Assert.Equal(0, Grid.GetColumn(page.BlogsHeaderPanel));
|
||||
Assert.Equal(0, Grid.GetColumn(page.BlogsCommandBar));
|
||||
}
|
||||
|
||||
Assert.Same(page.BlogsCommandBar, NavigationPage.GetTopCommandBar(page));
|
||||
var articleScroll = page.FindControl<MarkdownScrollViewer>("ArticleReader")!
|
||||
.GetVisualDescendants().OfType<ScrollViewer>().Single();
|
||||
Assert.InRange(articleScroll.Viewport.Height, 1, window.ClientSize.Height);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Headless;
|
||||
using Avalonia.Headless.XUnit;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.LogicalTree;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.VisualTree;
|
||||
using AvaloniaEdit;
|
||||
using PostIt.Controls;
|
||||
using PostIt.Services;
|
||||
using PostIt.ViewModels;
|
||||
using PostIt.Views;
|
||||
using PostIt.Views.Blogs;
|
||||
|
||||
namespace PostIt.Tests;
|
||||
|
|
@ -16,6 +21,201 @@ public class MarkdownEditorScrollTests
|
|||
private static readonly string LongArticle =
|
||||
string.Join("\n\n", Enumerable.Range(1, 100).Select(i => $"Paragraph {i}: article content."));
|
||||
|
||||
[AvaloniaFact]
|
||||
public async Task Landscape_keyboard_preserves_controls_and_restores_editor_layout()
|
||||
{
|
||||
var root = new MainView();
|
||||
var page = new BlogsPage { DataContext = new BlogsViewModel { IsEditing = true, DraftArticle = LongArticle } };
|
||||
var window = new Window { Width = 800, Height = 400, Content = root };
|
||||
try
|
||||
{
|
||||
window.Show();
|
||||
await root.NavRoot.PushAsync(page, null);
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
window.UpdateLayout();
|
||||
var editor = page.ArticleEditor;
|
||||
var source = editor.FindControl<TextEditor>("SourceEditor")!;
|
||||
source.TextArea.Focus();
|
||||
source.CaretOffset = source.Document.TextLength;
|
||||
root.ApplyKeyboardOcclusion(new Rect(0, 200, 800, 200));
|
||||
window.UpdateLayout();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
window.UpdateLayout();
|
||||
Assert.True(page.DraftTitleTextBox.IsVisible);
|
||||
Assert.True(page.AttachmentsBorder.IsVisible);
|
||||
Assert.True(root.SessionBanner.IsVisible);
|
||||
Assert.Equal(1, Grid.GetColumn(page.DraftTitleTextBox));
|
||||
Assert.Equal(1, Grid.GetColumn(page.AttachmentsBorder));
|
||||
Assert.True(page.StatusBar.IsVisible);
|
||||
Assert.Equal(2, Grid.GetColumn(page.StatusBar));
|
||||
Assert.Same(page.BlogsCommandBar, NavigationPage.GetTopCommandBar(page));
|
||||
Assert.True(source.TextArea.Bounds.Height >= source.TextArea.TextView.DefaultLineHeight * 3);
|
||||
var bottom = source.TranslatePoint(new Point(0, source.Bounds.Height), window)!.Value.Y;
|
||||
Assert.InRange(bottom, 1, 200);
|
||||
var document = source.Document;
|
||||
root.ApplyKeyboardOcclusion(null);
|
||||
window.UpdateLayout();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
window.UpdateLayout();
|
||||
Assert.True(page.DraftTitleTextBox.IsVisible);
|
||||
Assert.True(page.AttachmentsBorder.IsVisible);
|
||||
Assert.True(root.SessionBanner.IsVisible);
|
||||
Assert.Equal(0, Grid.GetColumn(page.DraftTitleTextBox));
|
||||
Assert.Same(document, source.Document);
|
||||
Assert.True(source.TextArea.IsFocused);
|
||||
|
||||
window.Height = 200;
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
window.UpdateLayout();
|
||||
root.ApplyKeyboardOcclusion(new Rect(0, 200, 800, 200));
|
||||
Assert.Equal(0, root.Padding.Bottom);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseWindow(window, page.ArticleEditor);
|
||||
}
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void Keyboard_padding_preserves_system_bar_insets_and_restores_them()
|
||||
{
|
||||
var root = new MainView();
|
||||
var window = new Window { Width = 600, Height = 800, Content = root };
|
||||
try
|
||||
{
|
||||
window.Show();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
window.UpdateLayout();
|
||||
var safeArea = new Thickness(10, 24, 12, 30);
|
||||
root.ApplySafeArea(safeArea);
|
||||
Assert.Equal(safeArea, root.Padding);
|
||||
root.ApplyKeyboardOcclusion(new Rect(0, 500, 600, 300));
|
||||
Assert.Equal(new Thickness(10, 24, 12, 300), root.Padding);
|
||||
root.ApplySafeArea(new Thickness(20, 26, 22, 32));
|
||||
Assert.Equal(new Thickness(20, 26, 22, 300), root.Padding);
|
||||
root.ApplyKeyboardOcclusion(null);
|
||||
window.UpdateLayout();
|
||||
Assert.Equal(new Thickness(20, 26, 22, 32), root.Padding);
|
||||
var navigationTop = root.NavRoot.TranslatePoint(new Point(), window)!.Value.Y;
|
||||
var bannerBottom = root.SessionBanner.TranslatePoint(new Point(0, root.SessionBanner.Bounds.Height), window)!.Value.Y;
|
||||
Assert.True(navigationTop >= 26);
|
||||
Assert.True(bannerBottom <= 768);
|
||||
Assert.True(root.SessionBanner.IsVisible);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[AvaloniaTheory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void Resizing_keeps_the_focused_caret_visible_without_changing_selection(bool focused)
|
||||
{
|
||||
var editor = new MarkdownEditorControl { MarkdownText = LongArticle };
|
||||
var other = new TextBox();
|
||||
var panel = new DockPanel();
|
||||
DockPanel.SetDock(other, Dock.Top);
|
||||
panel.Children.Add(other);
|
||||
panel.Children.Add(editor);
|
||||
var window = new Window { Width = 600, Height = 500, Content = panel };
|
||||
try
|
||||
{
|
||||
window.Show();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
window.UpdateLayout();
|
||||
var source = editor.FindControl<TextEditor>("SourceEditor")!;
|
||||
source.TextArea.Focus();
|
||||
source.Select(LongArticle.Length - 20, 10);
|
||||
source.TextArea.Caret.BringCaretToView();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
window.UpdateLayout();
|
||||
var selectedText = source.SelectedText;
|
||||
var caretOffset = source.CaretOffset;
|
||||
var scroller = FindArticleScroller(editor, false);
|
||||
if (!focused)
|
||||
{
|
||||
other.Focus();
|
||||
scroller.ScrollToHome();
|
||||
}
|
||||
|
||||
window.Height = 250;
|
||||
window.UpdateLayout();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
window.UpdateLayout();
|
||||
|
||||
Assert.Equal(selectedText, source.SelectedText);
|
||||
Assert.Equal(caretOffset, source.CaretOffset);
|
||||
if (focused)
|
||||
{
|
||||
Assert.True(source.TextArea.IsFocused);
|
||||
var caret = source.TextArea.Caret.CalculateCaretRectangle();
|
||||
var view = source.TextArea.TextView;
|
||||
Assert.InRange(caret.Top - view.ScrollOffset.Y, 0, view.Bounds.Height);
|
||||
Assert.InRange(caret.Bottom - view.ScrollOffset.Y, 0, view.Bounds.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(other.IsFocused);
|
||||
Assert.Equal(0, scroller.Offset.Y);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseWindow(window, editor);
|
||||
}
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void Repeated_touch_requests_keyboard_without_losing_focus_and_read_only_does_not()
|
||||
{
|
||||
var editor = new MarkdownEditorControl { MarkdownText = LongArticle };
|
||||
var window = new Window { Width = 600, Height = 400, Content = editor };
|
||||
var previous = Platform.ShowSoftKeyboard;
|
||||
var requests = 0;
|
||||
Platform.ShowSoftKeyboard = () => requests++;
|
||||
try
|
||||
{
|
||||
window.Show();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
window.UpdateLayout();
|
||||
var source = editor.FindControl<TextEditor>("SourceEditor")!;
|
||||
source.TextArea.Focus();
|
||||
var focusLosses = 0;
|
||||
source.TextArea.LostFocus += (_, _) => focusLosses++;
|
||||
var point = source.TextArea.TranslatePoint(new Point(60, 20), window)!.Value;
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
using var touch = window.TouchBegin(point);
|
||||
window.TouchEnd(touch, point);
|
||||
Assert.True(source.TextArea.IsFocused);
|
||||
Assert.Equal(i + 1, requests);
|
||||
}
|
||||
|
||||
window.MouseDown(point, MouseButton.Left);
|
||||
window.MouseUp(point, MouseButton.Left);
|
||||
Assert.Equal(2, requests);
|
||||
using (var scrollTouch = window.TouchBegin(point))
|
||||
{
|
||||
var end = point + new Vector(0, -80);
|
||||
window.TouchMove(scrollTouch, end);
|
||||
window.TouchEnd(scrollTouch, end);
|
||||
}
|
||||
Assert.Equal(2, requests);
|
||||
source.IsReadOnly = true;
|
||||
using var readOnlyTouch = window.TouchBegin(point);
|
||||
window.TouchEnd(readOnlyTouch, point);
|
||||
Assert.Equal(2, requests);
|
||||
Assert.Equal(0, focusLosses);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Platform.ShowSoftKeyboard = previous;
|
||||
CloseWindow(window, editor);
|
||||
}
|
||||
}
|
||||
|
||||
[AvaloniaTheory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue