From 2dfaa07e7553714848621ac2bb08f8998f05c75d Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 27 Jan 2023 13:55:39 +0100 Subject: [PATCH] Use correct range ctor. And fix unit test that should've caught the mistake. --- .../Automation/AutomationTextRange.cs | 2 +- .../Automation/AutomationTextRangeTests.cs | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Windows/Avalonia.Win32/Automation/AutomationTextRange.cs b/src/Windows/Avalonia.Win32/Automation/AutomationTextRange.cs index 560fd73562..a8c098f16c 100644 --- a/src/Windows/Avalonia.Win32/Automation/AutomationTextRange.cs +++ b/src/Windows/Avalonia.Win32/Automation/AutomationTextRange.cs @@ -51,7 +51,7 @@ namespace Avalonia.Win32.Automation } } - public TextRange Range => new(Start, End); + public TextRange Range => TextRange.FromStartEnd(Start, End); private AAP.ITextProvider InnerProvider => (AAP.ITextProvider)_owner.Peer; diff --git a/tests/Avalonia.Win32.UnitTests/Automation/AutomationTextRangeTests.cs b/tests/Avalonia.Win32.UnitTests/Automation/AutomationTextRangeTests.cs index 0abe161ec8..820281e52f 100644 --- a/tests/Avalonia.Win32.UnitTests/Automation/AutomationTextRangeTests.cs +++ b/tests/Avalonia.Win32.UnitTests/Automation/AutomationTextRangeTests.cs @@ -91,12 +91,12 @@ public class AutomationTextRangeTests public void Moves_Left_One_Char(string newline) { var (node, peer) = CreateTestNode(newline: newline); - var range = new AutomationTextRange(node, 0, 1); + var range = new AutomationTextRange(node, 1, 2); - var result = range.Move(TextUnit.Character, 1); + var result = range.Move(TextUnit.Character, -1); - Assert.Equal(1, result); - Assert.Equal(peer.Lines[0][1].ToString(), range.GetText(-1)); + Assert.Equal(-1, result); + Assert.Equal(peer.Lines[0][0].ToString(), range.GetText(-1)); } [Theory] @@ -227,6 +227,19 @@ public class AutomationTextRangeTests Assert.Equal(peer.Lines[^1], range.GetText(-1)); } + [Theory] + [ClassData(typeof(Newlines))] + public void Moving_Down_From_DocumentRange_Moves_To_Second_Line(string newline) + { + var (node, peer) = CreateTestNode(newline: newline); + var range = new AutomationTextRange(node, peer.DocumentRange); + + var result = range.Move(TextUnit.Line, 1); + + Assert.Equal(1, result); + Assert.Equal(peer.Lines[1], range.GetText(-1)); + } + [Theory] [ClassData(typeof(Newlines))] public void Moves_Up_To_Empty_Line(string newline)